juancastillo0 / leto

Dart GraphQL server libraries. Utilities, code generator, examples and reference implementation.
https://juancastillo0.github.io/leto/
MIT License
38 stars 6 forks source link

Query variables aren't used as values when used in an InputType #7

Closed warrenisarobot closed 1 year ago

warrenisarobot commented 1 year ago

In Leto, when a query/mutation takes scalars for input variable substituion works fine. This function and query work: Dart function:

@Query()
//Get the first of all rewards
String something(Ctx ctx, String bob) {
  return "bob: $bob";
}

Client query:

mutation n($bob: String!){
  something(bob: $bob)
}

Server-side variable substitution works correctly. However, using using an input type this does not work as expected:

Dart function:

@GraphQLInput()
@JsonSerializable()
class BobInput {
  final String bob;

  BobInput(this.bob);

  factory BobInput.fromJson(Map<String, dynamic> json) =>
      _$BobInputFromJson(json);

  Map<String, dynamic> toJson() => _$BobInputToJson(this);
}

@Query()
String something(Ctx ctx, BobInput bobInput) {
  return "bob: ${bobInput.bob}";
}

Query:

query n($email: String!) {
  something(bobInput: { bob: $email })
}

This throws an exception on type coercion even when the varaible is set to a non-null value.

PR #6 addresses this