From e407eebdc9271a87994a715e7bb01d3ac3d68cf7 Mon Sep 17 00:00:00 2001 From: Andriy Komm Date: Thu, 4 May 2017 14:22:36 +0200 Subject: [PATCH 1/4] Add graphiql custom http headers documentation --- .../graphiql/custom-http-headers.md | 48 +++++++++++++++++++ Resources/doc/definitions/graphiql/index.md | 4 ++ Resources/doc/definitions/index.md | 1 + 3 files changed, 53 insertions(+) create mode 100644 Resources/doc/definitions/graphiql/custom-http-headers.md create mode 100644 Resources/doc/definitions/graphiql/index.md 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..796659e22 --- /dev/null +++ b/Resources/doc/definitions/graphiql/custom-http-headers.md @@ -0,0 +1,48 @@ +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 using parameter: + +```yml +# app/config/config_dev.yml +parameters: + overblog_graphql.graphiql_template: 'graphiql.html.twig' +``` +2. Create a new template: + +```twig +{# app/Resources/views/graphiql.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 +{# app/Resources/views/graphiql.html.twig #} +{% extends 'OverblogGraphQLBundle:GraphiQL:index.html.twig' %} + +{% block graphql_fetcher_headers %} +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). From 802cc6e85d93906a15e8b47c2d2b37a222478264 Mon Sep 17 00:00:00 2001 From: Andriy Komm Date: Thu, 4 May 2017 14:53:19 +0200 Subject: [PATCH 2/4] Use bundle configuration for graphiql template --- .../doc/definitions/graphiql/custom-http-headers.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Resources/doc/definitions/graphiql/custom-http-headers.md b/Resources/doc/definitions/graphiql/custom-http-headers.md index 796659e22..b4c87f28d 100644 --- a/Resources/doc/definitions/graphiql/custom-http-headers.md +++ b/Resources/doc/definitions/graphiql/custom-http-headers.md @@ -14,17 +14,18 @@ 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 using parameter: +1. Override the default GraphiQL template: ```yml # app/config/config_dev.yml -parameters: - overblog_graphql.graphiql_template: 'graphiql.html.twig' +overblog_graphql: + templates: + graphiql: AppBundle:GraphiQL:index.html.twig ``` 2. Create a new template: ```twig -{# app/Resources/views/graphiql.html.twig #} +{# AppBundle/Resources/views/GraphiQL/index.html.twig #} {% extends 'OverblogGraphQLBundle:GraphiQL:index.html.twig' %} {% block graphql_fetcher_headers %} From fea98a05b3e5bd88917c49bbbaef12708820856f Mon Sep 17 00:00:00 2001 From: Andriy Komm Date: Thu, 4 May 2017 14:54:42 +0200 Subject: [PATCH 3/4] path fix --- Resources/doc/definitions/graphiql/custom-http-headers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/doc/definitions/graphiql/custom-http-headers.md b/Resources/doc/definitions/graphiql/custom-http-headers.md index b4c87f28d..d11c0798d 100644 --- a/Resources/doc/definitions/graphiql/custom-http-headers.md +++ b/Resources/doc/definitions/graphiql/custom-http-headers.md @@ -25,7 +25,7 @@ overblog_graphql: 2. Create a new template: ```twig -{# AppBundle/Resources/views/GraphiQL/index.html.twig #} +{# src/AppBundle/Resources/views/GraphiQL/index.html.twig #} {% extends 'OverblogGraphQLBundle:GraphiQL:index.html.twig' %} {% block graphql_fetcher_headers %} @@ -40,7 +40,7 @@ headers = { Or append headers instead of replacing the default one: ```twig -{# app/Resources/views/graphiql.html.twig #} +{# src/AppBundle/Resources/views/GraphiQL/index.html.twig #} {% extends 'OverblogGraphQLBundle:GraphiQL:index.html.twig' %} {% block graphql_fetcher_headers %} From 475ef076a9bb2354cd0470fd23a6e3ce5750a884 Mon Sep 17 00:00:00 2001 From: Andriy Komm Date: Thu, 4 May 2017 15:00:55 +0200 Subject: [PATCH 4/4] added parent call --- Resources/doc/definitions/graphiql/custom-http-headers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/doc/definitions/graphiql/custom-http-headers.md b/Resources/doc/definitions/graphiql/custom-http-headers.md index d11c0798d..ea3c6cb9d 100644 --- a/Resources/doc/definitions/graphiql/custom-http-headers.md +++ b/Resources/doc/definitions/graphiql/custom-http-headers.md @@ -44,6 +44,7 @@ Or append headers instead of replacing the default one: {% 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