Search code examples
javascriptreactjsnext.jsgoogle-chrome-devtoolsreact-apollo

Failed to fetch


I’m trying to build app with next.js ,apollo client at frontend and graphql-yoga and prisma at backend and i have problem with apollo client extension to chrome it cant fetch my date . That’s how it looks. Failed to fetch error picture. And ther is code :

import withApollo from "next-with-apollo";
import ApolloClient from "apollo-boost";
import { endpoint } from "../config";

function createClient({ headers }) {
  return new ApolloClient({
    uri: process.env.NODE_ENV === "development" ? endpoint : endpoint,
    request: operation => {
      operation.setContext({
        fetchOptions: {
          credentials: "include",
          connectToDevTools: true
        },
        headers
      });
    }
  });
}

export default withApollo(createClient);

I know it must be my stupid gaffe ,but i can’t find it. For everybody who trying help me thanks.


Solution

  • Did you try enabling cors on the server?

    import cors from 'cors'
    const app = express();
    app.use(cors('*'))
    

    https://www.prisma.io/blog/enabling-cors-for-express-graphql-apollo-server-1ef999bfb38d