Download the PHP package folklore/graphql without Composer
On this page you can find all versions of the php package folklore/graphql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package graphql
Laravel GraphQL
This package is no longuer maintained. Please use rebing/graphql-laravel or other Laravel GraphQL packages
Use Facebook GraphQL with Laravel 5 or Lumen. It is based on the PHP implementation here. You can find more information about GraphQL in the GraphQL Introduction on the React blog or you can read the GraphQL specifications. This is a work in progress.
This package is compatible with Eloquent model (or any other data source). See the example below.
To use laravel-graphql with Relay, check the feature/relay branch.
Installation
Version 1.0 is released. If you are upgrading from older version, you can check Upgrade to 1.0.
Dependencies:
1- Require the package via Composer in your composer.json
.
2- Run Composer to install or update the new requirement.
or
Laravel >= 5.5.x
1- Publish the configuration file
2- Review the configuration file
Laravel <= 5.4.x
1- Add the service provider to your config/app.php
file
2- Add the facade to your config/app.php
file
3- Publish the configuration file
4- Review the configuration file
Lumen
1- Load the service provider in bootstrap/app.php
2- For using the facade you have to uncomment the line $app->withFacades();
in bootstrap/app.php
After uncommenting this line you have the GraphQL
facade enabled
3- Publish the configuration file
4- Load configuration file in bootstrap/app.php
Important: this command needs to be executed before the registration of the service provider
5- Review the configuration file
Documentation
- Upgrade to 1.0
Usage
- Schemas
- Creating a query
- Creating a mutation
- Adding validation to mutation
Advanced Usage
- Query variables
- Query nested resource
- Enums
- Interfaces
- Custom field
- Eager loading relationships
Schemas
Starting from version 1.0, you can define multiple schemas. Having multiple schemas can be useful if, for example, you want an endpoint that is public and another one that needs authentication.
You can define multiple schemas in the config:
Or you can add schema using the facade:
Afterwards, you can build the schema using the facade:
Or you can request the endpoint for a specific schema
Creating a query
First you need to create a type.
Add the type to the config/graphql.php
configuration file
You could also add the type with the GraphQL
Facade, in a service provider for example.
Then you need to define a query that returns this type (or a list). You can also specify arguments that you can use in the resolve method.
Add the query to the config/graphql.php
configuration file
And that's it. You should be able to query GraphQL with a request to the url /graphql
(or anything you choose in your config). Try a GET request with the following query
input
For example, if you use homestead:
Creating a mutation
A mutation is like any other query, it accepts arguments (which will be used to do the mutation) and return an object of a certain type.
For example a mutation to update the password of a user. First you need to define the Mutation.
As you can see in the resolve
method, you use the arguments to update your model and return it.
You then add the mutation to the config/graphql.php
configuration file
You should then be able to use the following query on your endpoint to do the mutation.
if you use homestead:
Adding validation to mutation
It is possible to add validation rules to mutation. It uses the laravel Validator
to performs validation against the args
.
When creating a mutation, you can add a method to define the validation rules that apply by doing the following:
Alternatively you can define rules with each args
When you execute a mutation, it will returns the validation errors. Since GraphQL specifications define a certain format for errors, the validation errors messages are added to the error object as a extra validation
attribute. To find the validation error, you should check for the error with a message
equals to 'validation'
, then the validation
attribute will contain the normal errors messages returned by the Laravel Validator.
All versions of graphql with dependencies
illuminate/support Version 5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*
webonyx/graphql-php Version ~0.10.2