Skip to content

Instantly share code, notes, and snippets.

@oxlb
Last active May 21, 2022 15:06
Show Gist options
  • Save oxlb/6073dc86460e3570611f3688a25bb2c9 to your computer and use it in GitHub Desktop.
Save oxlb/6073dc86460e3570611f3688a25bb2c9 to your computer and use it in GitHub Desktop.
const { knex } = require('./connection');
const { ApolloServer, gql } = require('apollo-server');
const typeDefs = gql`
type Student {
id: ID!
name: String!
}
type Query {
students: [Student]
}
`;
const resolvers = {
Query: {
students: async() => await getStudents(),
}
};
async function getStudents() {
const result = await knex.select().from('student');
return result;
}
const server = new ApolloServer({
typeDefs,
resolvers,
csrfPrevention: true,
});
// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
/*(async() => {
const students = await getStudents();
console.log(students);
})();*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment