Skip to content

Instantly share code, notes, and snippets.

@Greenie10
Created September 13, 2019 06:15
Show Gist options
  • Save Greenie10/620e054b12897ca52de6f55240f25790 to your computer and use it in GitHub Desktop.
Save Greenie10/620e054b12897ca52de6f55240f25790 to your computer and use it in GitHub Desktop.
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