Last active
August 29, 2015 14:25
-
-
Save frikille/e17f45c2f3c63220a4c8 to your computer and use it in GitHub Desktop.
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
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