From ff36de55694f19bacd08703f748f027d8ad40a72 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sat, 13 May 2023 07:52:25 +0200 Subject: [PATCH 01/17] plugin file --- .well-known/.gitkeep | 0 .well-known/ai-plugin.json | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 .well-known/.gitkeep create mode 100644 .well-known/ai-plugin.json diff --git a/.well-known/.gitkeep b/.well-known/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json new file mode 100644 index 000000000..f4a19b4ff --- /dev/null +++ b/.well-known/ai-plugin.json @@ -0,0 +1,18 @@ +{ + "schema_version": "v1", + "name_for_human": "Science Knowledge Graph", + "name_for_model": "Science Knowledge Graph", + "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", + "description_for_model": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", + "auth": { + "type": "none" + }, + "api": { + "type": "openapi", + "url": "https://raw.githubusercontent.com/kjgarza/science-knowledge-graph-gpt-plugin/master/openapi.yaml", + "is_user_authenticated": false + }, + "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", + "contact_email": "kgarza@datacite.org", + "legal_info_url": "http://www.example.com/legal" +} \ No newline at end of file From 5a67544d7c4a76e56f1d491fc8cb41414cffd0ca Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sat, 13 May 2023 07:53:21 +0200 Subject: [PATCH 02/17] plugin route --- app/controllers/application_controller.rb | 8 ++++++++ config/routes.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d20c676fa..09ee8d58f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -164,6 +164,14 @@ def skip_bullet Bullet.enable = previous_value end + def serve_manifest + send_file( + "#{Rails.root}/.well-known/ai-plugin.json", + type: "application/json", + disposition: "inline" + ) + end + protected def is_admin_or_staff? current_user&.is_admin_or_staff? ? 1 : 0 diff --git a/config/routes.rb b/config/routes.rb index f1b42826f..a6f93bb9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,9 @@ # send reset link post "reset", to: "sessions#reset" + ## to route when requesting .well-known/ai-plugin.json to route to that file + get "/.well-known/ai-plugin.json", to: "application#serve_manifest" + # content negotiation via index path get "/application/vnd.datacite.datacite+xml/:id", to: "index#show", @@ -244,6 +247,7 @@ constraints: { id: /.+/ }, format: false + root to: "index#index" # rescue routing errors From 676e52ebd1983b96c634cb8ccf5f92ba68f5459b Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sat, 13 May 2023 08:41:42 +0200 Subject: [PATCH 03/17] working copy --- .well-known/ai-plugin.json | 4 +- app/controllers/application_controller.rb | 8 + config/routes.rb | 1 + graphql-openapi.yaml | 230 ++++++++++++++++++++++ 4 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 graphql-openapi.yaml diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index f4a19b4ff..ef92fcdb4 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -1,7 +1,7 @@ { "schema_version": "v1", "name_for_human": "Science Knowledge Graph", - "name_for_model": "Science Knowledge Graph", + "name_for_model": "science_knowledge_graph", "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", "description_for_model": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", "auth": { @@ -9,7 +9,7 @@ }, "api": { "type": "openapi", - "url": "https://raw.githubusercontent.com/kjgarza/science-knowledge-graph-gpt-plugin/master/openapi.yaml", + "url": "http://localhost:8065/graphql-openapi.yaml", "is_user_authenticated": false }, "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09ee8d58f..6b980a793 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -172,6 +172,14 @@ def serve_manifest ) end + def serve_openapi_spec + send_file( + "#{Rails.root}/graphql-openapi.yaml", + type: "text/yaml", + disposition: "inline" + ) + end + protected def is_admin_or_staff? current_user&.is_admin_or_staff? ? 1 : 0 diff --git a/config/routes.rb b/config/routes.rb index a6f93bb9c..84da67052 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ ## to route when requesting .well-known/ai-plugin.json to route to that file get "/.well-known/ai-plugin.json", to: "application#serve_manifest" + get "/graphql-openapi.yaml", to: "application#serve_openapi_spec" # content negotiation via index path get "/application/vnd.datacite.datacite+xml/:id", diff --git a/graphql-openapi.yaml b/graphql-openapi.yaml new file mode 100644 index 000000000..413083c60 --- /dev/null +++ b/graphql-openapi.yaml @@ -0,0 +1,230 @@ +openapi: 3.0.0 +info: + title: GraphQL Research API + description: An API to manage datasets, researchers, and articles using GraphQL. + version: 1.0.0 +servers: + - url: http://localhost:8065/client-api +paths: + /graphql: + post: + summary: Make a GraphQL query + operationId: graphql_request + description: Send a GraphQL query to the server. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/GraphQLRequest' + responses: + '200': + description: A successful GraphQL response + content: + application/json: + schema: + $ref: '#/components/schemas/GraphQLResponse' + '400': + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' +components: + schemas: + GraphQLRequest: + type: object + required: + - query + properties: + query: + type: string + description: The GraphQL query. + variables: + type: object + description: The variables for the query. + additionalProperties: true + GraphQLResponse: + type: object + properties: + data: + type: object + description: The result of the query. + additionalProperties: true + errors: + type: array + description: A list of errors that occurred during the request. + items: + $ref: '#/components/schemas/Error' + ErrorResponse: + type: object + properties: + errors: + type: array + description: A list of errors that occurred during the request. + items: + $ref: '#/components/schemas/Error' + Error: + type: object + properties: + message: + type: string + description: A description of the error. + locations: + type: array + description: The locations of the errors in the query, if available. + items: + $ref: '#/components/schemas/ErrorLocation' + path: + type: array + description: The path of the field that caused the error, if available. + items: + oneOf: + - type: string + - type: integer + ErrorLocation: + type: object + properties: + line: + type: integer + description: The line number of the error. + column: + type: integer + description: The column number of the error. +x-graphql-types: + - name: Dataset + - name: Work + - name: Software + - name: Organisation + - name: Person + - name: Publication +x-graphql-queries: + - name: Fetch the data and the works linked to the person with ORCID ID 0000-0001-5934-7525 + query: | + { + person(id: "https://orcid.org/0000-0001-5934-7525") { + id + name + givenName + familyName + citationCount + works(hasFunder: true) { + totalCount + published { + title + count + } + resourceTypes { + title + count + } + nodes { + id + type + titles { + title + } + rights { + rights + } + citationCount + } + } + } + } + - name: Fetch all the data about the organization with ROR ID 052gg0110 + query: | + { + organization(id: "https://ror.org/052gg0110") { + id + name + alternateName + citationCount + viewCount + downloadCount + works(hasViews: 100, first: 100) { + totalCount + published { + title + count + } + resourceTypes { + title + count + } + nodes { + id + type + publisher + publicationYear + titles { + title + } + creators { + id + name + affiliation { + id + name + } + } + citationCount + viewCount + downloadCount + } + } + } + } + - name: Fetch 30 dissertations about machine learning + query: | + { + dissertations(query: "machine learning", first: 30) { + totalCount + published{ + id + count + } + nodes { + id + publicationYear + publisher + creators { + id + name + } + titles { + title + } + } + } + } + - name: Fetch the citations of datasets that use the DOI 10.5061/dryad.234 and the citations of those citations + query: | + { + dataset(id: "https://doi.org/10.5061/dryad.234") { + id + titles { + title + } + citationCount + citations { + nodes { + id + publisher + titles { + title + } + citationCount + } + } + } + } + - name: Fetch all the types in the GraphQL schema. + query: | + { __schema { types { name kind } } } From 0091e819d11c9a4697095a1db2be070910a04fff Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sat, 13 May 2023 09:19:01 +0200 Subject: [PATCH 04/17] correct licenses --- .well-known/ai-plugin.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index ef92fcdb4..f96abc37a 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -3,7 +3,7 @@ "name_for_human": "Science Knowledge Graph", "name_for_model": "science_knowledge_graph", "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", - "description_for_model": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", + "description_for_model": "Run GraphQL queries against an API hosted by DataCite API. The DataCite API supports most GraphQL query but does not support mutations statements. Use `{ __schema { types { name kind } } }` to get all the types in the GraphQL schema. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{person(id:ORCID) {works(first:50) {nodes {id titles(first: 1){title} publicationYear}}}}` to get the first 50 works of a person based on their ORCID. Mutations statements are not allowed.", "auth": { "type": "none" }, @@ -13,6 +13,6 @@ "is_user_authenticated": false }, "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", - "contact_email": "kgarza@datacite.org", - "legal_info_url": "http://www.example.com/legal" + "contact_email": "kj.garza@gmail.com", + "legal_info_url": "https://github.com/kjgarza/science-knowledge-graph-gpt-plugin/blob/master/LICENSE" } \ No newline at end of file From 8f2ab1f50f71495f66b457eedbd3478e0755f48d Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sun, 14 May 2023 13:21:54 +0200 Subject: [PATCH 05/17] cors policy for graphql --- config/initializers/cors.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 5f68d44d3..06341c86a 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -6,12 +6,11 @@ # Read more: https://github.com/cyu/rack-cors -# Rails.application.config.middleware.insert_before 0, Rack::Cors do -# allow do -# origins 'example.com' -# -# resource '*', -# headers: :any, -# methods: [:get, :post, :put, :patch, :delete, :options, :head] -# end -# end +Rails.application.config.middleware.insert_before 0, Rack::Cors do + allow do + origins "" # replace with your actual trusted sites + resource "graphql", + headers: "*", + methods: [:get, :post, :head, :options] + end +end From 15f92dc38ca306ccb5482931dadb364106632a76 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sun, 14 May 2023 13:26:44 +0200 Subject: [PATCH 06/17] remove cors --- config/initializers/cors.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 06341c86a..740ee2615 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -6,11 +6,11 @@ # Read more: https://github.com/cyu/rack-cors -Rails.application.config.middleware.insert_before 0, Rack::Cors do - allow do - origins "" # replace with your actual trusted sites - resource "graphql", - headers: "*", - methods: [:get, :post, :head, :options] - end -end +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "" # replace with your actual trusted sites +# resource "graphql", +# headers: "*", +# methods: [:get, :post, :head, :options] +# end +# end From b36ff231efc18b94fb49f7ffc3f1c8db3f9aa6eb Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sun, 14 May 2023 18:49:00 +0200 Subject: [PATCH 07/17] use redirect isntead of serve --- .well-known/.gitkeep | 0 .well-known/ai-plugin.json | 18 -- app/controllers/application_controller.rb | 12 +- graphql-openapi.yaml | 230 ---------------------- 4 files changed, 2 insertions(+), 258 deletions(-) delete mode 100644 .well-known/.gitkeep delete mode 100644 .well-known/ai-plugin.json delete mode 100644 graphql-openapi.yaml diff --git a/.well-known/.gitkeep b/.well-known/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json deleted file mode 100644 index f96abc37a..000000000 --- a/.well-known/ai-plugin.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "schema_version": "v1", - "name_for_human": "Science Knowledge Graph", - "name_for_model": "science_knowledge_graph", - "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", - "description_for_model": "Run GraphQL queries against an API hosted by DataCite API. The DataCite API supports most GraphQL query but does not support mutations statements. Use `{ __schema { types { name kind } } }` to get all the types in the GraphQL schema. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{person(id:ORCID) {works(first:50) {nodes {id titles(first: 1){title} publicationYear}}}}` to get the first 50 works of a person based on their ORCID. Mutations statements are not allowed.", - "auth": { - "type": "none" - }, - "api": { - "type": "openapi", - "url": "http://localhost:8065/graphql-openapi.yaml", - "is_user_authenticated": false - }, - "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", - "contact_email": "kj.garza@gmail.com", - "legal_info_url": "https://github.com/kjgarza/science-knowledge-graph-gpt-plugin/blob/master/LICENSE" -} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b980a793..34a3af20a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -165,19 +165,11 @@ def skip_bullet end def serve_manifest - send_file( - "#{Rails.root}/.well-known/ai-plugin.json", - type: "application/json", - disposition: "inline" - ) + redirect_to ENV["PLUGIN_MANIFEST_URL"] || "https://api.datacite.org" end def serve_openapi_spec - send_file( - "#{Rails.root}/graphql-openapi.yaml", - type: "text/yaml", - disposition: "inline" - ) + redirect_to ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" end protected diff --git a/graphql-openapi.yaml b/graphql-openapi.yaml deleted file mode 100644 index 413083c60..000000000 --- a/graphql-openapi.yaml +++ /dev/null @@ -1,230 +0,0 @@ -openapi: 3.0.0 -info: - title: GraphQL Research API - description: An API to manage datasets, researchers, and articles using GraphQL. - version: 1.0.0 -servers: - - url: http://localhost:8065/client-api -paths: - /graphql: - post: - summary: Make a GraphQL query - operationId: graphql_request - description: Send a GraphQL query to the server. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/GraphQLRequest' - responses: - '200': - description: A successful GraphQL response - content: - application/json: - schema: - $ref: '#/components/schemas/GraphQLResponse' - '400': - description: Bad request - content: - application/json: - schema: - $ref: '#/components/schemas/ErrorResponse' - '500': - description: Internal server error - content: - application/json: - schema: - $ref: '#/components/schemas/ErrorResponse' -components: - schemas: - GraphQLRequest: - type: object - required: - - query - properties: - query: - type: string - description: The GraphQL query. - variables: - type: object - description: The variables for the query. - additionalProperties: true - GraphQLResponse: - type: object - properties: - data: - type: object - description: The result of the query. - additionalProperties: true - errors: - type: array - description: A list of errors that occurred during the request. - items: - $ref: '#/components/schemas/Error' - ErrorResponse: - type: object - properties: - errors: - type: array - description: A list of errors that occurred during the request. - items: - $ref: '#/components/schemas/Error' - Error: - type: object - properties: - message: - type: string - description: A description of the error. - locations: - type: array - description: The locations of the errors in the query, if available. - items: - $ref: '#/components/schemas/ErrorLocation' - path: - type: array - description: The path of the field that caused the error, if available. - items: - oneOf: - - type: string - - type: integer - ErrorLocation: - type: object - properties: - line: - type: integer - description: The line number of the error. - column: - type: integer - description: The column number of the error. -x-graphql-types: - - name: Dataset - - name: Work - - name: Software - - name: Organisation - - name: Person - - name: Publication -x-graphql-queries: - - name: Fetch the data and the works linked to the person with ORCID ID 0000-0001-5934-7525 - query: | - { - person(id: "https://orcid.org/0000-0001-5934-7525") { - id - name - givenName - familyName - citationCount - works(hasFunder: true) { - totalCount - published { - title - count - } - resourceTypes { - title - count - } - nodes { - id - type - titles { - title - } - rights { - rights - } - citationCount - } - } - } - } - - name: Fetch all the data about the organization with ROR ID 052gg0110 - query: | - { - organization(id: "https://ror.org/052gg0110") { - id - name - alternateName - citationCount - viewCount - downloadCount - works(hasViews: 100, first: 100) { - totalCount - published { - title - count - } - resourceTypes { - title - count - } - nodes { - id - type - publisher - publicationYear - titles { - title - } - creators { - id - name - affiliation { - id - name - } - } - citationCount - viewCount - downloadCount - } - } - } - } - - name: Fetch 30 dissertations about machine learning - query: | - { - dissertations(query: "machine learning", first: 30) { - totalCount - published{ - id - count - } - nodes { - id - publicationYear - publisher - creators { - id - name - } - titles { - title - } - } - } - } - - name: Fetch the citations of datasets that use the DOI 10.5061/dryad.234 and the citations of those citations - query: | - { - dataset(id: "https://doi.org/10.5061/dryad.234") { - id - titles { - title - } - citationCount - citations { - nodes { - id - publisher - titles { - title - } - citationCount - } - } - } - } - - name: Fetch all the types in the GraphQL schema. - query: | - { __schema { types { name kind } } } From 5ccaa569cf02060cff0c132a333ba05d08c01895 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 10:46:31 +0200 Subject: [PATCH 08/17] Revert "use redirect isntead of serve" This reverts commit b36ff231efc18b94fb49f7ffc3f1c8db3f9aa6eb. --- .well-known/.gitkeep | 0 .well-known/ai-plugin.json | 18 ++ app/controllers/application_controller.rb | 12 +- graphql-openapi.yaml | 230 ++++++++++++++++++++++ 4 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 .well-known/.gitkeep create mode 100644 .well-known/ai-plugin.json create mode 100644 graphql-openapi.yaml diff --git a/.well-known/.gitkeep b/.well-known/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json new file mode 100644 index 000000000..f96abc37a --- /dev/null +++ b/.well-known/ai-plugin.json @@ -0,0 +1,18 @@ +{ + "schema_version": "v1", + "name_for_human": "Science Knowledge Graph", + "name_for_model": "science_knowledge_graph", + "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", + "description_for_model": "Run GraphQL queries against an API hosted by DataCite API. The DataCite API supports most GraphQL query but does not support mutations statements. Use `{ __schema { types { name kind } } }` to get all the types in the GraphQL schema. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{person(id:ORCID) {works(first:50) {nodes {id titles(first: 1){title} publicationYear}}}}` to get the first 50 works of a person based on their ORCID. Mutations statements are not allowed.", + "auth": { + "type": "none" + }, + "api": { + "type": "openapi", + "url": "http://localhost:8065/graphql-openapi.yaml", + "is_user_authenticated": false + }, + "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", + "contact_email": "kj.garza@gmail.com", + "legal_info_url": "https://github.com/kjgarza/science-knowledge-graph-gpt-plugin/blob/master/LICENSE" +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 34a3af20a..6b980a793 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -165,11 +165,19 @@ def skip_bullet end def serve_manifest - redirect_to ENV["PLUGIN_MANIFEST_URL"] || "https://api.datacite.org" + send_file( + "#{Rails.root}/.well-known/ai-plugin.json", + type: "application/json", + disposition: "inline" + ) end def serve_openapi_spec - redirect_to ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" + send_file( + "#{Rails.root}/graphql-openapi.yaml", + type: "text/yaml", + disposition: "inline" + ) end protected diff --git a/graphql-openapi.yaml b/graphql-openapi.yaml new file mode 100644 index 000000000..413083c60 --- /dev/null +++ b/graphql-openapi.yaml @@ -0,0 +1,230 @@ +openapi: 3.0.0 +info: + title: GraphQL Research API + description: An API to manage datasets, researchers, and articles using GraphQL. + version: 1.0.0 +servers: + - url: http://localhost:8065/client-api +paths: + /graphql: + post: + summary: Make a GraphQL query + operationId: graphql_request + description: Send a GraphQL query to the server. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/GraphQLRequest' + responses: + '200': + description: A successful GraphQL response + content: + application/json: + schema: + $ref: '#/components/schemas/GraphQLResponse' + '400': + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' +components: + schemas: + GraphQLRequest: + type: object + required: + - query + properties: + query: + type: string + description: The GraphQL query. + variables: + type: object + description: The variables for the query. + additionalProperties: true + GraphQLResponse: + type: object + properties: + data: + type: object + description: The result of the query. + additionalProperties: true + errors: + type: array + description: A list of errors that occurred during the request. + items: + $ref: '#/components/schemas/Error' + ErrorResponse: + type: object + properties: + errors: + type: array + description: A list of errors that occurred during the request. + items: + $ref: '#/components/schemas/Error' + Error: + type: object + properties: + message: + type: string + description: A description of the error. + locations: + type: array + description: The locations of the errors in the query, if available. + items: + $ref: '#/components/schemas/ErrorLocation' + path: + type: array + description: The path of the field that caused the error, if available. + items: + oneOf: + - type: string + - type: integer + ErrorLocation: + type: object + properties: + line: + type: integer + description: The line number of the error. + column: + type: integer + description: The column number of the error. +x-graphql-types: + - name: Dataset + - name: Work + - name: Software + - name: Organisation + - name: Person + - name: Publication +x-graphql-queries: + - name: Fetch the data and the works linked to the person with ORCID ID 0000-0001-5934-7525 + query: | + { + person(id: "https://orcid.org/0000-0001-5934-7525") { + id + name + givenName + familyName + citationCount + works(hasFunder: true) { + totalCount + published { + title + count + } + resourceTypes { + title + count + } + nodes { + id + type + titles { + title + } + rights { + rights + } + citationCount + } + } + } + } + - name: Fetch all the data about the organization with ROR ID 052gg0110 + query: | + { + organization(id: "https://ror.org/052gg0110") { + id + name + alternateName + citationCount + viewCount + downloadCount + works(hasViews: 100, first: 100) { + totalCount + published { + title + count + } + resourceTypes { + title + count + } + nodes { + id + type + publisher + publicationYear + titles { + title + } + creators { + id + name + affiliation { + id + name + } + } + citationCount + viewCount + downloadCount + } + } + } + } + - name: Fetch 30 dissertations about machine learning + query: | + { + dissertations(query: "machine learning", first: 30) { + totalCount + published{ + id + count + } + nodes { + id + publicationYear + publisher + creators { + id + name + } + titles { + title + } + } + } + } + - name: Fetch the citations of datasets that use the DOI 10.5061/dryad.234 and the citations of those citations + query: | + { + dataset(id: "https://doi.org/10.5061/dryad.234") { + id + titles { + title + } + citationCount + citations { + nodes { + id + publisher + titles { + title + } + citationCount + } + } + } + } + - name: Fetch all the types in the GraphQL schema. + query: | + { __schema { types { name kind } } } From af9294ecf36d2a8edba51a04f4f57dce9970e7da Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 10:53:07 +0200 Subject: [PATCH 09/17] use local file --- .well-known/ai-plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index f96abc37a..b81efcbc0 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -9,7 +9,7 @@ }, "api": { "type": "openapi", - "url": "http://localhost:8065/graphql-openapi.yaml", + "url": "http://api.stage.datacite.org/graphql-openapi.yaml", "is_user_authenticated": false }, "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", From 8edd1161301dd01a897fb53c3f30169c05971aa4 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 10:53:35 +0200 Subject: [PATCH 10/17] still remote spec --- app/controllers/application_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b980a793..1fa57ff95 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -173,11 +173,12 @@ def serve_manifest end def serve_openapi_spec - send_file( - "#{Rails.root}/graphql-openapi.yaml", - type: "text/yaml", - disposition: "inline" - ) + redirect_to ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" + # send_file( + # "#{Rails.root}/graphql-openapi.yaml", + # type: "text/yaml", + # disposition: "inline" + # ) end protected From 14a679af67902d94f7eea0008adf57306591a6dd Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 11:38:13 +0200 Subject: [PATCH 11/17] all local --- app/controllers/application_controller.rb | 11 +++++------ graphql-openapi.yaml | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1fa57ff95..6b980a793 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -173,12 +173,11 @@ def serve_manifest end def serve_openapi_spec - redirect_to ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" - # send_file( - # "#{Rails.root}/graphql-openapi.yaml", - # type: "text/yaml", - # disposition: "inline" - # ) + send_file( + "#{Rails.root}/graphql-openapi.yaml", + type: "text/yaml", + disposition: "inline" + ) end protected diff --git a/graphql-openapi.yaml b/graphql-openapi.yaml index 413083c60..d92635b66 100644 --- a/graphql-openapi.yaml +++ b/graphql-openapi.yaml @@ -4,7 +4,7 @@ info: description: An API to manage datasets, researchers, and articles using GraphQL. version: 1.0.0 servers: - - url: http://localhost:8065/client-api + - url: https://api.stage.datacite.org paths: /graphql: post: From 24ce357070ba65a3e62f1e5867213ee0ce2842ef Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 12:20:57 +0200 Subject: [PATCH 12/17] Update ai-plugin.json --- .well-known/ai-plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index b81efcbc0..dd5f9d864 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -9,7 +9,7 @@ }, "api": { "type": "openapi", - "url": "http://api.stage.datacite.org/graphql-openapi.yaml", + "url": "https://api.stage.datacite.org/graphql-openapi.yaml", "is_user_authenticated": false }, "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", From 3bb5e50022ed8ac62038e9f17012f99540f52e83 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 12:21:52 +0200 Subject: [PATCH 13/17] Update ai-plugin.json --- .well-known/ai-plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index dd5f9d864..3ed34de14 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -12,7 +12,7 @@ "url": "https://api.stage.datacite.org/graphql-openapi.yaml", "is_user_authenticated": false }, - "logo_url": "https://datacite.org/assets/DataCite-Logo_Schwoop.png", + "logo_url": "https://raw.githubusercontent.com/kjgarza/science-knowledge-graph-gpt-plugin/master/science_graph_logo.png", "contact_email": "kj.garza@gmail.com", "legal_info_url": "https://github.com/kjgarza/science-knowledge-graph-gpt-plugin/blob/master/LICENSE" } \ No newline at end of file From 089d1870ea2874fe8012d9b5ff2e2571a63f9600 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 14:17:39 +0200 Subject: [PATCH 14/17] re-serve --- .well-known/.gitkeep | 0 .well-known/ai-plugin.json | 18 -- app/controllers/application_controller.rb | 19 +- graphql-openapi.yaml | 230 ---------------------- 4 files changed, 13 insertions(+), 254 deletions(-) delete mode 100644 .well-known/.gitkeep delete mode 100644 .well-known/ai-plugin.json delete mode 100644 graphql-openapi.yaml diff --git a/.well-known/.gitkeep b/.well-known/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json deleted file mode 100644 index 3ed34de14..000000000 --- a/.well-known/ai-plugin.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "schema_version": "v1", - "name_for_human": "Science Knowledge Graph", - "name_for_model": "science_knowledge_graph", - "description_for_human": "Plugin for discoverying scientific knowledge. You can search for papers, authors, datasets and software.", - "description_for_model": "Run GraphQL queries against an API hosted by DataCite API. The DataCite API supports most GraphQL query but does not support mutations statements. Use `{ __schema { types { name kind } } }` to get all the types in the GraphQL schema. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{ datasets { nodes { id sizes citations { nodes { id titles { title } } } } } }` to get all the citations of all datasets in the API. Use `{person(id:ORCID) {works(first:50) {nodes {id titles(first: 1){title} publicationYear}}}}` to get the first 50 works of a person based on their ORCID. Mutations statements are not allowed.", - "auth": { - "type": "none" - }, - "api": { - "type": "openapi", - "url": "https://api.stage.datacite.org/graphql-openapi.yaml", - "is_user_authenticated": false - }, - "logo_url": "https://raw.githubusercontent.com/kjgarza/science-knowledge-graph-gpt-plugin/master/science_graph_logo.png", - "contact_email": "kj.garza@gmail.com", - "legal_info_url": "https://github.com/kjgarza/science-knowledge-graph-gpt-plugin/blob/master/LICENSE" -} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6b980a793..e2cdcc431 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require 'open-uri' class ApplicationController < ActionController::API include ActionController::HttpAuthentication::Basic::ControllerMethods @@ -165,18 +166,24 @@ def skip_bullet end def serve_manifest - send_file( - "#{Rails.root}/.well-known/ai-plugin.json", + url = ENV["PLUGIN_MANIFEST_URL"] || "https://api.datacite.org" + data = URI.open(url).read + + send_data( + data, type: "application/json", disposition: "inline" ) end def serve_openapi_spec - send_file( - "#{Rails.root}/graphql-openapi.yaml", - type: "text/yaml", - disposition: "inline" + url = ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" + data = URI.open(url).read + + send_data( + data, + type: 'text/yaml', + disposition: 'inline' ) end diff --git a/graphql-openapi.yaml b/graphql-openapi.yaml deleted file mode 100644 index d92635b66..000000000 --- a/graphql-openapi.yaml +++ /dev/null @@ -1,230 +0,0 @@ -openapi: 3.0.0 -info: - title: GraphQL Research API - description: An API to manage datasets, researchers, and articles using GraphQL. - version: 1.0.0 -servers: - - url: https://api.stage.datacite.org -paths: - /graphql: - post: - summary: Make a GraphQL query - operationId: graphql_request - description: Send a GraphQL query to the server. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/GraphQLRequest' - responses: - '200': - description: A successful GraphQL response - content: - application/json: - schema: - $ref: '#/components/schemas/GraphQLResponse' - '400': - description: Bad request - content: - application/json: - schema: - $ref: '#/components/schemas/ErrorResponse' - '500': - description: Internal server error - content: - application/json: - schema: - $ref: '#/components/schemas/ErrorResponse' -components: - schemas: - GraphQLRequest: - type: object - required: - - query - properties: - query: - type: string - description: The GraphQL query. - variables: - type: object - description: The variables for the query. - additionalProperties: true - GraphQLResponse: - type: object - properties: - data: - type: object - description: The result of the query. - additionalProperties: true - errors: - type: array - description: A list of errors that occurred during the request. - items: - $ref: '#/components/schemas/Error' - ErrorResponse: - type: object - properties: - errors: - type: array - description: A list of errors that occurred during the request. - items: - $ref: '#/components/schemas/Error' - Error: - type: object - properties: - message: - type: string - description: A description of the error. - locations: - type: array - description: The locations of the errors in the query, if available. - items: - $ref: '#/components/schemas/ErrorLocation' - path: - type: array - description: The path of the field that caused the error, if available. - items: - oneOf: - - type: string - - type: integer - ErrorLocation: - type: object - properties: - line: - type: integer - description: The line number of the error. - column: - type: integer - description: The column number of the error. -x-graphql-types: - - name: Dataset - - name: Work - - name: Software - - name: Organisation - - name: Person - - name: Publication -x-graphql-queries: - - name: Fetch the data and the works linked to the person with ORCID ID 0000-0001-5934-7525 - query: | - { - person(id: "https://orcid.org/0000-0001-5934-7525") { - id - name - givenName - familyName - citationCount - works(hasFunder: true) { - totalCount - published { - title - count - } - resourceTypes { - title - count - } - nodes { - id - type - titles { - title - } - rights { - rights - } - citationCount - } - } - } - } - - name: Fetch all the data about the organization with ROR ID 052gg0110 - query: | - { - organization(id: "https://ror.org/052gg0110") { - id - name - alternateName - citationCount - viewCount - downloadCount - works(hasViews: 100, first: 100) { - totalCount - published { - title - count - } - resourceTypes { - title - count - } - nodes { - id - type - publisher - publicationYear - titles { - title - } - creators { - id - name - affiliation { - id - name - } - } - citationCount - viewCount - downloadCount - } - } - } - } - - name: Fetch 30 dissertations about machine learning - query: | - { - dissertations(query: "machine learning", first: 30) { - totalCount - published{ - id - count - } - nodes { - id - publicationYear - publisher - creators { - id - name - } - titles { - title - } - } - } - } - - name: Fetch the citations of datasets that use the DOI 10.5061/dryad.234 and the citations of those citations - query: | - { - dataset(id: "https://doi.org/10.5061/dryad.234") { - id - titles { - title - } - citationCount - citations { - nodes { - id - publisher - titles { - title - } - citationCount - } - } - } - } - - name: Fetch all the types in the GraphQL schema. - query: | - { __schema { types { name kind } } } From 0f9eea5929daeca8f8d97f06f1eae7da5bf2020f Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 14:28:49 +0200 Subject: [PATCH 15/17] lint --- app/controllers/application_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e2cdcc431..c8f5c430a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'open-uri' + +require "open-uri" class ApplicationController < ActionController::API include ActionController::HttpAuthentication::Basic::ControllerMethods @@ -170,7 +171,7 @@ def serve_manifest data = URI.open(url).read send_data( - data, + data, type: "application/json", disposition: "inline" ) @@ -179,11 +180,11 @@ def serve_manifest def serve_openapi_spec url = ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" data = URI.open(url).read - + send_data( - data, - type: 'text/yaml', - disposition: 'inline' + data, + type: 'text/yaml', + disposition: 'inline' ) end From 264823f00da1876125d2c8006be759ac99be4333 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 14:33:38 +0200 Subject: [PATCH 16/17] lint --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c8f5c430a..4da39eeec 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -183,8 +183,8 @@ def serve_openapi_spec send_data( data, - type: 'text/yaml', - disposition: 'inline' + type: "text/yaml", + disposition: "inline" ) end From f67c73bb83943fb2e842371c24f5357c7bacbd56 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 16 May 2023 17:47:11 +0200 Subject: [PATCH 17/17] Update cors.rb --- config/initializers/cors.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 740ee2615..5f68d44d3 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -8,9 +8,10 @@ # Rails.application.config.middleware.insert_before 0, Rack::Cors do # allow do -# origins "" # replace with your actual trusted sites -# resource "graphql", -# headers: "*", -# methods: [:get, :post, :head, :options] +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] # end # end