graphql / vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
https://marketplace.visualstudio.com/items?itemName=Prisma.vscode-graphql
MIT License
555 stars 71 forks source link

Executing Query does not use headers #298

Closed jmarbutt closed 3 years ago

jmarbutt commented 3 years ago

Actual Behavior

When defining schema in .graphqlrc.yml but no end points does not use the headers when executing queries from a query in vs code.

Expected Behavior

It should use the end point with the default schema headers

Steps to Reproduce the Problem Or Description

This is using a docker hosted version of Hasura but any graph ql api should work.

  1. Create a .graphqlrc.yml like the following:
    schema: 
    - http://localhost:8080/v1/graphql:
        headers:
            X-Hasura-Admin-Secret: 123456
    documents:
    - ./src/**/*.tsx
    - ./src/**/*.ts
    - ./src/**/*.graphql
    overwrite: true
    generates:
    ./src/graphql/graphql.ts:
        plugins:
            - typescript
            - typescript-operations
            - typescript-react-apollo
            - typescript-apollo-client-helpers
        config:
            skipTypename: false
            withHooks: true
    ./src/graphql/graphql.schema.graphql:
        plugins: 
            - schema-ast
  2. Create a .graphql file with the a query, for example:

    query getMyAccounts { 
    
        accounts(order_by: { name: asc }) {
            id,
            name
        }
    }
  3. Click Execute Query in Visual studio image
  4. Should run the query.

Specifications

Logs Of TS Server || GraphQL Language Service

The warning in the logs is:

Warning: endpoints missing from graphql config. will try 'schema' value(s) instead
emmiep commented 3 years ago

@jmarbutt Have you tried using the endpoints extension as shown in this example?

I haven't tried using a yaml file for configuration, but I guess in your case it should look something like this:

schema: http://localhost:8080/v1/graphql
extensions:
  endpoints:
    default:
      url: http://localhost:8080/v1/graphql
      headers:
        X-Hasura-Admin-Secret: 123456
acao commented 3 years ago

thanks @emmiep that is the recommended graphql-config usage!

@jmarbutt the schema headers are used for retrieving the remote schema, not necessarily the operations, thats what extensions.endpoints is for.