Skip to content

Instantly share code, notes, and snippets.

@guzmonne
Created March 27, 2017 00:59
Show Gist options
  • Save guzmonne/65aaa72983a8f5995ab4255d4068cf26 to your computer and use it in GitHub Desktop.
Save guzmonne/65aaa72983a8f5995ab4255d4068cf26 to your computer and use it in GitHub Desktop.
Habitapp first graphql schema
const {merge, range, uniqueId} = require('lodash')
const {makeExecutableSchema} = require('graphql-tools')
const {
schema: clickSchema,
} = require('./clicks.schema.js')
let clicks = []
const rootSchema = [`
type Query {
# A list of all the clicks stored.
clicks: [Click]
}
type Mutation {
# Add a new click
addClick(message: String): Click
}
schema {
query: Query
mutation: Mutation
}
`]
const rootResolvers = {
Query: {
clicks(){
return clicks
}
},
Mutation: {
addClick(root, {message}){
const click = {
_id: uniqueId('click'),
timestamp: Date.now(),
message,
}
clicks = clicks.concat(click)
return Promise.resolve(click)
}
}
}
const schema = [...rootSchema, ...clickSchema]
const resolvers = merge(rootResolvers)
const executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
})
exports = module.exports = executableSchema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment