Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Resources/doc/definitions/graphiql/custom-http-headers.md
Original file line number Diff line number Diff line change
@@ -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 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing parent call in this example: {{ parent() }}

{{ parent() }}
headers["access-token"] = "sometoken";
{% endblock graphql_fetcher_headers %}
```
4 changes: 4 additions & 0 deletions Resources/doc/definitions/graphiql/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GraphiQL
========

* [Custom HTTP headers](custom-http-headers.md)
1 change: 1 addition & 0 deletions Resources/doc/definitions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).