Intended outcome:
When running codegen when the project is configured to use a schema from Apollo Engine, yet when the ENGINE_API_KEY environment variable is not defined, loading the schema should fail with a descriptive error, suggesting perhaps that the user is missing an Apollo Engine API key, or the user lacks permissions to obtain the schema, or the Apollo project is misconfigured.
Actual outcome:
When running codegen when the project is configured to use a schema from Apollo Engine, yet when the ENGINE_API_KEY environment variable is not defined, loading the schema fails with a cryptic error, e.g.
Error: Error initializing Apollo GraphQL project "myproject": Error: Error in "Loading schema for myproject": TypeError: Cannot read property 'startsWith' of undefined
How to reproduce the issue:
Create a dummy project configured to have schema pulled from Apollo Engine, and then run codegen on the project with the API key missing.
I was getting the same error, but when starting VS Code with Apollo GrapQL extension.
Turns out had mistakenly removed my .env file, so my ENGINE_API_KEY was missing.
The error message could definitely be more helpful :)
I have the same error, I do have the .env file, but I don't use Apollo engine. If I replace my env variables with their values, then it works. Is the engine mandatory to use this extension because I didn't read that anywhere?
Same problem here, I don't use Apollo engine
I had the same error in conjunction with apollo for a corner case (no query), but it was due an error on my part. In the context handler, I had this code:
if (!request.query.startsWith('query IntrospectionQuery'))
That should've guarded against an undefined request
if (!request?.query?.startsWith('query IntrospectionQuery'))
A little bit of useful stack tracing from Apollo would've saved me an hour of wasted time.
Most helpful comment
Same problem here, I don't use Apollo engine