diff --git a/server/Gemfile b/server/Gemfile index 26abdb0c8..f600875bd 100644 --- a/server/Gemfile +++ b/server/Gemfile @@ -50,8 +50,6 @@ gem 'typhoeus', '~>1.4.0' gem 'audited', '~> 5.3' -gem 'graphiql-rails', '~> 1.8.0' - #user comment rendering gem 'rinku', '~> 2.0.6' gem 'sanitize', '~> 6.0.2' diff --git a/server/Gemfile.lock b/server/Gemfile.lock index 13b294ddc..25c6c343f 100644 --- a/server/Gemfile.lock +++ b/server/Gemfile.lock @@ -179,9 +179,6 @@ GEM raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) - graphiql-rails (1.8.0) - railties - sprockets-rails graphql (1.12.24) graphql-batch (0.4.3) graphql (>= 1.3, < 2) @@ -500,7 +497,6 @@ DEPENDENCIES dockerfile-rails (>= 1.5) ed25519 elasticsearch (~> 7.13.0) - graphiql-rails (~> 1.8.0) graphql (~> 1.12.4) graphql-batch (~> 0.4.3) htmlentities (~> 4.3.4) diff --git a/server/app/assets/config/manifest.js b/server/app/assets/config/manifest.js index b46f9f8c8..591819335 100644 --- a/server/app/assets/config/manifest.js +++ b/server/app/assets/config/manifest.js @@ -1,4 +1,2 @@ //= link_tree ../images //= link_directory ../stylesheets .css -//= link graphiql/rails/application.css -//= link graphiql/rails/application.js diff --git a/server/app/controllers/graphiql_controller.rb b/server/app/controllers/graphiql_controller.rb new file mode 100644 index 000000000..cf6c03f0a --- /dev/null +++ b/server/app/controllers/graphiql_controller.rb @@ -0,0 +1,7 @@ +class GraphiqlController < ApplicationController + layout false + def show + @initial_query = GQL_EXAMPLES.initial_query + @examples = GQL_EXAMPLES.examples + end +end diff --git a/server/app/javascript/application.js b/server/app/javascript/application.js new file mode 100644 index 000000000..e69de29bb diff --git a/server/app/views/graphiql/show.html.erb b/server/app/views/graphiql/show.html.erb new file mode 100644 index 000000000..d772af57d --- /dev/null +++ b/server/app/views/graphiql/show.html.erb @@ -0,0 +1,150 @@ + + + + + CIViC GraphiQL + + + + + + + + + + + + + + + + + +
+
+

+ Welcome to the CIViC GraphiQL Sandbox. Here you can browse the API schema + and documentation as well as view example queries in the sidebar. Click the + docs icon + icon to browse the CIViC API Documentation or click here to learn more about GraphQL. +

+
+
+
+ <% @examples.each do |ex| %> +
+
+
+ +
+

+ <%= ex["description"] %> +

