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 :
- Type system
- ✔️ Scalars
- ✔️ Object
- ✔️ Interface
- ✔️ Union
- ✔️ Enum
- ✔️ Input Object
- ✔️ Lists
- ✔️ Non-Null
- Concepts :
- ✔️ Resolver
- ✔️ Query
- ✔️ GlobalId
- ✖️ Type Inheritance
- ✔️ Pagination
- ✔️ Mutation
- ✖️ Promise
- ✔️ Validation
- git
- composer
- PHP 7.1.3 or higher
- PDO-SQLite PHP extension enabled
- a Symfony 4.4 compatible environment
Retrieve repository :
$ git clone [email protected]: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
.
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
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.
This project use Makefile
to simplify application usage.
Take a look, you will find some useful commands.
This application use SQLite. Database is versioned and available in the /var/app.db
file.
Schema is available in the original migration.
If you corrupt data you can drop database and reload fixtures using this command :
$ make install
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