Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI Connector seems to use incorrect Accept and Content-Type headers #65

Open
durkino opened this issue Nov 14, 2024 · 0 comments
Open

Comments

@durkino
Copy link

durkino commented Nov 14, 2024

Description

I initially hit this issue trying to set up an OpenAPI Connector to some proprietary software. When sending a query to a POST endpoint that only accepts http form data in the application/x-www-form-urlencoded format, it will automatically be sent as multipart/form-data, so the query will fail. If this is supposed to be resolved by populating the headers parameter in the GraphQL query, it's not clear how the that string should be formatted.

I can't share reproduction steps for the original bug since it involves proprietary software, but I found (via the test data) a similar endpoint in the Auckland Museum OpenAPI Specification. They have documentation here and their specification here. We are concerned with the /sparql POST endpoint which produces
["application/sparql-results+json", "application/sparql-results+xml"] and consumes "application/x-www-form-urlencoded". I tried running the sample query in the Auckland Museum documentation . As a curl command it looks like this:

curl -X POST -H "Accept: application/sparql-results+json" -H "Content-Type: application/x-www-form-urlencoded" -d 'query=PREFIX ecrm:<http://erlangen-crm.org/current/>     SELECT ?subject WHERE {       ?subject ecrm:P45_consists_of/ecrm:P2_has_type <http://api.aucklandmuseum.com/id/thesauri/material/AAT.11914>     }     LIMIT 10' "https://api.aucklandmuseum.com/sparql"

I tried translating it to a GraphQL query like this:

mutation MyMutation {
  postSparqlPostSparql(
    data: {query: "PREFIX ecrm:<http://erlangen-crm.org/current/>     SELECT ?subject WHERE {       ?subject ecrm:P45_consists_of/ecrm:P2_has_type <http://api.aucklandmuseum.com/id/thesauri/material/AAT.11914>     }     LIMIT 10"}
  )
}

When I run this query, the trace and connector container logs show a SyntaxError: Unexpected token 'P', \"Please use\"... is not valid JSON. The stack is here:

"err":{"type":"InternalServerError","message":"Error encountered when invoking function 'postSparqlPostSparql'","stack":"Error: Error encountered when invoking function 'postSparqlPostSparql'\n    at invokeFunction (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:184:13)\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async executeMutationOperation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:96:18)\n    at async executeMutation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:69:18)\n    at async Object.mutation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/connector.ts:87:14)\n    at async Object.<anonymous> (/functions/node_modules/@hasura/ndc-sdk-typescript/src/server.ts:251:32)","statusCode":500,"details":{"type":"Object","message":"Unexpected token 'P', \"Please use\"... is not valid JSON","stack":"SyntaxError: Unexpected token 'P', \"Please use\"... is not valid JSON\n    at JSON.parse (<anonymous>)\n    at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)\n    at successSteps (node:internal/deps/undici/undici:5555:27)\n    at fullyReadBody (node:internal/deps/undici/undici:1665:9)\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async specConsumeBody (node:internal/deps/undici/undici:5564:7)\n    at async /functions/api.ts:192:22\n    at async postSparqlPostSparql (/functions/functions.ts:182:18)\n    at async /functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:176:16\n    at async invokeFunction (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:172:12)\n"}}

The "Please use" message is suspiciously similar to their error response "Please use either 'application/sparql-results+json' or 'application/sparql-results+xml' as your 'Accept' header". If this is user error, please let me know the appropriate way to set the headers in the GraphQL query. Thank you!

Reproduction Steps

  1. Install DDN and set the current working directory to be wherever you want to build your test supergraph.
  2. Make sure the CLI is up to date (DDN CLI Version: v2.13.0)
    ddn update-cli
  3. ddn supergraph init .
  4. ddn connector init -i
  5. Pick the hasura/openapi connector. Use default options except for
  • Connector Name: auckland_openapi
  • NDC_OAS_DOCUMENT_URI: https://api.aucklandmuseum.com/apidoc
  • NDC_OAS_BASE_URL: https://api.aucklandmuseum.com
  1. ddn connector introspect auckland_openapi
  2. ddn command add auckland_openapi "*"
  3. ddn supergraph build local
  4. ddn run docker-start
  5. ddn console --local
  6. In the GraphiQL interface, try the following query.
mutation MyMutation {
  postSparqlPostSparql(
    data: {query: "PREFIX ecrm:<http://erlangen-crm.org/current/>     SELECT ?subject WHERE {       ?subject ecrm:P45_consists_of/ecrm:P2_has_type <http://api.aucklandmuseum.com/id/thesauri/material/AAT.11914>     }     LIMIT 10"}
  )
}
  1. Observe the error in the Trace and/or connector container logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant