spectaql
spectaql copied to clipboard
Error: Invalid or incomplete schema, unknown type: query_root when using Hasura
When attempting to build docs from a hasura graphql server I receive the follow error. It seems like spectaql does not respond well to hasura's query_root
type.
[aws-cognito:!?][austin@asus-ubuntu:~/Workspace/Sophia/platform/modules/docs]
[14:41:24] 1 $ yarn spectaql config.yaml
yarn run v1.22.5
$ /home/austin/Workspace/Sophia/platform/modules/docs/node_modules/.bin/spectaql config.yaml
/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/graphql/utilities/buildClientSchema.js:117
throw new Error("Invalid or incomplete schema, unknown type: ".concat(typeName, ". Ensure that a full introspection query is used in order to build a client schema."));
^
Error: Invalid or incomplete schema, unknown type: query_root. Ensure that a full introspection query is used in order to build a client schema.
at getNamedType (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/graphql/utilities/buildClientSchema.js:117:13)
at getType (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/graphql/utilities/buildClientSchema.js:110:12)
at getObjectType (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/graphql/utilities/buildClientSchema.js:144:16)
at buildClientSchema (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/graphql/utilities/buildClientSchema.js:66:51)
at graphQLSchemaFromIntrospectionResponse (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/spectaql/app/spectaql/graphql-loaders.js:72:10)
at module.exports (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/spectaql/app/spectaql/index.js:92:25)
at loadData (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/spectaql/app/index.js:165:74)
at module.exports (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/spectaql/app/index.js:169:80)
at Object.<anonymous> (/home/austin/Workspace/Sophia/platform/modules/docs/node_modules/spectaql/bin/spectaql.js:64:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
using the default minimal config.yaml
spectaql:
# logoFile: ./test/fixtures/logo.png
# faviconFile: ./test/fixtures/favicon.png
introspection:
url: https://api.cloud.dev-austinrivas.onework.services/v1/graphql
# metadataFile: ./examples/data/metadata.json
# dynamicExamplesProcessingModule: ./examples/customizations/examples
info:
title: GraphQL API Reference
description: Welcome to the party!
termsOfService: https://www.example.com/terms
contact:
name: API Support
url: http://www.example.com/support
email: [email protected]
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: https://example.com/graphql
description: Production
production: true
Hi @austinrivas - sorry you're having an issue. I've reproduced the problem over here and your intuition was correct.
The queryType
and mutationType
definitions in the Introspection Query returned by your GraphQL endpoint name the "query_root"
and "mutation_root"
as the Types to look for for Queries and Mutations, respectively.
This is a problem because it appears in your schema, the Query and Mutation types are actually named "Query"
and "Mutation"
, respectively, and there are no Types named "query_root"
or "mutation_root"
.
I got your documentation to build by re-writing the queryType.name
and mutationType.name
values to be "Query"
and "Mutation"
, respectively, in this area here.
It seems to me that this schema setup is incorrectly...yet I'm confused as to how a working GraphQL implementation (in this case, Hasura) could return such values if they are not correct. I'm also confused by the fact that the schema returned by your endpoint seems to be acceptable to Playground when I plug it in.
You'll notice that the error is not from spectaql
code, but from graphql
toolkit code. This library is using "graphql": "^14.1.1"
, but perhaps this situation is handled in later versions?
I'm not very familiar with this situation, or Hasura's nuances - do you have any more insight you can offer up before I dig around some more?
Thanks for taking a look and providing a work around for me to start testing.
I'll also cross post this over to the hasura boards to see if I can get some clarification on how the schema types for Query and Mutation are defined.
Same thing happens when using url config with Absinthe
The first few lines from generated SDL file from absinthe generate sdl task is as follows:
"Represents a schema"
schema {
query: RootQueryType
}
...
type RootQueryType {
"A doc"
queryFoo: Bar
...
}
We are also using Absinthe, and having an issue with introspection results causing the error above (both static and dynamic). Absinthe uses the convention RootQueryType
and RootMutationType
as opposed to Query
and Mutation
.
It seems that this library has a rigid opinion on what the root type names should be; which I don't believe is formal spec (as evidenced by the multiple versions out there, and GraphiQL not throwing an error).
I would suggest the library either accept whatever names are used as the roots, or allow the root names to be explicitly declared in the config. Otherwise, we need to resort to static introspection json, and manually swap out the root names each time (not practical).
There seems to have been some sort of bug in the graphql
helpers where if a Schema had a non-standard queryType
or mutationType
type, it would rename each of the types in the types
array of the synthesized IntrospectionQuery response, but it would not change the names in the queryType
and/or mutationType
, and things would break.
So an SDL like this:
schema {
query: RootQueryType
}
type RootQueryType {
"A query"
queryThing: String
}
Would result in an Introspection Query Result like this:
{
__schema: {
queryType: { name: "RootQueryType" },
types: [
{
kind: "OBJECT",
name: "Query",
fields: [
{ name: "queryThing", ... },
...,
],
...,
],
...
}
}
...which will break since there will be no type RootQueryType
found.
This PR should fix things when the SpectaQL user is providing raw SDL schema files...but I would like to see what an Introspection Query Response looks like from an Absinthe GraphQL server that's running a schema with an SDL like the one above.
Does it rename "RootQueryType"
to "Query"
everywhere, or will it all be "RootQueryType"
or will it be something else?
@bjunc can you provide a snippet of a simple introspection query response from an Absinthe GraphQL server running a schema with an SDL like the one above?
A fix for the particular use-case described above should be available now in v0.7.1
...it may also work for other use-cases encountered by users here.
Can you try again with the latest version of SpectaQL?
@bjunc @austinrivas @gfviegas
I'm on 0.9.2 and it works fine with Hasura's query_root
and mutation_root
.