Example for retrieving nested content

Hi Sebastian,

we are now using schemas with nested references with the following structure

  • Home page
    • team schema 1
      • team-member schema
        • person schema

Basically, we tried to create a list of persons. Most of these persons are part of the team / team-member. Let’s assume we want to have a page where we want to show some content and all persons assigned to content team schema 1 (we could have a different page where we assign team-members to team 2)

Right now, we tried to use the ClientLibrary to query from the top content. By doing so, we do not get our references resolved. We’ve seen a couple of questions in this forum (e.g., Using the Reference Type) which basically tell us to either

  1. load the recursively.
    Taking your comment from [IMPLEMENTED] One-to-many relationship display on Content section a little bit out of context, you agree that having single calls for referenced content is not the best way to go. I think it’s possible to query multiple IDs at once instead of using N queries for N referenced content items. Given we have a deeper hierarchy, we would need to make at least 1 query for each level of hierarchy which is consuming time and API calls.
  2. using GraphQL. This seems to your most recommended solution.

We’ve invested 3-4 hours to trying to get the referenced content resolved and we are at a point where we are a bit frustrated. We’ve managed to write a Graph QL query in the GraphiQL interface (https://cloud.squidex.io/app/XXX/api/graphql) but it’s cumbersome to write such a query per hand and keep it in sync with schema changes.

Open questions that we currently have:

  1. The easiest way for us would be to have all references resolved automatically (so that it would feel like a big SQL join) by Squidex. Since that request came up multiple times in the past and it’s not implemented suggests, that not resolving references from IDs to content is by design. Instead of breaking existing functionality, an optional query parameter with ‘ResolveNestedSchemas’ would be a possible way to do this. Is this something you would consider on the roadmap?
  2. How do we move from having a query from GraphiQL to using it with the SquidexClientLibrary? I think we came to the point where we found the right method but didn’t know how to wrap the example query back to C# classes. I’m not sure if we’ve understood Squidex’s GraphQL approach correctly: Do we really need to manually keep these three places in sync? 1) Schema in Squidex, 2) GraphQL query as C# Code, 3) C# wrapper class with attributes that read the JSON response and map to properties in the C# classes.
    Is there an easier way?
  3. Would you please provide a complete example in the docs for using GraphQL with multiple levels of nested schemas, starting by creating the schemas in Squidex, writing a GraphQL query for them, querying the API from the GraphQL syntax as C# code through the NuGet package and providing a C# response class where the result from GraphQL is being somewhat flat? This would help us a lot :slight_smile: Thank you!

So many questions:

Load the references recursively

I would use this endpoint for that: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsClient.cs#L33

So you need to collect all ids first and then resolve them all together. And this needs to be done for each level.

About “Open questions that we currently have:”

  1. I would consider that, but I don’t see, why I should just put more stuff into REST, when GraphQL can do that already. Resolving all references is an issue, it can lead to a lot of duplicate data potentially and the load on the DB is not predictable. You can even have loops.

  2. Yes, that is the GraphQL story, nothing I have invented. I would really like to see a star operator like in SQL but it is not there.

  3. Yes, I can do that the next days

1 Like

Thanks for your fast reponse! We are looking forward for the example in the next week and continue from there on :wink:

Its not a documentation yet, but kind of a sample: https://github.com/Squidex/squidex/blob/master/backend/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs

Thank you very much!

Unfortunately, after one hour of adapting your code to our schema, we decided to not use the GraphQL endpoint since it’s too time consuming to write GraphQL (although we managed to write the query we needed, it just took us some time) and especially the C# classes necessary since we need to keep them in sync in the future manually. We decided to throw away all of our schemas and started from scratch again and try to avoid any referenced content. Instead, we’ll just solve this with additional API calls :expressionless:

With the flat schema hierarchy and the additional calls, everything is running smooth now.

Maybe you can extend the docs in the future (e.g., by linking your example) but we don’t need it anymore at the moment.