Max depth of graphQuery Deep Fetching

I'm trying to make a graphQuery with deep fetching, and it fails for me if I get to 3 levels deep. So I have to limit it to 2 levels deep so it could work for now.
And I can't find any information about this in the doc.
So, is it true grapQuery deep fetching is limited to 2 levels deep?

Hello @quang

Thanks for reaching out to us.

With GraphQuery, you can go deeper than two documents and also fetch Slices content. Can you send me your query and the repo of your URL?

Thanks,
Priyanka

Hello Priyanka,
Thanks for looking into this.
That's strange. Here's my query, please take a look. The repo is carbmanager.prismic.io

{
  keto_academy_home {
    collections {
      ...collectionsFields
      keto_academy_collection {
        ...keto_academy_collectionFields
        articles {
          ...articlesFields
          related_to {
            author {
              ...authorFields
            }
          }
        }
      }
    }
  }
}

Somehow it only works if I remove what comes after author. I've also tried with the ...on syntax but no different

Hello @quang

I have looked into your repository and query and found these things:

  1. You have a keto_academy_collection Custom Type that has the Content relationship field related_to linked to the keto_academy_article Custom Type, not to author Custom Type.
  2. You need to use a Union Type ...on to define the Custom Type that you are querying.

You need to update your query like this:

{
  keto_academy_collection {
    articles {
      related_to {
        ...on keto_academy_article {
           title
           is_behind_paywall
      }
     }
    }
  }
}

Once you have adjusted your API query, the linked content will appear in a data object nested in the Link or Content Relationship field. Here is a screenshot of your repository where I added the graphQuery and retrieved some fields from the keto_academy_article.


Screen Shot 2021-12-21 at 11.43.32

Give this a try, and let me know if you have further questions related to it.

Thanks,
Priyanka

I did try that,
Here is full query with the union, nothing changes for me, it only works without deep fetching author

{
  keto_academy_home {
    collections {
      ...collectionsFields
      keto_academy_collection {
        ...on keto_academy_collection {
          ...keto_academy_collectionFields
          articles {
            ...articlesFields
            related_to {
              ...on keto_academy_article {
                author {
                   ...on author {
                     ...authorFields
                   }
                }
              }
            }
          }
        }
      }
    }
  }
}

It works for me. Since you have a Group field inside an author Custom Type, you need to mention it specifically with their API ID. You might need to remove white spaces in your Rest API query. Learn more about it here.

{
keto_academy_collection {
articles {
related_to {
...on keto_academy_article {
title
is_behind_paywall
author {
...on author {
name
avatar
links {
...linksFields
}
}
}
}
}
}
}
}

See the API response, the linked content of author Custom Type nested in data object.

There might be some limitations for deep fetching with graphQuery, but I need to discuss this with my product team. But for sure, it's not limited to 2 levels deep. You can fetch more than two documents.

You cannot go deeper than three levels of documents. I will update our documentation accordingly. If you put in the Rest API browser, you might be getting this error:

I pasted the request url in the browser and it turns out it exceeds 3 levels deep. I thought it is only 2 levels but I counted again and it might be 3.
keto_academy_home > keto_academy_collection (1 level deep) > keto_academy_article (2) > author (3)
Or it might be 4. If the first level is counted.

Thank you anyway for your support. I'll make the change in my side.

Yes, It counts keto_academy_home too, up to three documents it works. The query I sent you above is working.

I am happy to help you. Feel free to reach out to us if you have any questions.

1 Like