Passing an auth token when running GraphQL codegen #6272
Unanswered
heinrichdude
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Have you seen this? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have a HotChocolate GraphQL implementation protected by Keycloak. In the GraphQL code we put an [Authorize] attribute on the Queries and Mutations which enforces the user calling them to be authenticated. That all works well.
The issue we are running into is when we try to run codegen, it fails getting the schema due to the token being required.
I have tried a couple methods will no success so far. The one I feel I am closest with is referenced on the following page under the Javascript Exports section. https://www.graphql-code-generator.com/docs/getting-started/schema-field
Our yml file the we are trying to recreate (it works as longs as authentication is turned of) is as follows:
We run it via a simple 'npm run codegen'
With the changes to accomodate the authentication we have change the schema line in the above yml file to:
schema: myCode.js
myCode.js is as follows:
This external code always results in the following:
Unable to find any GraphQL type definitions for the following pointers:
- schema.js
I feel its promising that I can take these two methods above and run them in a separate node.js script and I can see the token and the schema being logged to the console ... so it feels like its close. Passing the token via the loadSchema function works.
Annoyingly I can't seem to view the console logs under 'npm run codegen'
Any solutions / advice would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions