graphql-code-generator: GraphQLError: Unknown field '__type' on type 'Query' when using flattenGeneratedTypes

Describe the bug

To Reproduce Steps to reproduce the behavior:

Create a GraphQL file that is valid GraphQL:

query FilterInputTypes {
  __type(name: "ProductAttributeFilterInput") {
    inputFields {
      name
      type {
        name
      }
    }
  }
}

See the error while generating: https://codesandbox.io/s/distracted-yonath-hhbqi?file=/package.json

$ yarn codegen
$ graphql-codegen --config ./codegen.yml
  ✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate types.ts
      ✔ Load GraphQL schemas
      ✔ Load GraphQL documents
      ✖ Generate
        → Unknown field '__type' on type 'Query'.


 Found 1 error

  ✖ document.graphql
    GraphQLError: Unknown field '__type' on type 'Query'.
        at createUserError (/sandbox/node_modules/relay-compiler/lib/core/CompilerError.js:35:1
0)
        at GraphQLDefinitionParser._transformField (/sandbox/node_modules/relay-compiler/lib/co
re/RelayParser.js:779:13)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:614:23
        at Array.map (<anonymous>)
        at GraphQLDefinitionParser._transformSelections (/sandbox/node_modules/relay-compiler/l
ib/core/RelayParser.js:610:36)
        at GraphQLDefinitionParser._transformOperation (/sandbox/node_modules/relay-compiler/li
b/core/RelayParser.js:584:27)
        at GraphQLDefinitionParser.transform (/sandbox/node_modules/relay-compiler/lib/core/Rel
ayParser.js:351:21)
        at parseDefinition (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:327:17
)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:154:18
        at eachWithCombinedError (/sandbox/node_modules/relay-compiler/lib/core/CompilerError.j
s:93:9)
        at RelayParser.transform (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:
151:5)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:92:19
        at Object.run (/sandbox/node_modules/relay-compiler/lib/core/GraphQLCompilerProfiler.js
:55:30)
        at Object.transform (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:90:19
)
        at Object.optimizeDocuments (/sandbox/node_modules/@graphql-tools/relay-operation-optim
izer/index.cjs.js:24:40)
        at Object.optimizeOperations (/sandbox/node_modules/@graphql-codegen/visitor-plugin-com
mon/index.cjs.js:2618:50)
    GraphQLError: Unknown field '__type' on type 'Query'.
        at createUserError (/sandbox/node_modules/relay-compiler/lib/core/CompilerError.js:35:1
0)
        at GraphQLDefinitionParser._transformField (/sandbox/node_modules/relay-compiler/lib/co
re/RelayParser.js:779:13)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:614:23
        at Array.map (<anonymous>)
        at GraphQLDefinitionParser._transformSelections (/sandbox/node_modules/relay-compiler/l
ib/core/RelayParser.js:610:36)
        at GraphQLDefinitionParser._transformOperation (/sandbox/node_modules/relay-compiler/li
b/core/RelayParser.js:584:27)
        at GraphQLDefinitionParser.transform (/sandbox/node_modules/relay-compiler/lib/core/Rel
ayParser.js:351:21)
        at parseDefinition (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:327:17
)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:154:18
        at eachWithCombinedError (/sandbox/node_modules/relay-compiler/lib/core/CompilerError.j
s:93:9)
        at RelayParser.transform (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:
151:5)
        at /sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:92:19
        at Object.run (/sandbox/node_modules/relay-compiler/lib/core/GraphQLCompilerProfiler.js
:55:30)
        at Object.transform (/sandbox/node_modules/relay-compiler/lib/core/RelayParser.js:90:19
)
        at Object.optimizeDocuments (/sandbox/node_modules/@graphql-tools/relay-operation-optim
izer/index.cjs.js:24:40)
        at Object.optimizeOperations (/sandbox/node_modules/@graphql-codegen/visitor-plugin-com
mon/index.cjs.js:2618:50)

Expected behavior I would expect it to work as the __type query should be available in any schema, right?

Environment: sandbox

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the hard work everybody, I’ve been testdriving the PR for a while now and it seems to be working perfectly!

I am seeing the same TypeError: parentType.isTypeOf is not a function when I enable Relay optimizer. I added some logging and it seems than none of the parentType objects that come through have it defined.

~Could it be some peer graphql-tools dependency not implementing this? What is responsible for implementing that function?~ edit: seems @SirensOfTitan figured it out and I am just catching up 😅