Last active
May 21, 2022 15:06
-
-
Save oxlb/6073dc86460e3570611f3688a25bb2c9 to your computer and use it in GitHub Desktop.
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 { 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