apollographql / federation-hotchocolate

HotChocolate support for Apollo Federation
https://www.apollographql.com/docs/federation/
MIT License
16 stars 8 forks source link

bug: map `@key` resolver logic fails to unwrap the entity representation #6

Closed dariuszkuc closed 1 year ago

dariuszkuc commented 1 year ago

Reference resolver currently fails to map nested selection set representation.

Failing case (link)

[Key("id")]
[Key("sku variation { id }")]
public class Product
{
    public Product(string id, string? sku, string? package, ProductVariation? variation)
    {
        Id = id;
        Sku = sku;
        Package = package;
        Variation = variation;
    }

    [ID]
    public string Id { get; }

    public string? Sku { get; }

    public string? Package { get; }

    public ProductVariation? Variation { get; }

    [ReferenceResolver]
    public static Product? GetProductById(
        string id,
        Data repository)
        => repository.Products.FirstOrDefault(t => t.Id.Equals(id));

    // THIS RESOLVER FAILS
    [ReferenceResolver]
    public static Product? GetProductByVariation(
        string sku,
        [Map("variation.id")] string variationId,
        Data repository)
        => repository.Products.FirstOrDefault(
            t => (t.Sku?.Equals(sku) ?? false) &&
                (t.Variation?.Id.Equals(variationId) ?? false));
}