Created
March 27, 2017 00:59
-
-
Save guzmonne/65aaa72983a8f5995ab4255d4068cf26 to your computer and use it in GitHub Desktop.
Habitapp first graphql schema
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
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