Skip to content

Commit b6581c4

Browse files
authored
Merge pull request #17 from Destroy666x/AddParametersBlock
Add GraphiQL parameters Twig block
2 parents ffbd3d0 + ba76daa commit b6581c4

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ More
8686
------------
8787

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

Resources/doc/custom-parameters.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Custom GraphiQL parameters
2+
==========================
3+
4+
By default, only the `fetcher` parameter is passed to GraphiQL's React component.
5+
To add more:
6+
7+
1. Override the default GraphiQL template:
8+
9+
```yaml
10+
# config/packages/graphiql.yaml or app/config/config.yml for Symfony without Flex
11+
overblog_graphiql:
12+
template: "GraphiQL/index.html.twig"
13+
```
14+
15+
2. Create a new template:
16+
17+
```twig
18+
{# templates/GraphiQL/index.html.twig #}
19+
{% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
20+
21+
{% block graphiql_params %}
22+
{{ parent() }},
23+
defaultQuery: `query SomeQuery($param: String) {
24+
items(param: $param) {
25+
someField
26+
}
27+
}`
28+
{% endblock graphiql_params %}
29+
```

Resources/views/GraphiQL/index.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
5959
ReactDOM.render(
6060
React.createElement(GraphiQL, {
61+
{% block graphiql_params %}
6162
fetcher: graphQLFetcher
63+
{% endblock graphiql_params %}
6264
}),
6365
document.body
6466
)

0 commit comments

Comments
 (0)