Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Created June 5, 2019 08:21
Show Gist options
  • Save desaijay315/a85733dc1d46dd51543b9c4bd5955d8e to your computer and use it in GitHub Desktop.
Save desaijay315/a85733dc1d46dd51543b9c4bd5955d8e to your computer and use it in GitHub Desktop.
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
},{
id:"5678",
name:"jhon",
email: "[email protected]",
age:27
},
{
id:"8910",
name:"ram",
email: "[email protected]",
age:27
}];
//array of posts
const posts = [{
id:'123',
title:'my new blog',
body:'new blog body',
published:true,
author: '8910',
commentId: '123'
},{
id:'456',
title:'blog 2',
body:'blog body 2',
published:false,
author: '1234',
commentId: '456'
},{
id:'789',
title:'blog 3',
body:'blog body 3',
published:true,
author: '5678',
commentId: '789'
}];
// type definitions , create mutation object - createNewUser
const typeDefs = `
type Query {
users(query: String):[User!]!
post(query: String):[Post!]!
}
type Mutation{
createNewUser(name: String!, email: String!, age: Int): User!
}
type User{
id: ID!
name: String!
email: String!
age: Int
posts:[Post!]!
}
type Post{
id:ID!
title:String!
body:String!
published:Boolean!
author: User!
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment