This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deleteUser(parent,args,ctx,info){ | |
const isUserExists = users.findIndex((user)=> user.id === args.author) | |
if(!isUserExists){ | |
throw new Error('User does not exist!') | |
} | |
//splice will return the removed items from the array object | |
const userdeleted = users.splice(isUserExists, 1) | |
return userdeleted[0] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Mutation{ | |
createNewUser(name: String!, email: String!, age: Int): User! | |
createPost(title: String!, body: String!, published: Boolean!, author: ID!): Post! | |
deleteUser(id: ID!): User! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolvers = { | |
Mutation:{ | |
createPost(parent,args,ctx,info){ | |
const userExists = users.some((user)=> user.id === args.author) | |
if(!userExists){ | |
throw new Error('User does not exist!') | |
} | |
//use this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Mutation{ | |
createNewUser(name: String!, email: String!, age: Int): User! | |
createPost(title: String!, body: String!, published: Boolean!, author: ID!): Post! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Mutation{ | |
createNewUser(name: String!, email: String!, age: Int): User! | |
deleteUser(id: ID!): User! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolvers = { | |
Mutation:{ | |
createNewUser(parent,args,ctx,info){ | |
const isEmailExists = users.some((user) => user.email === args.email) | |
if(isEmailExists){ | |
throw new Error('Email already Taken') | |
} | |
const user = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLServer } from 'graphql-yoga'; | |
import uuidv4 from 'uuid/v4'; | |
//array of users | |
const users = [{ | |
id:"1234", | |
name:"jay desai", | |
email: "[email protected]", | |
age:27 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Post:{ | |
author(parent,args,ctx,info){ | |
return users.find((user) =>{ | |
return user.id === parent.author | |
}) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User:{ | |
posts(parent,args,ctx,info){ | |
return posts.filter((post) =>{ | |
return post.author === parent.id | |
}) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLServer } from 'graphql-yoga'; | |
//user array | |
const users = [{ | |
id:"1234", | |
name:"jaydesai", | |
email: "[email protected]", | |
age:27 | |
},{ | |
id:"5678", |