Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 1.19 KB

custom-http-headers.md

File metadata and controls

49 lines (39 loc) · 1.19 KB

Custom HTTP headers

GraphiQL, provided by this bundle, sends the following default headers on each request:

headers = {
  "Accept": "application/json",
  "Content-Type": "application/json"
};

Headers sent by GraphiQL can be modified. For example, let's assume an access-token header is required in development. The header can be added the following way:

  1. Override the default GraphiQL template:
# config/packages/graphiql.yaml or app/config/config.yml for Symfony without Flex
overblog_graphiql:
    template: "GraphiQL/index.html.twig"
  1. Create a new template:
{# templates/GraphiQL/index.html.twig #}
{% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}

{% block graphql_fetcher_headers %}
headers = {
  "Accept": "application/json",
  "Content-Type": "application/json",
  "access-token": "sometoken"
};
{% endblock graphql_fetcher_headers %}

Or append headers instead of replacing the default one:

{# templates/GraphiQL/index.html.twig #}
{% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}

{% block graphql_fetcher_headers %}
{{ parent() }}
headers["access-token"] = "sometoken";
{% endblock graphql_fetcher_headers %}