All `astNode` fields are undefined when schema is loaded using buildClientSchema
See original GitHub issueI noticed an issue with loading a GraphQLSchema using introspection JSON.
Given the following introspection JSON: https://gist.github.com/dotansimha/c25f0ce38382086f55f5382da7dcbcb8
If I’m running the following code:
const introspection = require('./schema.json');
const { buildClientSchema } = require('graphql');
const schema = buildClientSchema(introspection);
const allTypes = schema.getTypeMap(); // Valid, all types are there
const rootNode = schema.astNode; // undefined
const allTypesAst = Object.keys(allTypes).map(key => allTypes[key].astNode); // Array of `undefined`
I know buildClientSchema should return a GraphQLSchema without resolvers and anything else, but is there a reason for removing the astNode fields?
My current workaround is to print the schema into a string, parse to into a Document using parse and then build the schema again using buildASTSchema:
const introspection = require('./schema.json');
const { buildClientSchema, buildASTSchema, parse, printSchema } = require('graphql');
const schema = buildClientSchema(introspection);
const validSchema = buildASTSchema(parse(printSchema(schema)));
const allTypesAst = Object.keys(allTypes).map(key => allTypes[key].astNode); // Valid ASTs
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Graphql Ruby - Cannot read property 'types' of undefined at ...
The issue is with schemaIntrospection.types , schemaIntrospection is undefined. So above, I inspected the introspection variable which calls ...
Read more >API Reference: graphql-tools - Apollo GraphQL Docs
Apollo server directly exports all the function from graphql-tools , enabling a migration ... A root field in a subschema from which the...
Read more >graphql SelectionSetNode TypeScript Examples
The following examples show how to use graphql. ... leave(node: ASTNode) { if (!(node.kind === 'Field' || node.kind === 'FragmentDefinition')) return ...
Read more >graphql/utilities
function buildClientSchema. Produces a client schema given the result of querying a schema with `introspectionQuery`. Schema Language. function buildSchema
Read more >graphql-toolkit @ 0.0.5 .. 0.2.9 - Package Diff
+ if (fields.length) {. + return `schema { ${fields.join('\n')} }`;. + }. + return undefined;. +}. +function mergeGraphQLTypes(types, config) {.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Our workaround was to print and reparse the schema to have
astNodepopulated:@dotansimha Sorry for the delay.
astNodeshould always point to the original location provided by the user and intended to be used mainly for error reporting (tie error to the particular location inside user input).Since
buildClientSchemaaccepts JSON it would be strange to report error showing SDL and pointing to the non-existing location.If you have a different use case for
astNodecan you please describe it?You can use
buildSchemawhich is basicallyparse+buildASTSchema.