How to filter a query on linkedFrom? - graphql

I have a collection of authors. Some authors have written blogs, others have not. I can reference the total amount of blogs they've written using:
query {
authorCollection {
linkedFrom {
blogCollection {
total
}
}
}
}
What I want, however, is a list of authors with more than 1 blog post. Some have written blogs, others have not. How can I filter the query to do so? Ive tried something like this but this is not possible:
query {
authorCollection(where: {linkedFrom: //This is not an available option}) {
linkedFrom {
blogCollection {
total
}
}
}
}

Related

Performing A GraphQL Selection On A Union for shopify SellingPlanPricingPolicy

I am trying to get union data using the Graphql APIfor Shopify and am unable to find any documentation on selecting data in unions.
Here is my current query:
query subscriptionPlans {
sellingPlanGroup(id: 1234) {
id
name
sellingPlans(first: 1) {
edges {
node {
id
billingPolicy {
... on SellingPlanRecurringBillingPolicy {
interval
intervalCount
}
}
pricingPolicies {
on
SellingPlanRecurringPricingPolicy {
afterCycle
adjustmentType
adjustmentValue {
on
SellingPlanPricingPolicyPercentageValue {
percentage
}
on
MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
I am able to retrieve the sellingPlans in this scenario. When I get to the SellingPlanPricingPolicy portion I run into issues. I am receiving the error:
Selections can't be made directly on unions (see selections on SellingPlanPricingPolicy)
However, I am unable to find any documentation on making selections using the documentation at: https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/sellingplanpricingpoli...
Any help with this would be appreciated. I just need an example of how to select this information.
Found the answer in https://graphql.org/learn/queries/#meta-fields. In case of sponsorEntity it looks like this:
sponsorEntity {
... on User {
name
}
}
The solution is to select the attributes on the respective sub-type of the union.

GraphQL query filtering multiple relations

(From Strapi) I am trying to get all "acts" with a certain age (can return multiple) and with a certain place (can return multiple). I can't figure out how to filter that.
This is what I am trying in GraphQL-playground (works without the variables), but it says "Unknown argument "age" on field "Act.ages"." (and "place" respectively).
query GetActs ($age:Int, $place:String) {
acts {
data {
id
attributes {
Title
ages (age: $age) {
data {
id
attributes {
age
}
}
}
places (place: $place) {
data {
id
attributes {
place
}
}
}
}
}
}
}
I just ran into this same issue. I can't make out the error you're reporting, but here is what worked for me.
You can use filter at the collection level to drill down to nested fields for the corresponding attributes. This follows the GraphQL example at the bottom of this Strapi resource on filtering nested fields.
Solution
query GetActs ($age:Int, $place:String) {
acts (filters: {ages: {age: {eq: $age}}, places: {place: {eq: $place}}}) {
data {
id
attributes {
Title
ages {
data {
id
attributes {
age
}
}
}
places {
data {
id
attributes {
place
}
}
}
}
}
}
}

Is it possible to filter a collection based on a collection field on the content type in graphql & contentful

This might be impossible in graphql/contentful or introduce too much complexity but I'm trying to query a collection and filter on a collection field, something like the following...
query {
eventCollection(
where: {
OR: [
{ categoryCollection: { key: "fashion" } }
]
}
) {
items {
slug
}
}
My back up plan is to query all the events and filter in the client but I thought it would be possible to do the above.
Contentful DevRel here. 👋
Currently, that's not possible. But what you can do is flip the query around and filter on the categoryCollection and then use linkedFrom to request the items linking to it.
query {
categoryCollection(where: {
key: "fashion
}) {
items {
title
linkedFrom {
eventCollection {
items {
slug
}
}
}
}
}
}

How do I filter issue comment authors using GraphQL

I'm trying to figure out how to get the list of comments on an issue using GraphQL. I'm able to get comments by everyone but not only by author.
My code:
query {
repository(name: "maintainer-bot", owner: "Xenfo") {
issue(number: 16) {
comments(first: 10) {
nodes {
author {
login
}
}
}
}
}
}
My question: How would I filter the comments returned so that only the user with the name Xenfo has his comments returned?

How can I filter by uid of a linked document / relationship using the prismic graphql api?

I am trying to list a set of articles by their categories, by uid, and I'm assuming that I would have to use the where query, but I'm not able to get that to worked on linked documents.
The issue seems to be that where only accepts a string on a field, but in the case of a linked document you would need to dig down to the uid field.
I'm not sure if I'm using the wrong query, but struggling to find anything in the documentation to help me out.
I tried digging into the category object:
{
allDirectoryServices(
where: { category: { _meta: { uid: "developers" } } }
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
But that returns an error that it's expecting a string:
"message": "Expected type String, found {_meta: {uid: \"developers\"}}.",
{
allDirectoryServices(
where: { category: "developers"}
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
This returns no results, obviously.
I asked this question on the Prismic Slack group too, and got the answer from them:
In order to query by a Content Relationship / Link field like this, you need to use the document ID.
where: { category: "WBsLfioAABNUo9Kk" }
Unfortunately it isn’t possible to query by the UID (or any other field).
I imagine they will be updating their documentation soonish, as this isn't covered by it.
Thanks to the Prismic guys!

Resources