Skip to content

Upgrading Next.js example to apollo-server v3 #5503

Answered by m-abdelwahab
m-abdelwahab asked this question in Q&A
Discussion options

You must be logged in to vote

Update:

This solution worked:

import { PageConfig } from "next";
import Cors from "micro-cors";
import { ApolloServer, gql } from "apollo-server-micro";

const typeDefs = gql`
  type Query {
    users: [User!]!
  }
  type User {
    name: String
  }
`;

const resolvers = {
  Query: {
    users(parent, args, context) {
      return [{ name: "Nextjs" }];
    },
  },
};

const cors = Cors({
  origin: "https://studio.apollographql.com",
  allowCredentials: true,
});

const apolloServer = new ApolloServer({ typeDefs, resolvers });

const startServer = apolloServer.start();

export default cors(async (req, res) => {
  if (req.method === "OPTIONS") {
    res.end();
    return false;
  }
  await s…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@LexSwed
Comment options

Comment options

You must be logged in to vote
3 replies
@m-abdelwahab
Comment options

@joeynimu
Comment options

@LexSwed
Comment options

Answer selected by m-abdelwahab
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants