Shopify / graphql-js-schema

Transforms the JSON representation of a GraphQL schema into a set of ES6 type modules
MIT License
35 stars 12 forks source link

TypeError: Cannot read property '__schema' of undefined #36

Open ryangrunest opened 4 years ago

ryangrunest commented 4 years ago

When running

graphql-js-schema --schema-file ./types/types.json --outdir schema --schema-bundle-name="Types"

in the console, it returns TypeError: Cannot read property '__schema' of undefined at generateSchemaModules (/usr/local/lib/node_modules/graphql-js-schema/lib/index.js:136:45) at runCli (/usr/local/lib/node_modules/graphql-js-schema/lib/cli.js:55:39) at Object.<anonymous> (/usr/local/lib/node_modules/graphql-js-schema/lib/cli.js:63:1) at Module._compile (internal/modules/cjs/loader.js:945:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10) at Module.load (internal/modules/cjs/loader.js:798:32) at Function.Module._load (internal/modules/cjs/loader.js:711:12) at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10) at internal/main/run_main_module.js:17:11

roperzh commented 4 years ago

Faced the same issue, if helps somebody: internally this tool expects the schema to be wrapped in a data object, so in order to generate the type definitions I edited my schema.json accordingly:

-  "__schema": {...}
+  "data": {
+    "__schema": {...}
+  }
volkanert commented 4 years ago

Same issue...Anyone has solution?

swalkinshaw commented 4 years ago

As @roperzh said, this tool is designed to be used with the input from an introspection response which starts with the data key: https://github.com/Shopify/graphql-js-schema/blob/43c147f199187f20d761ffa7dc053b1f1993a5fc/src/index.js#L78

I'm curious where your schema file is coming from if not an introspection response. Maybe this should be more flexible to support both formats. We'd welcome a PR if so

itsezc commented 3 years ago

As @roperzh said, this tool is designed to be used with the input from an introspection response which starts with the data key:

https://github.com/Shopify/graphql-js-schema/blob/43c147f199187f20d761ffa7dc053b1f1993a5fc/src/index.js#L78

I'm curious where your schema file is coming from if not an introspection response. Maybe this should be more flexible to support both formats. We'd welcome a PR if so

When using Apollo CLI tooling to download a remote schema, there is no data key. (https://github.com/apollographql/apollo-tooling/blob/be117f3140247b71b792a6b52b2ed26f2f76da02/packages/apollo/src/commands/client/download-schema.ts)