`Unable to find field "__type" on type "Query"` with presets `import-types` and `near-operation-file`
#110 aperta il 14 apr 2020
Metriche repository
- Star
- (136 star)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
Describe the bug
When I have a query against Query.__type() in combination with import-types or near-operation, graphql-codegen fails:
yarn run v1.22.0
$ yarn gql:download && yarn gql:generate
$ get-graphql-schema http://127.0.0.1:8000 > src/graphql/schema.graphql
$ yarn gql:codegen
$ graphql-codegen --config codegen.yml
✔ Parse configuration
❯ Generate outputs
✔ Generate src/graphql/graphql-types.tsx
❯ Generate to src/graphql/graphql-operations.tsx (using EXPERIMENTAL preset "
import-types")
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Generate
→ Unable to find field "__type" on type "Query"!
✔ Generate src/graphql/fragment-introspection.ts
Found 1 error
✖ src/graphql/graphql-operations.tsx
Error: Unable to find field "__type" on type "Query"!
at nextTypeName (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:141:39)
at Object.enter (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:160:23)
at Object.visit (/base/node_modules/graphql/language/visitor.js:242:26)
at Object.isUsingTypes (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:121:13)
at options.documents.map.documentFile (/base/node_modules/@graphql-codegen/import-types-preset/index.cjs.js:30:31)
at Array.map (<anonymous>)
at Object.buildGeneratesSection (/base/node_modules/@graphql-codegen/import-types-preset/index.cjs.js:29:27)
at Listr.task.wrapTask (/base/node_modules/@graphql-codegen/cli/bin.js:799:64)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error: Unable to find field "__type" on type "Query"!
at nextTypeName (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:141:39)
at Object.enter (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:160:23)
at Object.visit (/base/node_modules/graphql/language/visitor.js:242:26)
at Object.isUsingTypes (/base/node_modules/@graphql-codegen/plugin-helpers/index.cjs.js:121:13)
at options.documents.map.documentFile (/base/node_modules/@graphql-codegen/import-types-preset/index.cjs.js:30:31)
at Array.map (<anonymous>)
at Object.buildGeneratesSection (/base/node_modules/@graphql-codegen/import-types-preset/index.cjs.js:29:27)
at Listr.task.wrapTask (/base/node_modules/@graphql-codegen/cli/bin.js:799:64)
at process._tickCallback (internal/process/next_tick.js:68:7)
Something went wrong
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[1] 12898 exit 1 yarn gql
To Reproduce
When I dump everything into one target file with plugins
- typescript
- typescript-operations
- typescript-react-apollo
I get no error, but once I split it up into multiple files & change the preset to either import-types or near-operation-file, I get the error message
Unable to find field "__type" on type "Query"
True, that field is not explicitly part of my Query type in the schema, but it should be there implicitly for every schema.
It seems that these implicit fields are not available from the presets?
Steps to reproduce the behavior:
Use a query like
export const GetFilterInfo = gql`
query FilterInfo($filterName: String!) {
__type(name: $filterName) {
kind
name
description
inputFields {
name
type {
kind
name
}
}
}
}
`;
with the presets import-types or near-operation-file.
Expected behavior
No error message, files get generated.
Environment:
- OS: Linux
@graphql-codegen/^1.13.2:- NodeJS: 10.17.0