GraphQL getting id of Story linked using Single Option

I’m trying to build a hierarchy of stories (to represent the tree of categories).
I’m unable to get any information from the Story linked via Single Option relation

Query:

      CategoryItem(id: 'categories/b') {
        id
        name
        content {
          parent {
            id
          }
        }
      }
    }

Results in the following (500 error)

SyntaxError: Unexpected token < in JSON at position 0

Anything that I’m doing wrong? In the JSON I can see that the reference is kept as UUID but GraphQL schema resolves parent as a field of Story type and forces accessing content via parent { ... } . Since accessing this kind of nested doesn’t seem to be supported there’s no way to even get to know the parent UUID (to query the data in separate query).

Hello Wojciech,

nice to have you in our forum!
You need to pass the component-field values to the resolve_relations parameter like in my example:

  RelationsItem(resolve_relations: "relations.single_option", id: "relations/test_story_relations") {
    content {
      single_option {
        content
      }
    }
  }
}

More to the topic resolve_relations can be found in our documentation --> https://www.storyblok.com/docs/api/content-delivery#core-resources/stories/retrieve-one-story

It worked, thanks!

By the way, isn’t it a bit of a GraphQL anti-pattern? It seems like the query itself should be sufficient for determining whether relation needs to be resolved or not.

You’re welcome!

The reason for this is that you can resolve at maximum 100 relations in one call. In the case that you have more and want to use those UIDs in another way or request them selectively making it automatically would take the choice from the developers and give less control about this.