Last active
November 26, 2018 08:05
-
-
Save redbluenat/764efd0c995b8b60201bcd27865ec410 to your computer and use it in GitHub Desktop.
This file contains 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 { GraphQLServer } = require('graphql-yoga'); | |
const { Prisma } = require('prisma-binding'); | |
const typeDefs = ` | |
type Query { | |
dogName: String! | |
} | |
`; | |
const resolvers = { | |
Query: { | |
dogName: () => `Tommy the chihuahua`, | |
dogs: (root, args, context, queryInfo) => { | |
return context.db.query.dogs({}, queryInfo); | |
} | |
}, | |
Mutation: { | |
dog: (root, args, context, queryInfo) => { | |
return context.db.mutation.createDog( | |
{ | |
data: { | |
type: args.type, | |
name: args.name | |
} | |
}, | |
queryInfo | |
); | |
} | |
} | |
}; | |
const server = new GraphQLServer({ | |
typeDefs, | |
resolvers, | |
context: req => ({ | |
...req, | |
db: new Prisma({ | |
typeDefs: 'src/generated/prisma.graphql', | |
endpoint: 'YOUR_ENDPOINT_PATH', | |
secret: 'testsecret', | |
debug: true | |
}) | |
}) | |
}); | |
server.start(() => console.log(`Server address: http://localhost:4000`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment