federation-hotchocolate icon indicating copy to clipboard operation
federation-hotchocolate copied to clipboard

feat: shareable framework types such as CollectionSegmentInfo

Open damienpontifex opened this issue 8 months ago • 0 comments

The type CollectionSegmentInfo is defined within HotChocolate for paging responses. Considering that, two subgraphs that use this same type end up with the below error on rover subgraph validation.

INVALID_FIELD_SHARING: Non-shareable field "CollectionSegmentInfo.hasNextPage" is resolved from multiple subgraphs:
INVALID_FIELD_SHARING: Non-shareable field "CollectionSegmentInfo.hasPreviousPage" is resolved from multiple subgraphs: it is resolved from subgraphs "a" and "b" and defined as non-shareable in subgraph "a"

These are troublesome to add decorators to e.g. I've had to do this to add a @tag decorator to them

public class PublicTypeInterceptor : TypeInterceptor
{
    public override void OnBeforeCompleteType(ITypeCompletionContext completionContext, DefinitionBase definition)
    {
        if (definition is not IHasDirectiveDefinition otd) return;
        switch (definition.Name)
        {
            case "ProductCollectionSegment":
            case "CollectionSegmentInfo":
                otd.AddDirective("tag", new[] { new ArgumentNode("name", "public") });
                break;
        }

        base.OnBeforeCompleteType(completionContext, definition);
    }
}

It'd be great to provide some ease of configuration or at least "standards" to be opted in to say so that such things such as @shareable might be added to some of these types to avoid every team having to provide a type interceptor to add these decorators and hence avoid conflicts such as the error above. The code example of adding the tag decorator might be specific to us, but again, does become something that needs repeating in each subgraph for a pageable type that needs it

n.b. I believe there are other common types e.g. cursor based paging vs token based that might also be included in this general nice to have outcome

damienpontifex avatar Oct 31 '23 05:10 damienpontifex