Laravel provides a clean interface for building https://www.iankumu.com/blog/laravel-rest-api/. Rest APIs have been the defacto way of building flexible and scalable APIs.

Whether you’re a beginner or an experienced Laravel developer, this tutorial will provide you with the knowledge you need to get started with Laravel Graphql.

//App/GraphQL/Queries/Articles/ArticlesQuery 'articles', 'description' => 'A query to fetch all articles' ]; public function type(): Type { // return Type::listOf(GraphQL::type('Articles')); //return all results return GraphQL::paginate('Articles'); //return paginated results } public function args(): array { return [ 'limit' => [ 'type' => Type::int()], 'page' => [ 'type' => Type::int()] ]; } public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields) { /** @var SelectFields $fields */ $fields = $getSelectFields(); $select = $fields->getSelect(); $with = $fields->getRelations(); if (!array_key_exists('limit', $args) || !array_key_exists('page', $args)) { $articles = Articles::with($with)->select($select) ->paginate(5, ['*'], 'page', 1); } else { $articles = Articles::with($with)->select($select) ->paginate($args['limit'], ['*'], 'page', $args['page']); } return $articles; // return Articles::select($select)->with($with)->get(); This returns all records without pagination }}

'UpdateArticle', 'description' => 'A mutation for Updating an Article' ]; public function type(): Type { return GraphQL::type('Articles'); } public function args(): array { return [ 'id' => [ 'type' => Type::nonNull(Type::id()), 'description' => 'The auto incremented Article ID' ], 'title' => [ 'type' => Type::nonNull(Type::string()), 'description' => 'A title of the Article' ], 'content' => [ 'type' => Type::nonNull(Type::string()), 'description' => 'The Body of the Article' ], 'author_id' => [ 'type' => Type::nonNull(Type::id()), 'description' => 'The Author of the Article' ]]; } public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields) { $article = Articles::findOrFail($args['id']); $article->update($args); return $article; }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners