1

I have a Next.js app and using apollo-client for GraphCMS.

Once I have set environment variables for URI and token on ApolloClient object, GraphQL query does not work and return. Actually, I can get data from GraphCMS. The problem is only for mutations.

Here is the .env file:

GRAPHCMS_ENDPOINT=https://api-some-thing.graphcms.com/v2/sd3s
GRAPHCMS_TOKEN=tsd89asd24jnNM

And here is apollo-client.js:

import { ApolloClient, InMemoryCache } from "@apollo/client";

const client = new ApolloClient({
  uri: process.env.GRAPHCMS_ENDPOINT,
  cache: new InMemoryCache(),
  headers: {
    "Authorization": `Bearer ${process.env.GRAPHCMS_TOKEN}`
  }
});

export default client;

If I set URI and token as string I mean not using process.env, everything works fine.

What am I missing?

Mesut
  • 23
  • 1
  • 1
  • 6
  • 1
    If you need the environment variables in the browser you need to prefix them with `NEXT_PUBLIC_`. See [NextJS environment variables aren't working](https://stackoverflow.com/questions/63257107/nextjs-environment-variables-arent-working). – juliomalves Dec 27 '21 at 12:20
  • 1
    Thanks a lot. It is working now. – Mesut Dec 27 '21 at 15:56

0 Answers0