+
+
+
+
+ <% end %> +
+
+
Loading...
+
+
+
+ + + + diff --git a/server/config/initializers/graphiql.rb b/server/config/initializers/graphiql.rb index 40bb12c8e..4c9831ae8 100644 --- a/server/config/initializers/graphiql.rb +++ b/server/config/initializers/graphiql.rb @@ -1,58 +1,15 @@ -GraphiQL::Rails.config.initial_query = <<~QUERY -# Below is an example of fetching a page of accepted Evidence Items using the GraphQL API. -# You can press the "Play >" button to run the query and see the response. Note how the structure mirrors the fields requested in the query. -# Clicking "Docs" in the upper right will allow you to explore the schema including all available queries and the fields you can request on them. -# -# The GraphiQL environment will offer autocompletion and validation as you experient with what's possible. -# -{ - evidenceItems(status: ACCEPTED, first: 25) { - totalCount #Total Count of EIDs matching the criteria - pageInfo { - endCursor #Cursor for the last item in the response. You can pass this to "after" to get the next page. - hasNextPage #Is there a page after this one? - } - nodes { - id - status - molecularProfile { - id - name - link - } - evidenceType - evidenceLevel - evidenceRating - evidenceDirection - phenotypes { - id - hpoId - name - } - description - disease { - id - doid - name - diseaseAliases - displayName - } - therapies { - id - ncitId - name - therapyAliases - } - source { - ascoAbstractId - citationId - pmcId - sourceType - title - } - therapyInteractionType +class GqlExamples + attr_reader :initial_query, :examples + + def initialize(path) + config_files = Dir.glob("*.yml", base: path) + @examples = config_files.map { |f| YAML.load_file(File.join(path, f)) } + .sort_by { |e| e['order'] || 999 } + + @initial_query = @examples.first["query"] + end +end + +path = File.join(Rails.root, 'config', 'query_examples') +GQL_EXAMPLES = GqlExamples.new(path) - } - } -} -QUERY diff --git a/server/config/query_examples/accepted_evidence.yml b/server/config/query_examples/accepted_evidence.yml new file mode 100644 index 000000000..b45638656 --- /dev/null +++ b/server/config/query_examples/accepted_evidence.yml @@ -0,0 +1,60 @@ +name: Accepted Evidence +description: Get only Accepted Evidence Items in CIViC +order: 0 +query: | + # Below is an example of fetching a page of accepted Evidence Items using the GraphQL API. + # You can press the "Play >" button to run the query and see the response. Note how the structure mirrors the fields requested in the query. + # Clicking the Docs icon to the left will allow you to explore the schema including all available queries and the fields you can request on them. + # + # The GraphiQL environment will offer autocompletion and validation as you experient with what's possible. + # + { + evidenceItems(status: ACCEPTED, first: 25) { + totalCount #Total Count of EIDs matching the criteria + pageInfo { + endCursor #Cursor for the last item in the response. You can pass this to "after" to get the next page. + hasNextPage #Is there a page after this one? + } + nodes { + id + status + molecularProfile { + id + name + link + } + evidenceType + evidenceLevel + evidenceRating + evidenceDirection + phenotypes { + id + hpoId + name + } + description + disease { + id + doid + name + diseaseAliases + displayName + } + therapies { + id + ncitId + name + therapyAliases + } + source { + ascoAbstractId + citationId + pmcId + sourceType + title + } + therapyInteractionType + + } + } + } diff --git a/server/config/query_examples/evidence_counts.yml b/server/config/query_examples/evidence_counts.yml new file mode 100644 index 000000000..ff02c8a63 --- /dev/null +++ b/server/config/query_examples/evidence_counts.yml @@ -0,0 +1,25 @@ +name: Use Allele Registry ID +description: Query for Molecular Profiles in CIViC by using a ClinGen Allele Registry ID, fetching Evidence Item counts for each +order: 1 +query: | + { + molecularProfiles(alleleRegistryId:"CA123643") { + totalCount + pageInfo { + hasNextPage + endCursor + } + nodes { + name + id + link + evidenceCountsByType { + diagnosticCount + predictiveCount + predisposingCount + oncogenicCount + functionalCount + } + } + } + diff --git a/server/config/query_examples/evidence_for_variant.yml b/server/config/query_examples/evidence_for_variant.yml new file mode 100644 index 000000000..e928b3647 --- /dev/null +++ b/server/config/query_examples/evidence_for_variant.yml @@ -0,0 +1,82 @@ +name: Gene And Variant By Name +description: Use an Entrez Gene Symbol and Variant name search to retrieve relevant Molecular Profiles and their Evidence Items +order: 2 +query: | + { + gene(entrezSymbol: "BRAF") { + variants(name: "V600") { + pageInfo { + hasNextPage + endCursor + } + nodes { + name + id + link + alleleRegistryId + primaryCoordinates { + start + stop + chromosome + representativeTranscript + } + molecularProfiles { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + name + evidenceItems { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + status + molecularProfile { + id + name + link + } + evidenceType + evidenceLevel + evidenceRating + evidenceDirection + phenotypes { + id + hpoId + name + } + description + disease { + id + doid + name + diseaseAliases + displayName + } + therapies { + id + ncitId + name + therapyAliases + } + source { + ascoAbstractId + citationId + pmcId + sourceType + title + } + therapyInteractionType + } + } + } + } + } + } + } + } diff --git a/server/config/routes.rb b/server/config/routes.rb index 2ee489742..b3d2b4841 100644 --- a/server/config/routes.rb +++ b/server/config/routes.rb @@ -18,9 +18,8 @@ get '/links' => 'links#redirect' get 'links/:idtype/:id' => 'links#redirect' - mount GraphiQL::Rails::Engine, at: "/api/graphiql", graphql_path: "/api/graphql" + get '/api/graphiql' => 'graphiql#show' - require 'sidekiq/web' require 'sidekiq/cron/web' mount Sidekiq::Web, at: '/jobs', constraints: UserLoggedInConstraint.new