Created
December 20, 2022 15:27
-
-
Save orozcorp/f5760da6794119b3e7832ae62f179810 to your computer and use it in GitHub Desktop.
Apollo Server with micro-cors and apollo-server-micro
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 Cors from "micro-cors"; | |
import ApolloServer from "../../apollo/config/server"; | |
const cors = Cors(); | |
export const config = { | |
api: { | |
bodyParser: false, | |
}, | |
}; | |
const serverStarted = ApolloServer.start(); | |
export default cors(async (req, res) => { | |
if (req.method === "OPTIONS") { | |
res.end(); | |
return false; | |
} | |
await serverStarted; | |
await ApolloServer.createHandler({ | |
path: "/api", | |
})(req, res); | |
}); |
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 } from "apollo-server-micro"; | |
import schema from "./schema"; | |
import resolvers from "./resolvers"; | |
import { context } from "./context"; | |
import { ApolloServerPluginLandingPageDisabled } from "apollo-server-core"; | |
const typeDefs = schema; | |
export default new ApolloServer({ | |
typeDefs, | |
resolvers, | |
context, | |
csrfPrevention: true, | |
cache: "bounded", | |
plugins: [ApolloServerPluginLandingPageDisabled()], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment