diff --git a/Resources/doc/definitions/graphiql/custom-http-headers.md b/Resources/doc/definitions/graphiql/custom-http-headers.md new file mode 100644 index 000000000..ea3c6cb9d --- /dev/null +++ b/Resources/doc/definitions/graphiql/custom-http-headers.md @@ -0,0 +1,50 @@ +Custom HTTP headers +============== + +GraphiQL, provided by this bundle, sends the following default headers on each request: + +```js +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: + +```yml +# app/config/config_dev.yml +overblog_graphql: + templates: + graphiql: AppBundle:GraphiQL:index.html.twig +``` +2. Create a new template: + +```twig +{# src/AppBundle/Resources/views/GraphiQL/index.html.twig #} +{% extends 'OverblogGraphQLBundle: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: + +```twig +{# src/AppBundle/Resources/views/GraphiQL/index.html.twig #} +{% extends 'OverblogGraphQLBundle:GraphiQL:index.html.twig' %} + +{% block graphql_fetcher_headers %} +{{ parent() }} +headers["access-token"] = "sometoken"; +{% endblock graphql_fetcher_headers %} +``` \ No newline at end of file diff --git a/Resources/doc/definitions/graphiql/index.md b/Resources/doc/definitions/graphiql/index.md new file mode 100644 index 000000000..81e0210f7 --- /dev/null +++ b/Resources/doc/definitions/graphiql/index.md @@ -0,0 +1,4 @@ +GraphiQL +======== + +* [Custom HTTP headers](custom-http-headers.md) \ No newline at end of file diff --git a/Resources/doc/definitions/index.md b/Resources/doc/definitions/index.md index a80948276..5e9c51f81 100644 --- a/Resources/doc/definitions/index.md +++ b/Resources/doc/definitions/index.md @@ -13,5 +13,6 @@ Go further * [Builders](builders/index.md) * [Expression language](expression-language.md) * [Debug](debug/index.md) +* [GraphiQL](graphiql/index.md) Next step [Data fetching](../data-fetching/index.md).