Home

Awesome

GraphQL POC in PHP

License: MIT Build Status Scrutinizer Code Quality Quality Gate Status

This project is a proof of concept to test graphQL usage in PHP.
This work is based mainly on Symfony framework and overblog/GraphQLBundle.

This project implements :

Requirement

Installation

Retrieve repository :

$ git clone git@github.com:Samffy/graphql-poc.git

Go to the project directory :

$ cd graphql-poc

Install and launch project using :

$ make deploy

Go to : http://localhost:8000/graphiql
If you want to request the app using another GraphQL client, the endpoint is : http://localhost:8000/

In dev mode, Symfony profiler is available at /_profiler.

GraphQL

Schema

You can consult the graphQL schema here :
https://github.com/Samffy/graphql-poc/blob/master/config/graphql/schema.graphql

If you update this project, you can dump the new version of the GraphQL schema using this command :

$ bin/console graphql:dump-schema --format=graphql --file=./config/graphql/schema.graphql

Queries

This project use 2 mains types : Person and Vehicle
A person has a Pet and one Vehicle or more.
A Pet can be a Dog, a Cat or a Bear.
A Vehicle can be a Car or a Truck.

Here is an example of a graphQL query :

{
    persons(id: "UGVyc29uOmR1ZmZ5") {
        id
        title
        name
        birth_date
        created_at
        pet {
            ...on Animal {
                id
                name
                breed
            }
        }
        vehicles {
            id
            manufacturer
            model
            ...on Car {
                seats_number
            }
            ...on Truck {
                maximum_load
            }
        }
    }
}

You can find many examples in the functional tests.

Developer tools

This project use Makefile to simplify application usage.
Take a look, you will find some useful commands.

Database

This application use SQLite. Database is versioned and available in the /var/app.db file.
Schema is available in the original migration.

Fixtures

If you corrupt data you can drop database and reload fixtures using this command :

$ make install

Tests

There is some functional tests, read it to see some useful examples.
It basically launch queries and check response.

To launch them use :

$ make integration

:warning: It will truncate database and dump default fixtures.