zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 621 forks source link

Type parameter parserFn is required when constructing options. #1052

Closed renancaraujo closed 2 years ago

renancaraujo commented 2 years ago

Describe the issue SubscriptionOptions, QueryOptions and MutationOptions have contructors with an optional parserFn parameter and a type parameter TParsed .

When the user desires to omit parserFn, TParsed is still required, even though the existence of TParsed without a parserFn serves no purpose.

This creates an error:

MutationOptions(
    document: gql(_rawQuery),
    operationName: 'Something something',
    variables: <String, dynamic>{
      'input': {
        'stuff': 42,
      },
    },
  )

A workaround is to pass void as type param:

MutationOptions<void>(
    document: gql(_rawQuery),
    operationName: 'Something something',
    variables: <String, dynamic>{
      'input': {
        'stuff': 42,
      },
    },
  )

For a more consistent API, one can make the type parameter optional by specifying a supertype for TParsed:

- class MutationOptions<TParsed> extends BaseOptions<TParsed> {
+ class MutationOptions<TParsed extends Object?> extends BaseOptions<TParsed> {

In this way, TParsed doesn't ever need to be explicitly passed.

MutationOptions(
    document: gql(_rawQuery),
    operationName: 'Something something',
    variables: <String, dynamic>{
      'input': {
        'stuff': 42,
      },
    },
  )

To Reproduce (MUST BE PROVIDED) Just use this package creating either SubscriptionOptions, QueryOptions or MutationOptions omitting parserFn.

Expected behavior TParsed should not be a required argument if parserFn isn't.

device / execution context This does not regard any specific device constraint.

budde377 commented 2 years ago

@renancaraujo, in my code, the variables is defaulted to dynamic. Do you know why this is not the case in yours? A different language version?

renancaraujo commented 2 years ago

This is visible to projects that sets implicit-dynamic to false in the analyzer file.

budde377 commented 2 years ago

@renancaraujo, just so we're on the same page. That'd be the strict-raw-types?

budde377 commented 2 years ago

@renancaraujo, can you please check out this PR to see if this solves your issue: #1053