Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/supliu/laravel-graphql
GraphQL with Laravel Framework
https://github.com/supliu/laravel-graphql
hacktoberfest
Last synced: 26 days ago
JSON representation
GraphQL with Laravel Framework
- Host: GitHub
- URL: https://github.com/supliu/laravel-graphql
- Owner: supliu
- Created: 2019-01-31T23:54:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-06-20T13:03:56.000Z (over 1 year ago)
- Last Synced: 2024-09-28T21:42:48.135Z (about 1 month ago)
- Topics: hacktoberfest
- Language: Blade
- Homepage:
- Size: 355 KB
- Stars: 34
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel GraphQL
[![Latest Stable Version](https://poser.pugx.org/supliu/laravel-graphql/v)](//packagist.org/packages/supliu/laravel-graphql) [![Total Downloads](https://poser.pugx.org/supliu/laravel-graphql/downloads)](//packagist.org/packages/supliu/laravel-graphql) [![Latest Unstable Version](https://poser.pugx.org/supliu/laravel-graphql/v/unstable)](//packagist.org/packages/supliu/laravel-graphql) [![License](https://poser.pugx.org/supliu/laravel-graphql/license)](//packagist.org/packages/phpunit/phpunit)
The objective of this project is to facilitate the integration of the webonyx/graphql-php with the Laravel Framework
## How to install
Use composer to install this package
```ssh
composer require supliu/laravel-graphql
```Execute a publish with artisan command:
```
php artisan vendor:publish --provider="Supliu\LaravelGraphQL\ServiceProvider"
```## How to use
You must create your Query and Mutation classes and register on `config/graphql.php` so that GraphQL can read.
```php
'queries' => [
'detailHero' => \App\GraphQL\Queries\DetailHero::class
],'mutations' => [
'updateHero' => \App\GraphQL\Mutations\UpdateHero::class
]
```### Query
Below is an example of a Query class that returns the data of a Star Wars hero:
```php
Type::nonNull(Type::int())
];
}
/**
* @return Type
*/
protected function typeResult(): Type
{
return new ObjectType([
'name' => 'HeroQueryResult',
'fields' => [
'name' => Type::string()
]
]);
}/**
* @return mixed
*/
protected function resolve($root, $args, $context, $info)
{
return Hero::find($args['id']);
}
}
```### Mutation
Below is an example of a Mutation class that returns if update worked:
```php
'UpdateHeroResult',
'fields' => [
'error' => Type::boolean(),
'message' => Type::string()
]
]);
}/**
* @return array
*/
protected function args(): array
{
return [
'id' => Type::nonNull(Type::int())
'name' => Type::nonNull(Type::string())
];
}/**
* @return mixed
*/
protected function resolve($root, $args, $context, $info)
{
Hero::find($args['id'])->update([
'name' => $args['name']
]);
return [
'error' => false,
'message' => 'Updated!'
];
}
}
```## License
The Laravel GraphQL is open-sourced project licensed under the [MIT license](https://opensource.org/licenses/MIT).