Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Can't use queries with variables in refetchQueries #203

Open
1 of 5 tasks
MargaretKrutikova opened this issue Jul 27, 2019 · 2 comments
Open
1 of 5 tasks

Can't use queries with variables in refetchQueries #203

MargaretKrutikova opened this issue Jul 27, 2019 · 2 comments

Comments

@MargaretKrutikova
Copy link
Contributor

Currently you can only pass string in refetchQueries when calling mutations, because the type apolloMutation in ReasonApolloMutation defines refetchQueries as optional array(string).

However, it seems like in many cases you would actually want to pass variables to those queries, apollo-client defines it like this:

type PureQueryOptions = {
  query: DocumentNode;
  variables?: { [key: string]: any };
  context?: any;
};
type RefetchQueryDescription = Array<string | PureQueryOptions>;
...
refetchQueries?:
    | ((result: ExecutionResult<T>) => RefetchQueryDescription)
    | RefetchQueryDescription;

In reason-apollo, there is a type queryObj in ApolloClient:

type queryObj = {
  .
  "query": ReasonApolloTypes.queryString,
  "variables": Js.Json.t,
};

so I quickly tried making refetchQueries into unit => array(queryObj)=? and it allowed me to pass variables into queries in refetchQueries.

However I am not sure how to make it work for both for strings and proper query objects. Is it even possible to do in reason?

  • has-reproduction
  • feature
  • docs
  • blocking
  • good first issue
@Gregoirevda
Copy link
Contributor

Good point! I guess it would require both types to be wrapped in a variant which can then be deconstructed in ReasonApolloMutation. That would be a breaking change. Could you create a PR?

@MargaretKrutikova
Copy link
Contributor Author

Yes, absolutely! I will prepare a PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants