Created
June 7, 2021 05:48
-
-
Save jmas/46133b07d67117bf326682b4e4649ef5 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
import { ApolloServer, gql } from "apollo-server-micro"; | |
import { makeExecutableSchema } from "graphql-tools"; | |
import { User } from "../../utils/db"; | |
const typeDefs = gql` | |
type User { | |
id: ID! | |
name: String! | |
email: String! | |
} | |
type Query { | |
users: [User]! | |
} | |
`; | |
const resolvers = { | |
Query: { | |
users: async (parent, args, context, info) => { | |
const user = await User.findOne({ name: "Alexander" }).exec(); | |
return [user]; | |
}, | |
}, | |
}; | |
const schema = makeExecutableSchema({ | |
typeDefs, | |
resolvers, | |
}); | |
const apolloServer = new ApolloServer({ | |
schema, | |
}); | |
export const config = { | |
api: { | |
bodyParser: false, | |
}, | |
}; | |
export default apolloServer.createHandler({ path: "/api/graphql" }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment