Skip to content

Instantly share code, notes, and snippets.

@skynode
Forked from koistya/schema.js
Created June 21, 2017 20:11
Show Gist options
  • Save skynode/3c96ff8b8f1ea7ff7b764470d324baea to your computer and use it in GitHub Desktop.
Save skynode/3c96ff8b8f1ea7ff7b764470d324baea 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