Graphql-code-generator: Unable to find field "(...)" on type "(...)"

Created on 7 Jan 2020  Â·  10Comments  Â·  Source: dotansimha/graphql-code-generator

Hey @dotansimha, here's a case where the same error happens https://codesandbox.io/s/ecstatic-hill-f2dbd:

 Found 1 error

  ✖ .
    Error: Unable to find field "barRequired" on type "Query"!
        at Object.enter (/sandbox/node_modules/@graphql-codegen/plugin-helpers/i
ndex.cjs.js:154:39)
        at Object.visit (/sandbox/node_modules/graphql/language/visitor.js:242:2
6)
        at Object.isUsingTypes (/sandbox/node_modules/@graphql-codegen/plugin-he
lpers/index.cjs.js:121:13)
        at documents.map.documentFile (/sandbox/node_modules/@graphql-codegen/ne
ar-operation-file-preset/index.cjs.js:182:27)
        at Array.map (<anonymous>)
        at resolveDocumentImportStatements (/sandbox/node_modules/@graphql-codeg
en/near-operation-file-preset/index.cjs.js:179:22)
        at Object.buildGeneratesSection (/sandbox/node_modules/@graphql-codegen/
near-operation-file-preset/index.cjs.js:226:25)
        at Listr.task.wrapTask (/sandbox/node_modules/@graphql-codegen/cli/bin.j
s:758:64)
        at process._tickCallback (internal/process/next_tick.js:68:7)
    Error: Unable to find field "barRequired" on type "Query"!
        at Object.enter (/sandbox/node_modules/@graphql-codegen/plugin-helpers/i
ndex.cjs.js:154:39)
        at Object.visit (/sandbox/node_modules/graphql/language/visitor.js:242:2
6)
        at Object.isUsingTypes (/sandbox/node_modules/@graphql-codegen/plugin-he
lpers/index.cjs.js:121:13)
        at documents.map.documentFile (/sandbox/node_modules/@graphql-codegen/ne
ar-operation-file-preset/index.cjs.js:182:27)
        at Array.map (<anonymous>)
        at resolveDocumentImportStatements (/sandbox/node_modules/@graphql-codeg
en/near-operation-file-preset/index.cjs.js:179:22)
        at Object.buildGeneratesSection (/sandbox/node_modules/@graphql-codegen/
near-operation-file-preset/index.cjs.js:226:25)
        at Listr.task.wrapTask (/sandbox/node_modules/@graphql-codegen/cli/bin.j
s:758:64)
        at process._tickCallback (internal/process/next_tick.js:68:7)

Thanks!

bug presets waiting-for-release

All 10 comments

I have the same problem on my project, could you guys take a look on this?

Yeah, same error here, with a field that's never queried for directly on Query 🤔 No errors using ^1.8.0

It mostly happens when presets, since validations are different and it's a bit more complex because we need to understand what each file needs to generate and what to import from other files.
I guess it's happening again we didn't cover all possible edge cases of isUsingTypes in our tests.

I can confirm that it still happens on 1.11.2 with the schema you provided. Working on a fix now :)

I think I managed to fix that. I reimplemented isUsingTypes with a better visitor (based on SelectionSetNode), so now it should work for more use-cases.

@andreyvital @gabrielsch @lukasluecke @ivansky can you please try this alpha? 1.11.3-alpha-fceb6efe.61

On 1.11.3-alpha-fceb6efe.61 i'm receiving error regarding pascalCase

@dotansimha 1.11.3-alpha-fceb6efe.61 seems work for me, except issue with missing fragment doc import.

@yoavain-sundaysky It's a different issue, I think @ardatan already solved it, right?
@ivansky same :)

Fixed in v1.12.0

Was this page helpful?
0 / 5 - 0 ratings