drupal-graphql / graphql

GraphQL integration for Drupal 9/10
288 stars 201 forks source link

Integrate graphiql's support of headers in the explorer #1392

Open jasonawant opened 8 months ago

jasonawant commented 8 months ago

It appears that within Drupal.behaviors.graphQLRenderExplorer here, the fetch request does not use the graphiql supported explorer headers.

It looks like the fetch assigns its own headers.

    // Defines a GraphQL fetcher using the fetch API.
    const graphQLFetcher = graphQLParams => fetch(settings.graphqlRequestUrl, {
      method: 'post',
      credentials: 'same-origin',
      body: JSON.stringify(graphQLParams),
      headers: {
        'Content-Type': 'application/json',
      },
    }).then(response => response.json());

graphiql supports sending custom request headers through its UI as seen in the screen shot below. image

Am I looking at this correctly?

It would be sweet to send custom request headers, e.g. Authorization bearer tokens with the request.