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

bug: entity resolver argument parser fails to map to objects #20

Open
dariuszkuc opened this issue Oct 17, 2023 · 1 comment
Open

bug: entity resolver argument parser fails to map to objects #20

dariuszkuc opened this issue Oct 17, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@dariuszkuc
Copy link
Member

Argument parser currently is only able to map scalar values. Attempting to use an object as an argument in [EntityResolver] leads to runtime errors.

[Key("bar { baz }")]
public class Foo
{

    public Foo(Bar bar, string? name)
    {
        Bar = bar;
        Name = name;   
    }

    public Bar bar { get; }
    public string? Name { get; }

    [ReferenceResolver]
    public static Foo? GetFooByBarBaz{
        Bar bar,
        Data repository)
    {
        // TODO implement logic
       return null;
    }
}

public class Bar {

    public Bar(string baz)
    {
        Baz = baz;
    }

    public Baz baz { get; }
}

Following workarounds are available

  1. map scalar arguments instead
    [ReferenceResolver]
    public static Foo? GetFooByBarBaz(
        [Map("bar.baz")] string baz
        Data repository)
    {
        // TODO implement logic
       return null;
    }
  1. instead of doing the auto mapping of arguments we process representation manually
    [ReferenceResolver]
    public static Foo? GetFooByBarBaz(
        [LocalState] ObjectValueNode data,
        Data repository)
    {
        // TODO implement logic by manually reading representation from data
       return null;
    }

Related #6

@phil-lee-kb
Copy link

Quick question - for the "// TODO implement logic by manually reading representation from data" option - I've had a look at the source code and there appear to be a range of Parsers and Converters that might already do the job of converting from the ObjectValueNode entity representation to the relevant C# entity class. Any guidance on which is the right one? Alternatively I'll just copy/paste some of the existing Parser/Visitor code to handle it.

E.g. In the above, converting from ObjectValueNode to Foo

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants