Skip to content

Instantly share code, notes, and snippets.

@koistya
Created June 15, 2017 17:40
Show Gist options
  • Save koistya/ff036c3378eb631f25cd0520df0e4ed5 to your computer and use it in GitHub Desktop.
Save koistya/ff036c3378eb631f25cd0520df0e4ed5 to your computer and use it in GitHub Desktop.
How to create a Hacker News API with Node.js and GraphQL https://medium.com/p/3b13ef04ec0f
import { GraphQLSchema, GraphQLObjectType } from 'graphql';
import { nodeField, nodesField } from './types/Node';
import StoryType from './types/StoryType';
import UserType from './types/UserType';
import StoryMutations from './mutations/StoryMutations';
import CommentMutations from './mutations/CommentMutations';
export default new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
node: nodeField,
nodes: nodesField,
me: {
type: UserType,
async resolve() {
// TODO: Resolve the currently logged in user
},
},
stories: {
type: StoryType /* TODO: Replace with StoryConnection type */,
args: {} /* TODO: StoryConnection args */,
async resolve() {
// TODO: Resolve the list of stories from a database
},
},
},
}),
mutation: new GraphQLObjectType({
name: 'Mutation',
fields: {
...StoryMutations,
...CommentMutations,
},
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment