graphql_ppx icon indicating copy to clipboard operation
graphql_ppx copied to clipboard

Get the query's name (string) for usage in Apollo's `refetchQueries`

Open elnygren opened this issue 5 years ago • 1 comments

Could graphql_ppx generate a let binding that contains the GraphQL query's name?

example input

module FooBarGQL = [%graphql
  {|
  query fooBarDingDong {
    foo { bar }
  }
|}
];

output:

module FooBarGQL = {
  /* all the usual fields  generated by graphql_ppx */
  let ppx_printed_query = "...";
  let query = ppx_printed_query;
  let parse = value...;
  // ...etc...

  /* new field */
  let queryName = "fooBarDingDong"
}

This would be nice as now we have to do refetchQueries=[| "fooBarDingDong" |] https://github.com/apollographql/reason-apollo#mutation

elnygren avatar Jun 25 '19 14:06 elnygren

reason-apollo-hooks uses the approach with passing both query and variables as it's supported by Apollo. Probably a good idea to submit PR to reason-apollo to support such a way of passing refetchQueries

baransu avatar Oct 05 '19 20:10 baransu