Easy build API using Laravel and GraphQL (Mutation) part 2
Mutation GraphQL

Previous article we learn Building API using Laravel And GraphQL for Product List and User List, if you read previous article , i suggest you read it first. Now we will learn about Mutation and Authentication API with GraphQL
GraphQL is awesome technology for making simple and dynamic API, it is powerful for client app which develop using React Native / ReactJs. there are many library for support GraphQL documented in below
1. Create Mutation Class
Mutation is type for inserting data into a database or altering data already in a database more detail here, in previous article we already have User Model, this sample we will add new user with profile and update user information using mutation query. First we must add new class for new user and update user

in NewUserMutation.php we have args function to declare field input and type input. Type::nonNull mean the field is required, in GraphQL query marked by exclamation (!), after save success we will return data user
UpdateUserMutation.php is example update data user, all action update and insert still using Eloquent and you can using Query builder for complicated query
2. Append Mutation in GraphQL
you can find graphql.php in config folder and append class with namespace in mutation schema

after append mutation class, open http://127.0.0.1:8000/graphql-ui in documentation appears mutation detail
4. Demo

don’t worry about full source code, you can access it below :). The next article we will continue learn GraphQL JWT Authentication
Click ❤ and follow me to get other articles. thanks

related articles

