Skip to content

Instantly share code, notes, and snippets.

@frikille
Last active August 29, 2015 14:25
Show Gist options
  • Save frikille/e17f45c2f3c63220a4c8 to your computer and use it in GitHub Desktop.
Save frikille/e17f45c2f3c63220a4c8 to your computer and use it in GitHub Desktop.
let PostMutationType = new GraphQLObjectType({
name: 'PostType',
fields: () => ({
like: {
type: PostLikeType,
args: {
postId: {
name: 'postId',
type: GraphQLInt
}
},
resolve: (user, {postId}) => {
return PostService.likePost({
userId: user.id,
postId
});
}
},
unlike: {
type: GraphQLInt,
args: {
postId: {
name: 'postId',
type: GraphQLInt
}
},
resolve: (user, {postId}) => {
return PostService.unlikePost({
userId: user.id,
postId
});
}
}
})
});
let MutationQueryType = new GraphQLObjectType({
name: 'MutationQueries',
fields: () => ({
post: {
type: PostMutationType,
resolve: (user) => user
}
})
});
let SessionQuery = new GraphQLObjectType({
name: 'MutationQuery',
fields: () => ({
data: {
type: MutationQueryType,
args: {
id: {
name: 'id',
type: GraphQLInt
}
},
resolve: (root, {id}) => {
return new User({id})
.fetch()
.then(user => {
if (user) {
return user.toJSON();
} else {
return {};
}
});
}
}
})
});
let schema = new GraphQLSchema({
mutation: SessionQuery
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment