Filter by ContentReference key with the Optimizely Graph C# SDK (migrating from Find)

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:

var query = _findClient
    .Search<ContentBlock>()
    .Filter(f => f.MyContentReference.ID.Match(anotherBlock.ContentLink.ID));

The most direct equivalent using the GraphQL C# SDK throws a NotSupportedException.

var query = _graphClient
    .QueryContent<ContentBlock>()
    .Where(f => f.MyContentReference.ID.Match(anotherBlock.ContentLink.ID));

Using FilterEquals() gets me closer:

var query = _graphClient
    .QueryContent<ContentBlock>()
    .Where(f => f.MyContentReference.FilterEquals(anotherBlockContentGuid.ToString("N")));

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:

where: {
  MyContentReference: {
    url: {
      default: {
        eq: "7fdc98b41d3a421ca6ca5c83f980c707"
      }
    }
  }
}

What I need is:

where: {
  MyContentReference: {
    key: {
      eq: "7fdc98b41d3a421ca6ca5c83f980c707"
    }
  }
}

Is there a way to express this key filter using the C# SDK? Alternatively I can use the IGraphClient directly with a hardcoded query, but I'd prefer to use the other method if available.

Originally asked in the Optimizely Community Slack: #optimizely-graph.

#343649
Oct 09, 2026 9:11
Mardy
Vote:

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.

#343650
Oct 09, 2026 11:30

This solves my last to-do for the CMS 12 to 13 upgrade. Thank you very much.

#343651
Oct 09, 2026 11:51
Mardy

Glad it helped, Good luck with the migration!

#343652
Oct 09, 2026 12:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.