Skip to content

Commit

Permalink
Merge pull request #17 from Destroy666x/AddParametersBlock
Browse files Browse the repository at this point in the history
Add GraphiQL parameters Twig block
  • Loading branch information
mcg-web committed May 9, 2018
2 parents ffbd3d0 + ba76daa commit b6581c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ More
------------

* [Custom HTTP headers](Resources/doc/custom-http-headers.md)
* [Custom GraphiQL parameters](Resources/doc/custom-parameters.md)
* [Define JavaScript libraries' versions](Resources/doc/libraries-versions.md)
* [Define a custom GraphQL endpoint](Resources/doc/graphql-endpoint.md)

Expand Down
29 changes: 29 additions & 0 deletions Resources/doc/custom-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Custom GraphiQL parameters
==========================

By default, only the `fetcher` parameter is passed to GraphiQL's React component.
To add more:

1. Override the default GraphiQL template:

```yaml
# config/packages/graphiql.yaml or app/config/config.yml for Symfony without Flex
overblog_graphiql:
template: "GraphiQL/index.html.twig"
```

2. Create a new template:

```twig
{# templates/GraphiQL/index.html.twig #}
{% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
{% block graphiql_params %}
{{ parent() }},
defaultQuery: `query SomeQuery($param: String) {
items(param: $param) {
someField
}
}`
{% endblock graphiql_params %}
```
2 changes: 2 additions & 0 deletions Resources/views/GraphiQL/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
ReactDOM.render(
React.createElement(GraphiQL, {
{% block graphiql_params %}
fetcher: graphQLFetcher
{% endblock graphiql_params %}
}),
document.body
)
Expand Down

0 comments on commit b6581c4

Please sign in to comment.