Resolve relationship between content

Hi,

I have a story structure where I have several content types:

  • news
  • reviews
  • features
  • products

At the moment, I can reference one or multiple products within news, reviews and features and I have the content being pulled through from the product on to that page using the GraphAPI.

I’m now trying to figure out how I can create a product page which contains a list of all the content that references it. So where it has been mentioned in a news, review or feature.

I started looking at the filter_query documentation, but it feels really lacking for GraphQL and seemingly any query I try (even a basic one) is returning Internal Server Error from the Storyblok API.

Does anyone know if this is even possible, or can offer any advice about how I would attempt to do this?

Hello @andismith,

can you show me the query that gives you the error message and the space ID, please?

Best regards
Hannes

Hi Hannes,

I can’t see to find documentation on how the filter_query should be used in GraphQL, so I’m currently trying something like (following the example in the docs for the RESTAPI):

{
  NewsItems(filter_query: "[name][like]=*john*") {
    items {
      name
    }
  }
}

which gives me SyntaxError: Unexpected token < in JSON at position 0

The space ID is 122649.

What I’m ultimately trying to do is be able from a product reference what news, reviews or features it has been included in. In those schemas, I added them as blocks with a component whitelist.

Thanks,
Andi

Hello @andismith,

the correct syntax would look like this:

  NewsItems(filter_query: {name: {like: "*john*"}}) {
    items {
      name
    }
  }
}

but as you can only search inside of the content type this query wouldn’t work. You can filter only for fields inside of the content type when you use the filter_query parameter.

What you could do is to use the parameter by_slugs to filter for stories by their slugs:

{
  NewsItems(by_slugs: "*john*") {
    items {
      name
      slug
    }
  }
}

Best regards
Hannes