GraphQL API introspecton/codegen

I wanted to hook up codegen for my Prismic repository types in a NextJS app, but introspection might not be supported? Is this feature planned?

1 Like

Got the same question. Have you figured it out?

Not yet. A wild (or not so wild) idea would be to spin up your own graphql server and use schema stitching. Don’t know if that’ll work for sure though.

Quite wild indeed. I came up with another wild quick solution. I used Altair GraphQL Client to manually download the schema and then add it to my project. Then I can generate typing with apollo-codegen. It’s ugly but it works fine if you don’t change schema too often. But, tbh, introspection should be supported by Prismic. It’s an essential feature.

Hey guys,
The introspection query is there and is used for the graphiQL interface when you hit /graphql in your browser.
But for now it’s not conventional since Prismic relies on GET request but also requires to specify the ref with the header Prismic-Ref.
That’s why this kind of tool doesn’t work out of the box but if you can configure it with GET and the ref in the headers that should work.
We plan to improve this part and make it compatible with this kind of codeGen/Types plugins.
Hope it helps :wink:

1 Like

Hey Arnaud! Thanks for the reply.
Could you be more specific? How do I configure it to be a GET? Right now I got this:

"download-schema": "apollo client:download-schema schema.graphql --endpoint --header 'Prismic-Ref: REF'"

I don’t know about your plugin specifically the config that you need to make but I wanted to give you the general spec to follow if you want to achieve it.
Some plugin don’t even let you use GET over POST.

1 Like

@alws for what it’s worth, the Apollo toolset is a fairly common mechanism for interacting with GraphQL services. It’s a great sign that Prismic has an Apollo Link, but I think to fully benefit from the Apollo tools — even with the Apollo Link — we need to be able to interact with the Prismic API using the Apollo CLI tools.

Any chance one of you could take a quick look into this to see what modifications would be needed to get this working? We would all really appreciate it, and deep integration with Apollo could be a huge differentiator for Prismic.


1 Like

Hello @adam,

We plan to make some improvement on the GraphQL API and a better support for this kind of tool will be part of it.
If you need an idea on when we plan to release this, maybe @renaud can already give you some more info :wink:

You can easily generate schema using CLI
with the following config:

I wish this would be documented in the guide, it took me half a day to figure that out, and I was very close to giving up on prismic and switching to GraphCMS

Expanding on what timur said, using @graphql-codegen/cli

Create a codegen.yml file with this content:

  - "https://{{repo-name}}":
      method: GET
        "Prismic-Ref": "{{key}}"
    - ./plugin.js

And create a plugin.js file with this content

module.exports = {
    plugin: (schema, documents, config) => {
        return schema.extensions.sources[0].body;

I was running into this issue as well, I've packaged up my solution in case it's of use to anyone else - this is a custom fetch implementation that takes care of fetching Prismic-ref for you, and supports private apis

1 Like