Graphql-code-generator: [0.14] Unable to specify headers when using schema from url

Created on 16 Nov 2018  Â·  5Comments  Â·  Source: dotansimha/graphql-code-generator

Is your feature request related to a problem? Please describe.
Tried updating from 0.13.0 to 0.14.0.
There are no docs for introspection Pugin and how to provide auth header.

Had this npm script for introspection:
"gql-gen:introspect": "gql-gen --schema http://localhost:4000 --header \"Authorization:[key]\" --template graphql-codegen-introspection-template --out ./src/app/graphql/generated/gql-gen-schema.json"

CLI suggested following config:

schema:
  - "http://localhost:4000"
documents: []
config: {}
generates:
  ./src/app/graphql/generated/gql-gen-schema.json:
    config: {}
    plugins:
      - "introspection"
require: []

Describe the solution you'd like
Add Docs for Introspection Plugin option and Auth header yaml config syntax.

Describe alternatives you've considered

roll back to 0.13.0

Additional context
Also some frustration stitching together the new yaml config.
Before I had the above introspect script and this generate script:
"gql-gen:generate": "gql-gen --schema ./src/app/graphql/generated/gql-gen-schema.json --template graphql-codegen-apollo-angular-template --out ./src/app/graphql/generated/gql-types.ts src/app/graphql/graphql-queries/*.graphql"

Was trail and error to merge it into codegen.yml config:

schema: 
  - http://localhost:4000 
# not sure about Auth header syntax here
  - headers: 
    Authorization:
      - "Bearer [key]"
generates:
  ./src/app/graphql/generated/gql-gen-schema.json:
    plugins:
      - "introspection"
  generates:
    ./src/app/graphql/generated/gql-types.ts:
      config:
        noGraphqlTag: true
    schema:
      - ./src/app/graphql/generated/gql-gen-schema.json
    documents: ./src/app/graphql/graphql-queries/*.graphql
    plugins:
      - typescript-common
      - typescript-client
      - typescript-apollo-angular

And not even sure if this is correct.

Congrats for launching docs and site looks great!

docs waiting-for-release

Most helpful comment

All 5 comments

@qirex thank you for reporting it!

Actually, headers has moved to be an object under the url, so you should be able to do:

schema:
  - "http://localhost:4000":
    headers:
       Authorization: "Bearer [key]"
generates:
  ./src/app/graphql/generated/gql-gen-schema.json:
    plugins:
      - "introspection"

I'm leaving this open because I know there are some things that are not documented yet, but we are working on it now!

Follow up to this (v0.14.1):

Not working:

schema: 
  - "http://localhost:4000":
      headers:
        Authorization: "Bearer [KEY]"
generates:
  ./src/app/graphql/generated/gql-gen-schema.json:
    plugins:
      - "introspection"

Output:

× Load schema
   → (schemaOptions.headers || []).map is not a funct…
   Generate outputs
(schemaOptions.headers || []).map is not a function

~Working:~ See edit

schema: 
  - "http://localhost:4000":
      headers:
      Authorization: "Bearer [KEY]"
generates:
  ./src/app/graphql/generated/gql-gen-schema.json:
    plugins:
      - "introspection"

An error either in docs or implementation?

EDIT:
Second config does not seem to work (files are not updated).
But output is showing success

√ Parse configuration
 √ Parse configuration
 √ Load schema
 √ Generate outputs

Thanks @qirex ! Re-opening until we'll fix the issue with headers as object.

Fixed in 0.14.2 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackhkmatthews picture jackhkmatthews  Â·  3Comments

leebenson picture leebenson  Â·  3Comments

fvisticot picture fvisticot  Â·  3Comments

SimenB picture SimenB  Â·  3Comments

dotansimha picture dotansimha  Â·  3Comments