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:
- 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"
- 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 %}