Open richardwu opened 3 years ago
It would be nice to be able to specify additional "keys" for the caching logic of a query. This was mentioned in https://github.com/apollographql/apollo-client/issues/1420 but was subsequently closed.
Concretely, if I'm passing additional information like target language in the header, it'd be convenient to not have to modify all my GraphQL endpoints to accept (and subsequently discard) the variable.
I've tried the following:
const FOO_QUERY = gql` query foo { foo { ... } } `; useQuery(FOO_QUERY, {variables: {lang: 'en'}})
But the above will still share the cache with other lang variables.
lang
You need to include $lang as a variable to the GraphQL query:
$lang
const FOO_QUERY = gql` query foo($lang: String) { foo { ... } } `;
But this will raise the error Variable $lang is never used in operation if $lang is not used. Doing the following:
Variable $lang is never used in operation
const FOO_QUERY = gql` query foo($lang: String) { foo(lang: $lang) { ... } } `;
works, but will require me to add the superfluous lang variable to my foo endpoint.
foo
+1
It would be nice to be able to specify additional "keys" for the caching logic of a query. This was mentioned in https://github.com/apollographql/apollo-client/issues/1420 but was subsequently closed.
Concretely, if I'm passing additional information like target language in the header, it'd be convenient to not have to modify all my GraphQL endpoints to accept (and subsequently discard) the variable.
I've tried the following:
But the above will still share the cache with other
lang
variables.You need to include
$lang
as a variable to the GraphQL query:But this will raise the error
Variable $lang is never used in operation
if$lang
is not used. Doing the following:works, but will require me to add the superfluous
lang
variable to myfoo
endpoint.