birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

Querying data based on relation #210

Open sn3h opened 4 years ago

sn3h commented 4 years ago

Hi, I am kinda new to this stuff and after few hours I still have no idea how to solve (to me) a simple problem using this plugin. Let's have a Tag and Article custom types. Article has group fields of relationship fied limited to Tags. Let's have 4 articles with these tags: A1[T1,T2,T3], A2[T1], A3[T2], A4[T3]

GraphQL offers me allArticles, allTags, article and tag. But I see no way how I could ask for something like this: allArticles ( filter: {article_tags: "T1", limit: 3})

Not sure if I am writing that right, but the point is to get max. 3 newest articles that has T1. So I could therefore link next article from articles, next article with some tag, or newest articles from each tag..

Ability to that easily has huge implications for me. Thanks to anyone who can help :)

dmtrek14 commented 4 years ago

Prismic doesn't allow you to query linked items that are in a group or slice. I asked that same question recently in the Community Forum.

My case is that I had custom types of Publication and Subject and I wanted to filter Publications by Subject, so that I could have a page for each subject. What I ended up doing was, in the gatsby-node, iterating through all of the Publications and adding them to an array. I used the createPage function to create a page for each Subject and passed a filtered version of my Publications array in the context.

So, the issue is not with this plugin, but Prismic's own limitations. I did use this plugin to create individual pages for each Publication, but I had to create my AllPublications page in the gatsby-node and pass in my array.

Let me know if you want me to pass on any code samples for what I did.

sn3h commented 4 years ago

I solved it with gatsby-source-prismic, which has no problem with that.. I can't create custom fields on nodes there, but that's another story... Context is fine, but I'd like to have access to things even outside of context :/ Anyway, thank you for your time, much appreciated