Description
Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here.
Symfony 2 GraphQl Bundle alternatives and similar libraries
Based on the "API" category.
Alternatively, view Symfony 2 GraphQl Bundle alternatives based on common mentions on social networks and blogs.
-
API Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time. -
PHP-CRUD-API
Single file PHP script that adds a REST API to a SQL database -
Firebase Admin SDK for PHP
Unofficial Firebase Admin SDK for PHP -
Restler
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API -
wsdl2phpgenerator
Simple utility and class library for generating php classes from a wsdl file. -
Hateoas
A PHP library to support implementing representations for HATEOAS REST web services. -
OverblogGraphQLBundle
This bundle provides tools to build a complete GraphQL API server in your Symfony App. -
Apigility
An API builder built with Zend Framework 2. -
Pinterest Bot for PHP
This PHP library will help you to work with your Pinterest account without using any API account credentials. -
Symfony DataTables Bundle
DataTables bundle for Symfony -
Symfony GraphQl Bundle
Pure PHP implementation of GraphQL Server – Symfony Bundle -
Slack for PHP
A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax. -
Drest
Quickly and easily expose Doctrine entities as REST resource endpoints with the use of simple configuration with annotations, yaml, json or a PHP array. -
chubbyphp-framework
A minimal, highly performant middleware PSR-15 microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use. -
Behapi
Behat extension for those who want to write acceptances tests for apis -
Bearer PHP Client
Bearer client for the PHP programming language -
phpDoc2pdf
Create PDF formatted documentation for your PHP projects -
yii2-fractal
A set of utils and actions for build API following JSON:Api specification, based on league/fractal -
mite SDK for PHP
Interact with mite from your PHP application. -
Personio SDK for PHP
Interact with Personio from your PHP application. -
laraccess
A Beta/Campaing Manager API built with Laravel -
icanhazstring/expressive-hashids-middleware
PSR-15/PSR-7 compliant middleware using ivanakimov/hashids.php
Managed Cloud Hosting Platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Symfony 2 GraphQl Bundle or a related project?
README
Symfony 2 GraphQl Bundle
Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here.
Installation
1- Require the package via Composer in your composer.json
.
{
"require": {
"suribit/graphql-bundle": "*"
}
}
2- Run Composer to install or update the new requirement.
$ composer install
or
$ composer update
3- Add the service provider to your app/AppKernel.php
file
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Suribit\GraphQLBundle\GraphQLBundle(),
);
// ...
}
// ...
}
4- Create Type src/path your bundle/Types/Country.php
<?php
namespace Lgck\GraphQlBundle\Types;
use GraphQL\Type\Definition\Type as TypeBase;
use Suribit\GraphQLBundle\Support\Type;
class Country extends Type
{
protected $attributes = [
'name' => 'Country',
'description' => 'A Country'
];
public function fields()
{
return [
'id' => [
'type' => TypeBase::nonNull(TypeBase::int()),
'description' => 'The id of the country'
],
'name' => [
'type' => TypeBase::string(),
'description' => 'The name of country'
],
'status' => [
'type' => TypeBase::int(),
'description' => 'The status of country'
]
];
}
}
5- Create Query src/path your bundle/Queries/Country.php
<?php
namespace Lgck\GraphQlBundle\Queries;
use GraphQL\Type\Definition\Type;
use Suribit\GraphQLBundle\Support\Query;
class Country extends Query
{
protected $attributes = [
'name' => 'Country query'
];
public function type()
{
return $this->manager->type('country');
}
public function args()
{
return [
'id' => ['name' => 'id', 'type' => Type::int()],
];
}
public function resolve($root, $args)
{
$em = $this->manager->em; // Doctrine Entity Manager
return [
'id' => `,
'name' => 'Russia',
'status' => 1
];
}
}
6- Create config for graphql schema src/path your bundle/Resources/config/graphql.yml
types:
country: 'Lgck\GraphQlBundle\Types\Country'
schema:
query:
country: 'Lgck\GraphQlBundle\Queries\Country'
mutation: []
7- Edit the file src/path your bundle/Resources/config/services.yml
services:
lgck_graph_ql.mapping.driver.yaml:
public: true
class: Suribit\GraphQLBundle\ConfigDrivers\Yaml\YamlDriver
arguments:
- "%kernel.root_dir%/../src/path your bundle/Resources/config/graphql.yml"
lgck_graph_ql.manager:
class: Suribit\GraphQLBundle\GraphQL
arguments:
- @doctrine.orm.entity_manager
- @lgck_graph_ql.mapping.driver.yaml
8- Create a controller that will be the starting point for processing the request
<?php
// ...
class MainController extends Controller
{
public function queryAction(Request $request)
{
$manager = $this->get('lgck_graph_ql.manager');
$query = $request->request->get('query');
try {
$data = $manager->query($query);
} catch (QueryException $e) {
$response = new JsonResponse($e->getErrors(), 500);
return $response;
}
$response = new JsonResponse($data);
return $response;
}
}
9- Now it is possible to send a data request
query FooBar {
country(id: 1) {
id,
name,
status
}
}
TODO:
- Add the complete documentation
- Add validation