1. Go to this page and download the library: Download bonfirecc/laravel-graphql library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\GraphQL\Type;
use GraphQL\Type\Definition\Type;
use BonfireCC\GraphQL\Support\Type as GraphQLType;
class UserType extends GraphQLType {
protected $attributes = [
'name' => 'User',
'description' => 'A user',
'model' => UserModel::class,
];
public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::string()),
'description' => 'The id of the user',
'alias' => 'user_id', // Use 'alias', if the database column is different from the type name
],
'email' => [
'type' => Type::string(),
'description' => 'The email of user',
],
// Uses the 'getIsMeAttribute' function on our custom User model
'isMe' => [
'type' => Type::boolean(),
'description' => 'True, if the queried user is the current user',
'selectable' => false, // Does not try to query this from the database
]
];
}
// If you want to resolve the field yourself, you can declare a method
// with the following format resolve[FIELD_NAME]Field()
protected function resolveEmailField($root, $args)
{
return strtolower($root->email);
}
}
namespace App\GraphQL\Mutation;
use GraphQL;
use GraphQL\Type\Definition\Type;
use BonfireCC\GraphQL\Support\Mutation;
use App\User;
class UpdateUserEmailMutation extends Mutation {
protected $attributes = [
'name' => 'UpdateUserEmail'
];
public function type()
{
return GraphQL::type('user');
}
public function args()
{
return [
'id' => ['name' => 'id', 'type' => Type::string()],
'email' => ['name' => 'password', 'type' => Type::string()]
];
}
public function rules(array $args = [])
{
return [
'id' => ['
class UpdateUserEmailMutation extends Mutation {
//...
public function args()
{
return [
'id' => [
'name' => 'id',
'type' => Type::string(),
'rules' => ['
public function validationErrorMessages ($args = [])
{
return [
'name.se enter your email address',
'email.email' => 'Please enter a valid email address',
'email.exists' => 'Sorry, this email address is already in use',
];
}
use GraphQL;
use GraphQL\Type\Definition\Type;
use BonfireCC\GraphQL\Support\UploadType;
use BonfireCC\GraphQL\Support\Mutation;
class UserProfilePhotoMutation extends Mutation
{
protected $attributes = [
'name' => 'UpdateUserProfilePhoto'
];
public function type()
{
return GraphQL::type('user');
}
public function args()
{
return [
'profilePicture' => [
'name' => 'profilePicture',
'type' => new UploadType($this->attributes['name']),
'rules' => ['