Update the error message `Ensure that you are passing "data" property of introspection response`
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Say you have a malformed JSON schema that is not in the form expected by the relay compiler. It contains `__schema` as a top level key, but is missing the outer-most `data` key:
```json
{
"__schema": {
"queryType": {
"name": "Query"
},
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
}
],
"directives": []
}
}
```
This is malformed according to relay *but is a very normal format to work with*, as it is:
* Output by graphene python library: https://github.com/graphql-python/graphene/issues/3#issuecomment-146725768
* Discussed in online articles in this form. For example [this Apollo blog post](https://www.apollographql.com/blog/backend/schema-design/three-ways-to-represent-your-graphql-schema/) talks about different formats for storing GraphQL schemas, and their JSON example [available here](https://gist.github.com/stubailo/c542779b872ae56fe69b332c68732e69) doesn't have a top-level "data" key.
* Many others
If you try to compile this JSON schema by running `npx relay-compiler --src ./some/dir/ --schema ./schema.json --extensions js`, the compiler will print this error:
```
Error: Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: undefined.
at devAssert (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/graphql/jsutils/devAssert.js:12:11)
at buildClientSchema (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/graphql/utilities/buildClientSchema.js:47:125)
at getSchemaSource (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/relay-compiler/bin/relay-compiler:8442:26)
at Object.getCodegenRunner (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/relay-compiler/bin/relay-compiler:8254:16)
at /media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/relay-compiler/bin/relay-compiler:8170:40
at Generator.next ()
at asyncGeneratorStep (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/media/michael/Storage2/Programming/HydDb2/hyddb-frontend/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
```
> Error: Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response
This is a confusing error. It sounds like it's saying "return the data key of the introspection, ie `introspection["data"]`", when it's actually saying "return an object with the introspection nested inside a data key, ie `{"data": introspection}`".
I propose that this error message is updated into a clearer format, which ideally links to a `schema.json` *in the correct format*. For example:
> Error: Invalid or incomplete introspection result. `schema.json` must be a JSON object of the form
```
{
"data": {
"__schema": {
"queryType": {...},
"types": [...],
}
}
}
```
> Please refer to `` for a complete example of the JSON format.
Finally, for others' reference, here's a minimal JSON schema that *does* compile, and what relay expects. Note that I've simply added an object to the top level with a `data` key:
```
{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
}
],
"directives": []
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.