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

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

Closed
dariuszkuc opened this issue Oct 12, 2023 · 0 comments · Fixed by #18
Closed

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

dariuszkuc opened this issue Oct 12, 2023 · 0 comments · Fixed by #18

Comments

@dariuszkuc
Copy link
Member

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));
}
dariuszkuc added a commit that referenced this issue Oct 17, 2023
Federated `ArgumentParser` is used to map entity representation to method arguments. When unwrapping nested fields, current logic was not accounting to nullability of the underlying field. If the underlying field returned non-null object, parser would fail trying to find the target property on `NonNull` GraphQL wrapper (which obviously doesn't exist).

Updated argument parser object handling logic to unwrap non-null types.

Note: this PR only addresses the issue with non-null types. Similar bug is present when handling keys with list representations.

Resolves: #6
dariuszkuc added a commit that referenced this issue Oct 17, 2023
Federated `ArgumentParser` is used to map entity representation to
method arguments. When unwrapping nested fields, current logic was not
accounting to nullability of the underlying field. If the underlying
field returned non-null object, parser would fail trying to find the
target property on `NonNull` GraphQL wrapper (which obviously doesn't
exist).

Updated argument parser object handling logic to unwrap non-null types.

Note: this PR only addresses the issue with non-null types. Similar bug
is present when handling keys with list representations.

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

Successfully merging a pull request may close this issue.

1 participant