Generate schema from the GraphQL endpoint on Next.js with Apollo CLI

Hi everyone,

I'm currently struggling with the apollo-tooling package.

I want to generate a GraphQL schema and a Typescript declaration file with the codegen command but the endpoint gives me a 403 status code.

I guess it is because of the access token, here is my config file :

const token =  "XXXXXXX";

module.exports = {
  client: {
    service: {
      name: "my-website-cms",
      url: `https://my-website.prismic.io/graphql?access_token=${token}`,
    },
  },
};

And here is the command I'm using after installing it on my Next.js project :

apollo service:download graphql-schema.json

The command gives me the following error :

  ✖ Loading Apollo Project
    → Error initializing Apollo GraphQL project "my-website-cms": Error: Error in "Loading schema for my-website-cms": Error: ServerError: Response not successful: Received status code 403

I also tried to pass the token in the header with Bearer and Token, but I have the same result.

I don't understand why the Apollo CLI doesn't work, the Apollo client seems to work fine however.

Thanks in advance,
Valentin

Hello @valentin1, maybe this document will be helpful for you:

You can use the Introspection query to get the schema.

Thank you, the script does work well with the bearer token in the header and generates the schema but still doesn't work when it comes to apollo codegen:generate to get the typescript type definitions.

I'm following this article but the problem really seems to be the token, I always end up with a 403 status code.

Otherwise, I'd love to use the default Prismic Next.js client to query my content but the documentation doesn't show how to generate TS types from it. Any idea ?

One of my colleagues recommends using GraphQL Code Generator instead. He provided this example.

Thank you, it seems to work !