Example of GraphQL querying a item with a relationship


#1

Hi

I’ve looked everywhere but I can’t find an example on how to query a list of items, where each item has a field with a relation to another item using GraphQL. I am currently using the GraphiQL tool.

I want to see the relation item’s data nested. I see you’ve mentioned it can be done using GraphQL, but I can’t find an example.

Please help.

Thanks
Rudolph


#2

Lets say you have two schemas:

  1. Category
    • name
    • posts (Reference to Posts)
  2. Posts
    • title

Then it would like this

{
   queryCategoryContents {
       id,
       data {
          name {
              iv
          },
          posts {
              id,
              data {
                title {
                  iv
               }
            }
        }
    }
}

#3

Thanks, I’ve figured it out but for me it looked as follow:

{
queryCategoryContents {
id,
data {
name {
iv
},
posts {
iv {
id,
data {
title {
iv
}
}
}
}
}
}


#4

yes, you are correct. Not easy to write these without intellisense.