Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

feat: shareable framework types such as CollectionSegmentInfo #46

Open
damienpontifex opened this issue Oct 31, 2023 · 0 comments
Open

Comments

@damienpontifex
Copy link
Contributor

damienpontifex commented Oct 31, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant