Skip to content

How do I transform the names of parameters for a class that is used as a query argument? #98

@WesToleman

Description

@WesToleman

Background

I'm trying to pass the variables { "foo": {"fooNumber": "0123456789", "systemCode": "BAZ"} } to this query

query GetFooId(
  $foo: FooNumber
) {
  foobeta (foo: foo) {
    id
  }
}

What works

If I use a class that with parameters that are named identically it works.

var = new { number = "0123456789", systemCode = FooSystemType.BAZ };
var arg = new GraphQLQueryArgument("foo", foo));

Issue

However it does not work with a traditionally named class because parameter names are not transformed.

public class FooNumber
{
    [GraphQLFieldName("fooNumber")]
    public string Number { get; set; }

    public FooSystemType SystemCode { get; set; }
}

It generates an SAHB.GraphQLClient.Exceptions.GraphQLHttpExecutorServerErrorStatusCodeException because of a BadRequest.

Generated Query

Query

query($foo:FooNumber){foobeta(foo:$foo){id}}",

Variables

"foo": {
    "Number": "0123456789",
    "SystemCode": "BAZ"
}

Response

{
    "errors": [
        {
            "message": "Variable \"$foo\" got invalid value { Number: \"0123456789\", SystemCode: \"BAZ\" }; Field fooNumber of required type String! was not provided."
        },
        {
            "message": "Variable \"$foo\" got invalid value { Number: \"0123456789\", SystemCode: \"BAZ\" }; Field systemCode of required type FooSystemType! was not provided."
        },
        {
            "message": "Variable \"$foo\" got invalid value { Number: \"0123456789\", SystemCode: \"BAZ\" }; Field \"Number\" is not defined by type FooNumber."
        },
        {
            "message": "Variable \"$foo\" got invalid value { Number: \"0123456789\", SystemCode: \"BAZ\" }; Field \"SystemCode\" is not defined by type FooNumber. Did you mean systemCode?"
        }
    ],
}

Query classes

public class FooQuery
{
    [GraphQLArguments("foo", "FooNumber", "foo")]
    public FooBeta FooBeta { get; set; }
}

[GraphQLFieldName("foobeta")]
public class FooBeta : Foo
{
}

public class Foo
{
    public string Id { get; set; }
}

[JsonConverter(typeof(StringEnumConverter))]
public enum FooSystemType
{
    [EnumMember(Value = "BAZ")]
    BAZ,
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions