hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.14k stars 2.77k forks source link

Error trying to introspect hasura/openapi #10530

Closed beddows closed 1 month ago

beddows commented 1 month ago

Component

c/v3-cli, c/v3-ndc-openapi

What is the current behaviour?

When running the following:

ddn supergraph init .

6:45PM INF Created file "hasura.yaml"
6:45PM INF Created file "supergraph.yaml"
6:45PM INF Created file ".env"
6:45PM INF Created file "compose.yaml"
6:45PM INF Created directory "engine"
6:45PM INF Created file "engine/.env.engine"
6:45PM INF Created file "otel-collector-config.yaml"
6:45PM INF Created file ".gitignore"
6:45PM INF Created file ".gitattributes"
6:45PM INF Created directory ".vscode"
6:45PM INF Created file ".vscode/launch.json"
6:45PM INF Created file ".vscode/extensions.json"
6:45PM INF Created file ".vscode/tasks.json"
6:45PM INF Created directory ".devcontainer"
6:45PM INF Created file ".devcontainer/devcontainer.json"
6:45PM INF Created directory "globals"
6:45PM INF Created file "globals/subgraph.yaml"
6:45PM INF Created file "globals/auth-config.hml"
6:45PM INF Created file "globals/compatibility-config.hml"
6:45PM INF Created file "globals/graphql-config.hml"
6:45PM INF Created directory "engine/build"
6:45PM INF Created file "engine/build/auth_config.json"
6:45PM INF Created file "engine/build/open_dd.json"
6:45PM INF Created file "engine/build/metadata.json"
6:45PM INF Created directory "app"
6:45PM INF Created file "app/subgraph.yaml"
6:45PM INF Created file ".hasura/context.yaml"
6:45PM INF Key "subgraph" set to "app/subgraph.yaml" in the context.
6:45PM INF Key "supergraph" set to "supergraph.yaml" in the context.
6:45PM INF Key "localEnvFile" set to ".env" in the context.
6:45PM INF Supergraph initialized in directory "." successfully
6:45PM INF A Subgraph "globals" was created with the supergraph-level metadata objects.
6:45PM INF A Subgraph "app" was created to get you started with building your API.
HINT Add a Connector to the Subgraph: ddn connector init -i

ddn connector init my_connector -i

6:45PM INF Using Subgraph "app/subgraph.yaml" found in context.
? Hub Connector hasura/openapi
? Port 4502
Provide the env vars for the connector. Press enter to use the default value or if no default is available, then nil value
? NDC_OAS_DOCUMENT_URI (The URI of OAS Document. If not provided, the connector will look for
`/etc/connector/swagger.json` by default) ./trilium.yaml
? NDC_OAS_BASE_URL (Base url of the API) http://localhost:8080/etapi
? NDC_OAS_LAMBDA_PRETTY_LOGS (Print logs in a human readable format instead of JSON) true
? NDC_OAS_FILE_OVERWRITE (Overwrite previously generated functions.ts file and api.ts file) false
7:05PM INF Using localEnvFile ".env" found in context.
7:05PM INF Created directory "app/connector/my_connector"
7:05PM INF Created file "app/connector/my_connector/connector.yaml"
7:05PM INF Created file "app/connector/my_connector/compose.yaml"
7:05PM INF Created file "app/connector/my_connector/.ddnignore"
7:05PM INF Created file "app/metadata/my_connector.hml"
7:05PM INF Connector URLs added to env file ".env" successfully
7:05PM INF Connector "my_connector" initialized in Subgraph "app" successfully
HINT Introspect data source: ddn connector introspect my_connector

ERROR: ddn connector introspect my_connector

7:06PM INF Using Subgraph "app/subgraph.yaml" found in context. 7:06PM INF Using localEnvFile ".env" found in context. [23:06:50.421] FATAL (1): Cannot create property 'info' on string 'error while fetching data from URL ""' err: { "type": "TypeError", "message": "Cannot create property 'info' on string 'error while fetching data from URL \"\"'", "stack": TypeError: Cannot create property 'info' on string 'error while fetching data from URL ""' at /app/node_modules/swagger-typescript-api/src/swagger-schema-resolver.js:71:19 at new Promise () at SwaggerSchemaResolver.convertSwaggerObject (/app/node_modules/swagger-typescript-api/src/swagger-schema-resolver.js:69:12) at SwaggerSchemaResolver.create (/app/node_modules/swagger-typescript-api/src/swagger-schema-resolver.js:59:23) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async CodeGenProcess.start (/app/node_modules/swagger-typescript-api/src/code-gen-process.js:86:21) at async Object.generateApi (/app/node_modules/swagger-typescript-api/src/index.js:21:12) at async Object.generateApiTsCode (/app/dist/app/generator/api-ts-generator.js:46:34) at async Object.generateCode (/app/dist/app/generator/index.js:35:23) at async Object.runApp (/app/dist/app/index.js:44:27) } Cannot create property 'info' on string 'error while fetching data from URL ""' 7:06PM ERR introspect failed with error: exit status 1

The image ghcr.io/hasura/ndc-open-api-lambda:v0.1.2 is in Docker.

What is the expected behaviour?

Expected the introspection to complete.

How to reproduce the issue?

I've tried this with several validated OpenAPI specs, same error. Using macOS Sonoma 14.5, Docker Desktop 4.34.0.

m-Bilal commented 1 month ago

@beddows Hi! Thank you for reporting this. Can you please point me to any OpenAPI Document URL that gives you this error?

beddows commented 1 month ago

@m-Bilal Apologies, I should have attached it. Please rename to yaml.

trilum.txt

m-Bilal commented 1 month ago

Found the issue! It's here:

NDC_OAS_DOCUMENT_URI (The URI of OAS Document. If not provided, the connector will look for /etc/connector/swagger.json by default) ./trilium.yaml

What's happening here, is that this file (trilium.yaml) is not being mounted to the container as swagger.json. If you want the connector to the OpenAPI Spec from a file, it must be named swagger.json, and it must be mounted to /etc/connector/. Otherwise, the connector will expect a URL from which it can fetch the OpenAPI Spec.

m-Bilal commented 1 month ago

@beddows let me know please if the explanation helps with the fix

beddows commented 1 month ago

@m-Bilal Just seeing this now, will try it out. Thanks!