Created
September 13, 2019 06:15
-
-
Save Greenie10/620e054b12897ca52de6f55240f25790 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 { ApolloServer, gql } = require("apollo-server"); | |
require("./config"); | |
const { Question } = require("./models"); | |
const typeDefs = gql` | |
type Question { | |
id: ID! | |
Question: String | |
Location: String | |
} | |
type Query { | |
getQuestions: [Question] | |
} | |
type Mutation { | |
addQuestion(Question: String!, Location: String!): Question | |
} | |
`; | |
const resolvers = { | |
Query: { | |
getQuestions: async () => await Question.find({}).exec() | |
}, | |
Mutation: { | |
addQuestion: async (_, args) => { | |
try { | |
let response = await Question.create(args); | |
return response; | |
} catch (e) { | |
return e.message; | |
} | |
} | |
} | |
}; | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
introspection: true, | |
playground: true | |
}); | |
server.listen().then(({ url }) => { | |
console.log(`🚀 Server ready at ${url}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment