Skip to content

Instantly share code, notes, and snippets.

@jmas
Created June 7, 2021 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmas/46133b07d67117bf326682b4e4649ef5 to your computer and use it in GitHub Desktop.
Save jmas/46133b07d67117bf326682b4e4649ef5 to your computer and use it in GitHub Desktop.
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