apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

apollo client:codegen --target typescript gives TypeError: context.getErrors is not a function #1947

Closed anark closed 4 years ago

anark commented 4 years ago

Intended outcome:

I am intending to export my graphql types to typescript types using apollo client:codegen --target typescript I expect to generate types in the generated folder My Apollo client is running on @apollo/client v3.0.beta

Actual outcome: I get the following error

    at getValidationErrors (node_modules/apollo-language-server/lib/errors/validation.js:25:20)
    at Object.validateQueryDocument node_modules/apollo-language-server/lib/errors/validation.js:30:34)
    at Object.generate [as default] (node_modules/apollo/lib/generate.js:23:18)
    at write node_modules/apollo/lib/commands/client/codegen.js:78:54)
    at Task.task (node_modules/apollo/lib/commands/client/codegen.js:98:46)

How to reproduce the issue:

Run apollo codegen against a react app using @apollo/client v3.0.beta

Versions apollo cli 2.27.4 @apollo/client v3.0.beta

juliovedovatto commented 4 years ago

@anark I faced this issue when using graphl@15 dependency. I believe if you downgrade to version graphql@14, will sove the issue.

That did the trick in my case.

anark commented 4 years ago

Downgrading to graphql@14 solved this. Is there anyway to fix this to make it compatible with graphql@15?

juliovedovatto commented 4 years ago

@abernix I noticed your made a new release of apollo-language-server, but I'm still getting error when using codegen with typescript support, using graphql@15.0.0

This line: https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-language-server/src/errors/validation.ts#L63

TypeError: context.getErrors is not a function

Could you take a look, please?

PS: graphql@14.6.0 works fine

bensalilijames commented 4 years ago

PR #1908 fixes this 🙂

hamzahsn commented 4 years ago

@benhjames unfortunately this PR is not yet merged so we cannot upgrade to it yet 😞

abernix commented 4 years ago

@anark @hamzahsn:

I'm copying and pasting the comments from @trevor-scheer on #1908 so you make sure you see them and can help test:

Update: The releases associated with this change can be found on the next dist-tag for the following packages.

apollo-graphql@0.5.0-alpha.0apollo-language-server@1.23.0-alpha.0apollo@2.29.0-alpha.0

To install the CLI from the next dist-tag, for example: npm i -D apollo@next

I'll be closing this PR in favor of the previously mentioned PRs. Thanks again @benhjames for the help with this!

Please try them out and provide feedback on the release PR #2032. Barring any issues I'll release this officially before the end of the week.

Please try the next versions and report back with updates!

juliovedovatto commented 4 years ago

Just an update: I was following #1908 and now I'm using apollo@next package.

It is working with GraphQL 15 as expected for the project I'm working on.

trevor-scheer commented 4 years ago

Thanks for the update @juliovedovatto! I'm preparing the release to latest as we speak, so expect to see apollo@2.29.0 in the next 10 minutes or so.

rainysiu commented 4 years ago

"apollo": "^2.29.0" works