graphql-codegen-plugin-typescript-swr icon indicating copy to clipboard operation
graphql-codegen-plugin-typescript-swr copied to clipboard

[Proof of concept] Custom key

Open ramiel opened this issue 2 years ago • 0 comments

:warning: This is not a real PR, just a working proof of concept to address some existing issues. :warning: The changeset is big because I need to use this PR from github directly. Only visitor.js has relevant changes

  • What kind of change does this PR introduce? Feature

  • What is the current behavior? (You can also link to an open issue here) The key cannot be changed dynamically

  • What is the new behavior (if this is a feature change)? A feature for which is possible to customise the key even if it's autogenerated. This address several issues as #157 and #158

  • Other information: The idea is to enable:

Conditional fetching

const result = sdk.useMyQuery(variables, undefined, {
  // This option let you customise the generated key. The key is passed as parameter to the function
  customKey: (key) => isTrue ? key : null
})

override the generated key

const result = sdk.useMyQuery(variables, undefined, {
  // This option let you customise the generated key. The key is passed as parameter to the function
  customKey: (key) => ([...key, customValue])
})

ramiel avatar Feb 17 '22 14:02 ramiel