Skip to content

Feature Request: set type QueryOptions and MutationOptions like Apollo #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
isaiahtaylorhh opened this issue Mar 14, 2020 · 3 comments
Closed

Comments

@isaiahtaylorhh
Copy link
Contributor

isaiahtaylorhh commented Mar 14, 2020

Is your feature request related to a problem? Please describe.
In Apollo, you can specify mutate(MutationOptions<CreateTestInput>{variables: {...}}). This is very powerful because it enforces the schema's requirements for a query or mutation. This is especially powerful when used in conjunction with automatic type generation like this: https://github.com/micimize/graphql-to-dart .

Describe the solution you'd like

class MutationOptions<T> extends BaseOptions {
  MutationOptions({
    // ...
    Map<String, T> variables, // used to be <String, dynamic>
    // ...
  }) : super(
    // ...
  );
}

Same for query.

Additional context
I've got this running locally and it works great. If I get some extra time I'll put it up in a PR but that is unlikely.

Usage:

await client.mutate(
  MutationOptions<CreateTestInput>(
    documentNode: gql(myMutation),
    variables: {
      "input": myTestInput, // myTestInput is CreateTestInput
    })
);
@isaiahtaylorhh
Copy link
Contributor Author

This could also be extended to the QueryResult so that QueryResult.data is MySchemaType.

@micimize
Copy link
Collaborator

We wouldn't be able to do Map<String, T>, but we can use the generated variable type as well.

@micimize
Copy link
Collaborator

micimize commented Nov 7, 2020

Merging in to #636 and continuing convo there

@micimize micimize closed this as completed Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants