9951 explained code solutions for 126 technologies


php-symfonyHow to use GraphQL with PHP Symfony?


GraphQL can be used with PHP Symfony by installing the webonyx/graphql-php library.

Example code

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;

$queryType = new ObjectType([
    'name' => 'Query',
    'fields' => [
        'hello' => [
            'type' => Type::string(),
            'resolve' => function () {
                return 'Hello world!';
            }
        ]
    ]
]);

Output example

Hello world!

The code above creates a Query object type with a hello field that returns a string Hello world!.

Helpful links

Edit this code on GitHub