GraphQL don't return published document

Hello,

Some of our documents are not returned in GraphQL and REST APIs although they are published and visible in Prismic panel.
For instance document YRzksRAAACEAYptO is not returned from following query:

{
  allCity_pages {
    totalCount
    edges {
      node {
        slug
      }
    }
  }
}

Also when I try to run Preview, REST API is not returning the document so I see No documents were returned error.

Hi Piotr,

Thanks for reaching out.

To help debug this issue, can I have the repository name you are trying to query (in a private message if necessary)?

This issue can be related to querying the API using an old API ref. Can you try to refresh your API browser to get a new ref (master ref) to see if you can get those published docs?

Also, I recommend you check this troubleshooting article.

Looking forward to your reply,
Fares

Hi @piotr.z

Well the given Id is available in the GraphQL and the REST API.

In fact, you have forgotten to add the lang in the query as this document id doesn't exist in the main locale.
To fetch documents in all locales then you can use the wide card (*) such as lang=*

To learn more about how supply lang URL parameter check this document.

Please let me know if need any further help,
Fares

Hi @Fares,

Thank you for your response.

  1. I tried your suggestion, but when I'm querying GraphQL with or without lang: * I got the same amount of results:
{
  allCity_pages(lang: "*")  {
    totalCount
    edges {
      
      node {
        _meta {
          id
        }
        slug
      }
    }
  }
}
  1. Today mentioned document is returned by the query even though english version has not been added. Why does it work today? We still have number of such documents which are not returned by the query, e.g. YR4T9RAAACIAZ9yg, YR4V9xAAACIAZ-Wp.

  2. You suggested to add lang parameter to REST call, but as I can see the parameter is already there in Prismic plugin, and documents are not there, e.g. https://batmaid.cdn.prismic.io/api/v2/documents/search?ref=https%3A%2F%2Fbatmaid.prismic.io%2Fpreviews%2FYXayDhIAACIAsX3Z%3FwebsitePreviewId%3DYNx10BIAAI8SyYOP&q=[[at(document.id%2C+"YR4T9RAAACIAZ9yg")]]&lang=*&pageSize=100&access_token=removed

^^ this is a query from Gatsby Preview Plugin and Prismic returns no results

Regards,
Piotr

Well, in fact, GraphQL gets all locales and that's why the docs count is 610, to the contrary to the REST API where it returns on the master locale docs:

And for us, this is correct behavior that we want to apply in the future if we want to implement a v3 of the REST API.

  1. Answered in 1

  2. You are using a preview ref and that is why you are unable to get the document if you use a master ref then you can get it like:

https://batmaid.prismic.io/api/v2/documents/search?ref=YXayDhIAACIAsX3Z&q=[[at(document.id,"YRzksRAAACEAYptO")]]&lang=*#format=json

We are using Graphql together with Gatsby plugin to fetch documents. In our query we do not specify language and we expect to have all documents in any language. It works for most of our documents but in some cases documents are not returned, examples in previous post.

The same happens when we query by document id - both documents are published on master and both do not have english version:

This document works:
https://batmaid.prismic.io/graphql?query={ %20%20allCity_pages(id%3A%20"YRzksRAAACEAYptO")%20{ %20%20%20%20totalCount %20%20%20%20edges%20{ %20%20%20%20%20%20node%20{ %20%20%20%20%20%20%20%20slug %20%20%20%20%20%20} %20%20%20%20} %20%20} }

This one doesn't:
https://batmaid.prismic.io/graphql?query={ %20%20allCity_pages(id%3A%20"YR4T9RAAACIAZ9yg")%20{ %20%20%20%20totalCount %20%20%20%20edges%20{ %20%20%20%20%20%20node%20{ %20%20%20%20%20%20%20%20slug %20%20%20%20%20%20} %20%20%20%20} %20%20} }

So I've reproduced the issue on a clone of your repository, and in fact, making a change to the document and publish again will solve the issue for this document.

https://batmaid.prismic.io/graphql?query={ %20%20allCity_pages(id%3A%20"YR4T9RAAACIAZ9yg")%20{ %20%20%20%20totalCount %20%20%20%20edges%20{ %20%20%20%20%20%20node%20{ %20%20%20%20%20%20%20%20slug %20%20%20%20%20%20} %20%20%20%20} %20%20} }

I have created an issue for this in our tracker and also created a clone of your repository to keep track of the issue if you use the workaround.

This thread is being monitored as an open ticket in the internal Prismic issue tracker. The Prismic support team will update this post as we get more information from our dev team. If you have a similar use-case, you can ‘Flag’ this topic to reopen and add it here.