SAHB.GraphQLClient icon indicating copy to clipboard operation
SAHB.GraphQLClient copied to clipboard

How do I add arguments to a model nested in the query?

Open WesToleman opened this issue 4 years ago • 1 comments

Background

I am trying to generate this query that has arguments passed to a subschema

query($fooId: String! $filter: BarFilter) {
  foo(id: $fooId) {
    id
    ... on FooBar {
      bars(filter: $filter) {
        name
      }
    }
  }
}

Query Classes

public class FooQuery
{
    // This works for binding the fooId
    [GraphQLArguments("id", "String!", "fooId", isRequired: true, inlineArgument: false)]
    [GraphQLUnionOrInterface("FooBar", typeof(FooBar))]
    public Foo Foo { get; set; }
}

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

public class FooBar : Foo
{
    // This does not work
    [GraphQLArguments("filter", "BarFilter", "filter", isRequired: true, inlineArgument: false)]
    public IEnumerable<Bar> Bars { get; set; }
}

public class Bar
{
    public string Name { get; set; }
}

Issue

When I supply the filter it causes GraphQLArgumentVariableNotFoundException with the message "The arguments with the following variables could not be found: filter".

var args = new GraphQLQueryArgument[]
{
    new GraphQLQueryArgument("fooId", string.Empty),
    new GraphQLQueryArgument("filter", new { }),
};

What the model generates

The model generates this query with the following arguments

query($fooId:String!) {
  foo(id:$fooId) {
    id
    __typename
    ... on FooBar {
      bars {
        name
      }
      id
    }
  }
}
var args = new GraphQLQueryArgument[]
{
    new GraphQLQueryArgument("fooId", string.Empty),
};

WesToleman avatar May 21 '20 07:05 WesToleman

This is clearly an error. I will look on it when I have the time.

sahb1239 avatar Jun 21 '20 09:06 sahb1239