I am trying to get the schema of the server which is running on localhost.
But running
apollo service:download --endpoint=http://localhost:8080/graphql Output.json
I get the error
Error: Input Object type XYZInput must define one or more fields.
at assertValidSchema (/usr/local/lib/node_modules/apollo/node_modules/graphql/type/validate.js:71:11)
at assertValidExecutionArguments (/usr/local/lib/node_modules/apollo/node_modules/graphql/execution/execute.js:147:35)
at executeImpl (/usr/local/lib/node_modules/apollo/node_modules/graphql/execution/execute.js:68:3)
at execute (/usr/local/lib/node_modules/apollo/node_modules/graphql/execution/execute.js:62:229)
at Object.introspectionFromSchema (/usr/local/lib/node_modules/apollo/node_modules/graphql/utilities/introspectionFromSchema.js:38:37)
at Task.task (/usr/local/lib/node_modules/apollo/lib/commands/service/download.js:16:78)
This is strange because on the server I am getting the same IntrospectionQuery as when I test the url in GraphiQL, then I can see the schema in GraphiQL but not in json file.
Can anyone help me?
@adrian1388 Are you still having trouble with this? From the error message, it looks like you were missing a field inside of your input type like so:
input XYZInput {
}
@JakeDawkins Yes, still...
Yes XYZInput type comes like that, but why it is not a problem for GraphiQL?
@adrian1388 I'm not sure why your graphql service is even able to start up with an error like that.
But, it looks like the schema provider the CLI uses calls buildClientSchema from graphql-js after receiving the introspection results, which has additional validation on the schema passed to it.
My guess is that tools like graphiql don't do this additional validation, but just use the introspection results to show type info.
We can't skip this in the CLI though, since other commands expect the schema that gets built to be valid and safe.
Since this seems to be working as expected, I'm going to close this issue. Feel free to still chime in if you need to :)
Actually, I momentarily deleted the field calling the XYZ type in the server to continue with my tests with the schema.json file.
Thank you for your clarifying comments @JakeDawkins.
Most helpful comment
Actually, I momentarily deleted the field calling the XYZ type in the server to continue with my tests with the
schema.jsonfile.Thank you for your clarifying comments @JakeDawkins.