├── .github
├── ISSUE_TEMPLATE.md
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ └── ci.yml
├── .gitignore
├── .php-cs-fixer.dist.php
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── composer.json
├── docs
├── auth-token.png
├── custom-http-headers.md
├── custom-parameters.md
├── custom-rendering.md
├── graphql-endpoint.md
└── libraries-versions.md
├── phpunit.xml.dist
├── src
├── Config
│ ├── GraphQLEndpoint
│ │ ├── GraphQLEndpointInvalidSchemaException.php
│ │ ├── Helpers
│ │ │ └── OverblogGraphQLBundleEndpointResolver.php
│ │ ├── RootResolver.php
│ │ └── RouteResolver.php
│ ├── GraphiQLControllerEndpoint.php
│ ├── GraphiQLViewConfig.php
│ └── GraphiQLViewJavaScriptLibraries.php
├── Controller
│ └── GraphiQLController.php
├── DependencyInjection
│ ├── Compiler
│ │ └── Endpoints
│ │ │ ├── DefaultEndpointWiringPass.php
│ │ │ └── OverblogGraphQLBundleEndpointWiringPass.php
│ ├── Configuration.php
│ └── OverblogGraphiQLExtension.php
├── OverblogGraphiQLBundle.php
└── Resources
│ ├── config
│ ├── routing.xml
│ ├── schema
│ │ └── overblog_graphiql-0.1.xsd
│ └── services.xml
│ └── views
│ └── GraphiQL
│ ├── auth.html.twig
│ └── index.html.twig
└── tests
├── Config
└── GraphQLEndpoint
│ ├── Helpers
│ └── OverblogGraphQLBundleEndpointResolverTest.php
│ ├── RootResolverTest.php
│ └── RouteResolverTest.php
├── Controller
└── GraphiQLControllerTest.php
├── Fixtures
└── TestKernel.php
├── ForwardCompatTestCaseTrait.php
├── Functional
└── DependencyInjection
│ ├── Fixtures
│ ├── Xml
│ │ ├── TestKernel.php
│ │ └── config.xml
│ └── Yaml
│ │ ├── TestKernel.php
│ │ └── config.yml
│ ├── Xml
│ └── ConfigurationTest.php
│ └── Yaml
│ └── ConfigurationTest.php
├── Integration
└── OverblogGraphQLBundle
│ ├── Controller
│ └── GraphiQLControllerTest.php
│ ├── Fixtures
│ ├── Resources
│ │ └── config
│ │ │ └── routing.xml
│ └── TestKernel.php
│ └── TestCase.php
├── TestCase.php
└── TestKernel.php
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | | Q | A
2 | | ---------------- | -----
3 | | Bug report? | yes/no
4 | | Feature request? | yes/no
5 | | BC Break report? | yes/no
6 | | RFC? | yes/no
7 | | Version/Branch | x.y.z
8 |
9 |
12 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | | Q | A
2 | | ------------- | ---
3 | | Bug fix? | yes/no
4 | | New feature? | yes/no
5 | | BC breaks? | yes/no
6 | | Deprecations? | yes/no
7 | | Tests pass? | yes/no
8 | | Documented? | yes/no
9 | | Fixed tickets | #...
10 | | License | MIT
11 |
12 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | pull_request: null
5 | push:
6 | branches:
7 | - "*.*"
8 | - "master"
9 | schedule:
10 | - cron: "0 4 * * *"
11 |
12 | jobs:
13 | tests:
14 | runs-on: ubuntu-22.04
15 | strategy:
16 | fail-fast: false
17 | matrix:
18 | php-version:
19 | - '8.0'
20 | - '8.1'
21 | - '8.2'
22 | - '8.3'
23 | - '8.4'
24 | symfony-version:
25 | - '5.4.*'
26 | - '6.0.*'
27 | - '6.2.*'
28 | - '6.4.*'
29 | - '7.0.*'
30 | - '7.1.*'
31 | dependencies:
32 | - 'lowest'
33 | - 'highest'
34 | remove-dependencies: [ '' ]
35 | coverage: [ 'none' ]
36 | exclude:
37 | - php-version: '8.0'
38 | symfony-version: '6.2.*'
39 | - php-version: '8.0'
40 | symfony-version: '6.4.*'
41 | - php-version: '8.0'
42 | symfony-version: '7.0.*'
43 | - php-version: '8.0'
44 | symfony-version: '7.1.*'
45 | - php-version: '8.1'
46 | symfony-version: '7.0.*'
47 | - php-version: '8.1'
48 | symfony-version: '7.1.*'
49 | steps:
50 | - name: "Checkout"
51 | uses: "actions/checkout@v2"
52 |
53 | - name: "Install PHP"
54 | uses: "shivammathur/setup-php@v2"
55 | with:
56 | tools: flex
57 | php-version: "${{ matrix.php-version }}"
58 | coverage: "none"
59 |
60 | - name: "Change stability"
61 | if: "matrix.stability != ''"
62 | run: perl -pi -e 's/^}$/,"minimum-stability":"'"${{ matrix.minimum-stability }}"'"}/' composer.json && cat composer.json
63 |
64 | - name: "Webonyx GraphQL version"
65 | if: "matrix.graphql-version != ''"
66 | run: composer require "webonyx/graphql-php:${{ matrix.graphql-version }}" --dev --no-update
67 |
68 | - name: Remove dependencies
69 | if: "matrix.remove-dependencies != ''"
70 | run: composer remove --no-update ${{ matrix.remove-dependencies }}
71 |
72 | - name: "Install dependencies"
73 | uses: ramsey/composer-install@1.3.0
74 | with:
75 | dependency-versions: ${{ matrix.dependencies }}
76 | env:
77 | SYMFONY_REQUIRE: "${{ matrix.symfony-version }}"
78 |
79 | - name: "Run tests"
80 | run: composer test
81 |
82 | coding-standard:
83 | runs-on: ubuntu-22.04
84 | name: Coding Standard
85 | steps:
86 | - name: "Checkout"
87 | uses: "actions/checkout@v4"
88 |
89 | - name: "Install PHP"
90 | uses: "shivammathur/setup-php@v2"
91 | with:
92 | tools: flex
93 | php-version: "8.2"
94 | coverage: "none"
95 |
96 | - name: "Install dependencies"
97 | uses: "ramsey/composer-install@v2"
98 |
99 | - name: "Check coding standard"
100 | run: composer run check-cs
101 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | phpunit.xml
2 | /build
3 | /vendor
4 | /bin
5 | composer.lock
6 | composer.phar
7 | /.php-cs-fixer.php
8 | /*.cache
9 |
10 | phpbench.phar
11 | phpbench.phar.*
12 | /.phpbench_storage
13 | php-cs-fixer.phar
14 |
--------------------------------------------------------------------------------
/.php-cs-fixer.dist.php:
--------------------------------------------------------------------------------
1 | exclude('Annotation')
5 | ->name('*.php')
6 | ->in([__DIR__.'/src', __DIR__.'/tests'])
7 | ;
8 |
9 | return (new PhpCsFixer\Config())
10 | ->setRules(
11 | [
12 | '@Symfony' => true,
13 | '@PHP80Migration' => true,
14 | '@PHP80Migration:risky' => true,
15 | 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']],
16 | 'general_phpdoc_annotation_remove' => [
17 | 'annotations' => [
18 | 'author',
19 | 'category',
20 | 'copyright',
21 | 'created',
22 | 'license',
23 | 'package',
24 | 'since',
25 | 'subpackage',
26 | 'version',
27 | ],
28 | ],
29 | 'fully_qualified_strict_types' => true,
30 | 'single_line_throw' => false,
31 | 'phpdoc_to_comment' => false,
32 | 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
33 | 'global_namespace_import' => ['import_functions' => true, 'import_classes' => true, 'import_constants' => true],
34 | 'phpdoc_summary' => false,
35 | 'single_line_comment_style' => false,
36 | 'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var']],
37 | 'no_mixed_echo_print' => ['use' => 'echo'],
38 | ]
39 | )
40 | ->setFinder($finder)
41 | ->setUsingCache(true)
42 | ;
43 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ============
3 |
4 | Running tests
5 | --------------
6 |
7 | In the bundle directory:
8 |
9 | ```bash
10 | ./vendor/bin/phpunit
11 | ```
12 |
13 | Giving some love to PHP CS
14 | ---------------------------
15 |
16 | ```bash
17 | composer require --dev 'friendsofphp/php-cs-fixer:^2.0'
18 | bin/php-cs-fixer fix
19 | ```
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Overblog
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | OverblogGraphiQLBundle
2 | ======================
3 |
4 | This Symfony bundle provides integration of [GraphiQL](https://github.com/graphql/graphiql) interface to your Symfony application
5 |
6 | [](https://travis-ci.org/overblog/GraphiQLBundle)
7 | [](https://coveralls.io/github/overblog/GraphiQLBundle?branch=master)
8 | [](https://packagist.org/packages/overblog/graphiql-bundle)
9 | [](https://packagist.org/packages/overblog/graphiql-bundle)
10 | [](https://packagist.org/packages/overblog/graphiql-bundle)
11 |
12 | Installation
13 | ------------
14 |
15 | **a)** Download the bundle
16 |
17 | In the project directory:
18 |
19 | ```bash
20 | composer require --dev overblog/graphiql-bundle
21 | ```
22 |
23 | Symfony Flex installation
24 | ------------
25 |
26 | **Note** If you are using Symfony Standard go to the next section
27 |
28 | **a)** Accept the contrib recipes installation from Symfony Flex
29 |
30 | ```
31 | - WARNING overblog/graphiql-bundle (0.1): From github.com/symfony/recipes-contrib
32 | The recipe for this package comes from the "contrib" repository, which is open to community contributions.
33 | Do you want to execute this recipe?
34 | [y] Yes
35 | [n] No
36 | [a] Yes for all packages, only for the current installation session
37 | [p] Yes permanently, never ask again for this project
38 | (defaults to n):
39 | ```
40 |
41 | **b)** In case you don't have twig
42 |
43 | In the project directory:
44 |
45 | ```bash
46 | composer require twig
47 | ```
48 |
49 | If you are using twig ONLY for graphiql you might want to use `--dev` during composer require
50 |
51 | Symfony Standard installation
52 | ------------
53 |
54 | **a)** Enable the bundle in the 'dev' section
55 |
56 | ```php
57 | // in app/AppKernel.php
58 | class AppKernel extends Kernel
59 | {
60 | // ...
61 |
62 | public function registerBundles()
63 | {
64 | if (in_array($this->getEnvironment(), array('dev', 'test'))) {
65 | // ...
66 | $bundles[] = new Overblog\GraphiQLBundle\OverblogGraphiQLBundle();
67 | }
68 | }
69 | }
70 | ```
71 |
72 | **b)** Enable GraphiQL endpoint
73 |
74 | ```yaml
75 | # in app/config/routing_dev.yml
76 | overblog_graphiql_endpoint:
77 | resource: "@OverblogGraphiQLBundle/Resources/config/routing.xml"
78 | ```
79 |
80 | Done
81 | ------------
82 |
83 | It's done now, navigate to `/graphiql` in your project url
84 |
85 | More
86 | ------------
87 |
88 | * [Custom HTTP headers](docs/custom-http-headers.md)
89 | * [Custom page rendering](docs/custom-rendering.md)
90 | * [Custom GraphiQL parameters](docs/custom-parameters.md)
91 | * [Define JavaScript libraries' versions](docs/libraries-versions.md)
92 | * [Define a custom GraphQL endpoint](docs/graphql-endpoint.md)
93 |
94 | Community
95 | ---------
96 |
97 | * Get some support on [Symfony devs Slack](https://symfony.com/slack-invite)
98 | on the dedicated channel **overblog-graphql**.
99 | * Follow us on [GitHub](https://github.com/overblog)
100 |
101 | Contributing
102 | ------------
103 |
104 | * [See contributing documentation](CONTRIBUTING.md)
105 | * [Thanks to all contributors](https://github.com/overblog/GraphiQLBundle/graphs/contributors)
106 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "overblog/graphiql-bundle",
3 | "type": "symfony-bundle",
4 | "description": "Symfony GraphiQLBundle makes possible to render the UI into your symfony project",
5 | "keywords": [
6 | "GraphQL", "GraphiQL"
7 | ],
8 | "license": "MIT",
9 | "authors": [
10 | {
11 | "name": "Renato Mefi",
12 | "email": "renato@mefi.in"
13 | },
14 | {
15 | "name": "Overblog",
16 | "homepage": "http://www.over-blog.com"
17 | }
18 | ],
19 | "config" : {
20 | "bin-dir": "bin",
21 | "sort-packages": true
22 | },
23 | "require": {
24 | "php": "^8.0",
25 | "symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
26 | "symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
27 | "symfony/routing": "^5.4 || ^6.0 || ^7.00"
28 | },
29 | "require-dev": {
30 | "overblog/graphql-bundle": "dev-master",
31 | "webonyx/graphql-php": "^15.4",
32 | "phpunit/phpunit": "^9.5.10",
33 | "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
34 | "symfony/config": "^5.4 || ^6.0 || ^7.0",
35 | "symfony/console": "^5.4 || ^6.0 || ^7.0",
36 | "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
37 | "symfony/dom-crawler": "^5.4 || ^6.0 || ^7.0",
38 | "symfony/expression-language": "^5.4 || ^6.0 || ^7.0",
39 | "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
40 | "symfony/finder": "^5.4 || ^6.0 || ^7.0",
41 | "symfony/templating": "^5.4 || ^6.0 || ^7.0",
42 | "symfony/yaml": "^5.4 || ^6.0 || ^7.0",
43 | "twig/twig": "^3.3.3"
44 | },
45 | "autoload": {
46 | "psr-4": { "Overblog\\GraphiQLBundle\\": "src/" }
47 | },
48 | "autoload-dev": {
49 | "psr-4": { "Overblog\\GraphiQLBundle\\Tests\\": "tests/" }
50 | },
51 | "scripts": {
52 | "test": "bin/phpunit --color=always",
53 | "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v3.48.0/php-cs-fixer.phar -O php-cs-fixer.phar",
54 | "fix-cs": [
55 | "@install-cs",
56 | "@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"
57 | ],
58 | "check-cs": [
59 | "@install-cs",
60 | "@php php-cs-fixer.phar fix --dry-run --diff -v --allow-risky=yes --ansi"
61 | ],
62 | "code-quality": [
63 | "rm composer.lock",
64 | "@composer install --ansi",
65 | "@check-cs"
66 | ]
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/docs/auth-token.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/overblog/GraphiQLBundle/68520e0732380d9acd03977e049d9490ee78a6a3/docs/auth-token.png
--------------------------------------------------------------------------------
/docs/custom-http-headers.md:
--------------------------------------------------------------------------------
1 | Custom HTTP headers
2 | ==============
3 |
4 | GraphiQL, provided by this bundle, sends the following default headers on each request:
5 |
6 | ```js
7 | headers = {
8 | "Accept": "application/json",
9 | "Content-Type": "application/json"
10 | };
11 | ```
12 |
13 | Headers sent by GraphiQL can be modified.
14 | For example, let's assume an `access-token` header is required in development.
15 | The header can be added the following way:
16 |
17 | 1. Override the default GraphiQL template:
18 |
19 | ```yaml
20 | # config/packages/graphiql.yaml or app/config/config.yml for Symfony without Flex
21 | overblog_graphiql:
22 | template: "GraphiQL/index.html.twig"
23 | ```
24 | 2. Create a new template:
25 |
26 | ```twig
27 | {# templates/GraphiQL/index.html.twig #}
28 | {% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
29 |
30 | {% block graphql_fetcher_headers %}
31 | headers = {
32 | "Accept": "application/json",
33 | "Content-Type": "application/json",
34 | "access-token": "sometoken"
35 | };
36 | {% endblock graphql_fetcher_headers %}
37 | ```
38 |
39 | Or append headers instead of replacing the default one:
40 |
41 | ```twig
42 | {# templates/GraphiQL/index.html.twig #}
43 | {% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
44 |
45 | {% block graphql_fetcher_headers %}
46 | {{ parent() }}
47 | headers["access-token"] = "sometoken";
48 | {% endblock graphql_fetcher_headers %}
49 | ```
50 |
--------------------------------------------------------------------------------
/docs/custom-parameters.md:
--------------------------------------------------------------------------------
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 | ```
30 |
--------------------------------------------------------------------------------
/docs/custom-rendering.md:
--------------------------------------------------------------------------------
1 | Custom rendering
2 | ===============
3 |
4 | It may be useful to change template to provide additional fields for more comfortable providing of [custom headers](custom-http-headers.md).
5 |
6 | It can be done the following way:
7 |
8 | 1. Override the default GraphiQL template:
9 |
10 | ```yaml
11 | # config/packages/graphiql.yaml or app/config/config.yml for Symfony without Flex
12 | overblog_graphiql:
13 | template: "GraphiQL/index.html.twig"
14 | ```
15 | 2. Create a new template:
16 |
17 | You have to override block `graphiql_render` and soon of all you have to override block `graphql_fetcher_headers`.
18 |
19 | ```twig
20 | {# templates/GraphiQL/index.html.twig #}
21 | {% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
22 |
23 | {% block graphiql_render %}
24 | ReactDOM.render(
25 | {# add your custom implementation here #}
26 | ,
27 | document.body
28 | )
29 | {% endblock graphiql_render %}
30 | ```
31 |
32 | ### Example
33 |
34 | See template [@OverblogGraphiQL/GraphiQL/auth.html.twig](../src/Resources/views/GraphiQL/auth.html.twig). How it looks like:
35 |
36 | 
37 |
38 | There is:
39 |
40 | 1. Header used for the authorization.
41 | 2. Header value (token) for the authorization.
42 | 3. Button to load schema when the header value (token) typed.
43 |
44 | So, you can extend base template [@OverblogGraphiQL/GraphiQL/index.html.twig](../src/Resources/views/GraphiQL/index.html.twig) or use that.
--------------------------------------------------------------------------------
/docs/graphql-endpoint.md:
--------------------------------------------------------------------------------
1 | Custom GraphQL endpoint
2 | =======
3 |
4 | If your graphql endpoint is not the default one coming with the
5 | [overblog/graphql-bundle](https://github.com/overblog/GraphQLBundle), then you might want to tell graphiql how to
6 | resolve the route depending on a schema name.
7 |
8 | By default it uses `Overblog\GraphiQLBundle\Config\GraphQLEndpoint\Helpers\OverblogGraphQLBundleEndpointResolver`.
9 |
10 | ### Configuration
11 |
12 | Just set the `overblog_graphiql.endpoint_resolver` parameter like this:
13 |
14 | ```yaml
15 | # in app/config/config.yml
16 | overblog_graphiql:
17 | # ...
18 | endpoint_resolver: \App\GraphiQL\EndpointResolver
19 | ```
20 |
21 | ### The Resolver
22 |
23 | The resolver must be something like this:
24 |
25 | ```php
26 | $name],
43 | ];
44 | }
45 | }
46 | ```
47 |
48 | It must return an array of packed params which will be passed to `RouterInterface::generate` like this
49 | `$router->generate(...$returnedValueOfTheGetByNameMethod)`.
50 |
--------------------------------------------------------------------------------
/docs/libraries-versions.md:
--------------------------------------------------------------------------------
1 | JavaScript libraries' versions
2 | ==============
3 |
4 | You might want to use custom versions of the libraries included by GraphiQL.
5 | This can be achieved in the bundle configuration, example:
6 |
7 | ```yaml
8 | overblog_graphiql:
9 | javascript_libraries:
10 | graphiql: "0.11"
11 | react: "15.6"
12 | fetch: "2.0"
13 | ```
14 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |