search
AI OnAI Off
I reproduced this in CMS 13 using Optimizely.Graph.Cms.Query 13.3.0.
GraphQL supports filtering on ContentReference.key, but the C# SDK's FilterEquals() automatically targets url.default instead. Filtering through ContentReference.ID also throws NotSupportedException.
I found a workaround using a custom extension:
public static DelegateFilterBuilder KeyEquals(
this ContentReference reference, string key)
{
return new DelegateFilterBuilder(field =>
reference.FilterEquals(key).GetFilter(
field.Replace(".url.default", "") + ".key"));
}
Usage:
.Where(x => x.MyContentReference.KeyEquals(
anotherBlock.ContentGuid.ToString("N")))
I tested it successfully: the SDK generated MyContentReference: { key: { eq: "..." } } and Graph returned the expected results.
This uses public SDK APIs, but it's a workaround rather than built-in support for filtering by ContentReference.key.
This solves my last to-do for the CMS 12 to 13 upgrade. Thank you very much.
I'm migrating a content query from Find to the GraphQL C# SDK and need some guidance.
With Find, I can filter by the content reference ID like this:
The most direct equivalent using the GraphQL C# SDK throws a NotSupportedException.
Using FilterEquals() gets me closer:
However, this generates a filter against url.default, whereas I only have the content GUID (or a ContentReference) and need to filter by key instead.
The generated GraphQL query looks like this:
What I need is:
Is there a way to express this key filter using the C# SDK? Alternatively I can use the
IGraphClientdirectly with a hardcoded query, but I'd prefer to use the other method if available.Originally asked in the Optimizely Community Slack: #optimizely-graph.