Closed davetapley closed 5 years ago
I don't even know who created yaml
format instead of just using json
. What a bad invention, which leads to cascade bad practices :(
@revskill10 We support JSON config as well :) @dukedave you can use environment variables to pass it, see this: https://github.com/dotansimha/graphql-code-generator/pull/1368
@dotansimha great! Should I do a PR to update the docs?
@dukedave It would be great :)
headers:
"${x-hasura-admin-secret:MYKEY}"
"${content-type:application/json}"
??
Help me pls.
Docs are updated now: https://graphql-code-generator.com/docs/getting-started/codegen-config#environment-variables
@Pomazan-Bogdan you should use:
headers:
x-hasura-admin-secret: ${MYKEY}
content-type: ${CONTENT_TYPE:application/json}
headers: x-hasura-admin-secret: ${MYKEY} content-type: ${CONTENT_TYPE:application/json}
@dotansimha Not Work(
TypeError: Cannot create property 'source' on string 'Unable to download schema from remote: Missing Authorization header in JWT authentication mode'
overwrite: true
schema: https://graphql.ecoalition.org.ua/v1/graphql
headers:
- x-hasura-admin-secret: {1PocfEqWXPPMX***}
- content-type: ${CONTENT_TYPE:application/json}
documents: "src/**/*.graphql"
generates:
src/graphql/index.tsx:
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
src/graphql/fragments.tsx:
plugins:
- fragment-matcher
@Pomazan-Bogdan it looks like you need to specify Authorization
header but you didn't... please make sure what is the name of the headers that you need to pass.
@dotansimha )) x-hasura-admin-secret
@Pomazan-Bogdan can you try this way?
headers:
x-hasura-admin-secret: {1PocfEqWXPPMX***}
content-type: ${CONTENT_TYPE:application/json}
@dotansimha not work too
@Pomazan-Bogdan my bad, can you try this? also, does the actual values works (without env vars)?
schema:
- https://graphql.ecoalition.org.ua/v1/graphql:
headers:
x-hasura-admin-secret: {1PocfEqWXPPMX***}
content-type: ${CONTENT_TYPE:application/json}
also, which version of the codegen do you use?
@dotansimha
TypeError: Cannot create property 'source' on string 'Unable to download schema from remote: invalid x-hasura-admin-secret/x-hasura-access-key'
=
{ "errors": [ { "extensions": { "path": "$", "code": "access-denied" }, "message": "invalid x-hasura-admin-secret/x-hasura-access-key" } ] }
schema:
- https://graphql.ecoalition.org.ua/v1/graphql:
headers:
x-hasura-admin-secret: {1PocfEqWX*****}
content-type: ${CONTENT_TYPE:application/json}
"@graphql-codegen/cli": "^1.4.0", О_о "gen:graphql": "gql-gen --config codegen.yml",
Can you try with the explicit values?
schema:
- https://graphql.ecoalition.org.ua/v1/graphql:
headers:
X-Hasura-Admin-Secret: PUT_SECRET_HERE
Content-Type: application/json
also, does an introspection request works for you? with tools like GraphQL Playground (or Postman)
@dotansimha This format works! Thank.
I think this should be mentioned separately in the documentation.
@Pomazan-Bogdan It's documents in our website: https://graphql-code-generator.com/docs/getting-started/schema-field#url
add to documents line "Content-Type: application/json" as sample?)
I mean that I saw the documentation, but I couldn’t understand what to do. Without the second line. and not abstract, not perceived (
@Pomazan-Bogdan The example just shows how to add any header, not specific ones.
I even think you can remove Content-Type: application/json
because the HTTP request that the codegen does it an introspection, which is already JSON.
Can someone also please update the docs on how to turn on DEBUG and VERBOSE modes? It currently says to set them as environment variables in the but how to do that is unclear at the moment :) https://graphql-code-generator.com/docs/getting-started/codegen-config/#debug-mode
Setting environmental variables depends on your OS. Let's say on POSIX(Mac, Linux etc) environments you can set an environmental variable only for that command like below;
DEBUG=1 yarn graphql-codegen
Brilliant, thanks!
I don't even know who created
yaml
format instead of just usingjson
. What a bad invention, which leads to cascade bad practices :(
Sidenote for the history books: Yaml was released in 2001. Douglas Crockford released json in 2002.
I know this issue is closed but if somebody lands here to figure out why their Headers aren't picked up, even though you configured them in your .yml
config file, it seems that correct indentation is the key to get this working. I am using Hasura and require a x-hasura-admin-secret
Header in my setup but I could not get it to work, no matter what instructions I followed (which is how I ended up here). The only thing that worked for me was to have 2 tabs indentation in front of headers
, i.e. this works:
schema:
- ${SCHEMA_PATH}:
headers:
x-hasura-admin-secret: ${HASURA_ADMIN_SECRET}
This does not work:
schema:
- ${SCHEMA_PATH}:
headers:
x-hasura-admin-secret: ${HASURA_ADMIN_SECRET}
This would produce Failed to load schema from http://localhost:8080/v1/graphql,headers:
As you can see, the actual value of headers
is missing.
@mvilrokx I've been fiddling with this for the last 30 minutes and the fix was actually to indent the headers
just like you said. This is what worked for me:
Is your feature request related to a problem? Please describe.
Hardcoding
YOUR-TOKEN-HERE
when specifying the schema with a URL may require checking secrets in to version control (incodegen.yml
) to usegraphql-codegen
on a CI server.Describe the solution you'd like
Be able to pass headers in via the CLI, or support variables in YAML.
Describe alternatives you've considered
codegen.yml
with a placeholder, and usingsed
to insert the secret.--header
switch.Additional context
It appears a
--header
switch was supported, but was removed on 0.14.0 😞Prisma support variables in YAML like this.