This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports batching using libs like ReactRelayNetworkLayer or Apollo GraphQL.
Version | PHP | Symfony | Support |
---|---|---|---|
1.0 |
>= 8.0 |
>= 5.3.7 |
DEV |
0.14 |
>= 7.4 |
>= 4.4.30 |
Active support |
0.13 |
>= 7.2 |
>= 4.3 |
Active support |
0.12 |
>= 7.1 |
>= 3.4, <4.4 |
Security |
0.11 |
>= 5.6 |
>= 3.1, <=4.3 |
End of life |
0.10 |
>= 5.5.9 |
>= 2.8, <= 3.1 |
End of life |
0.9 |
>= 5.5.9 |
>= 2.8, <= 3.1 |
End of life |
0.8 |
>= 5.4 |
>= 2.7, <= 3.1 |
End of life |
Define your GraphQL schema.
Note: OverblogGraphQLBundle only supports Symfony Flex from version 0.9.0 onwards
a) Download the bundle
In the project directory:
composer require overblog/graphql-bundle
b) Accept the contrib recipes installation from Symfony Flex
- WARNING overblog/graphql-bundle (0.9): From github.com/symfony/recipes-contrib
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Do you want to execute this recipe?
[y] Yes
[n] No
[a] Yes for all packages, only for the current installation session
[p] Yes permanently, never ask again for this project
(defaults to n):
c) If you want to run GraphiQL interface we have a bundle:
composer require --dev overblog/graphiql-bundle
a) Download the bundle
In the project directory:
composer require overblog/graphql-bundle
b) Enable the bundle
// in app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Overblog\GraphQLBundle\OverblogGraphQLBundle(),
];
// ...
}
}
c) Enable GraphQL endpoint
# in app/config/routing.yml
overblog_graphql_single_endpoint:
resource: "@OverblogGraphQLBundle/Resources/config/routing/single.yaml"
prefix: /
To use multiple schemas:
# in app/config/routing.yml
overblog_graphql_multiple_endpoint:
resource: "@OverblogGraphQLBundle/Resources/config/routing/multiple.yaml"
prefix: /graphql
- To use the Validator features, you must also install
symfony/validator
anddoctrine/annotations
- To use the annotations, you must also install
doctrine/annotations
- To use the annotations doctrine type guesser, you must also install
doctrine/orm
Use composer ClassLoader
to load generated class (optional but recommended)
Using composer ClassLoader will help keeping hand on loader optimization in production environment...
First start by some configuration:
overblog_graphql:
definitions:
# disable listener the bundle out of box classLoader
use_classloader_listener: false
# change to "false" to disable auto compilation.
# To generate types manually, see "graphql:compile" command.
auto_compile: true
# change classes cache dir (recommends using a directory that will be committed)
cache_dir: "/my/path/to/my/generated/classes"
# Can also change the namespace
#class_namespace: "Overblog\\GraphQLBundle\\__DEFINITIONS__"
then enable composer autoloader in project composer.json
:
{
"autoload": {
"psr-4": {
"Overblog\\GraphQLBundle\\__DEFINITIONS__\\": "my/path/to/my/generated/classes/"
}
}
}
Finish by dumping the new autoloader.
composer dump-autoload