Skip to content
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

feature: adding the possibility of passing a function as fetchPolicy #2828

Closed
morrys opened this issue Aug 19, 2019 · 4 comments
Closed

feature: adding the possibility of passing a function as fetchPolicy #2828

morrys opened this issue Aug 19, 2019 · 4 comments

Comments

@morrys
Copy link
Contributor

morrys commented Aug 19, 2019

I would like to suggest adding the possibility of passing a function as fetchPolicy. This change will be useful when new fetchPolicy will be added.

export type FetchType = store-or-network | store-and-network | network-only | store-only

export type RefetchOptions = {|
   + force ?: boolean,
   + fetchPolicy ?: FetchType | (() => FetchType),
   + metadata ?: {[key: string]: mixed},
|};

export type FetchPolicy = FetchType | (() => FetchType);

This allows you to have dynamic policies without having to change the parameter, for example:

// ...
const fetchPolicy = function () {
   if (<condition>) {
      return 'store-only';
   }

   return 'store-then-network';
}
// ...
@josephsavona
Copy link
Contributor

Can you clarify the use-case? It isn't immediately obvious what additional flexibility this offers, since you can just execute the function yourself to decide the value.

@jstejada
Copy link
Contributor

@morrys also curious if you could elaborate why you need this type of behavior. I'm not sure I follow why the fetchPolicy would change for the same request. Can you dynamically pass the fetchPolicy you need (to useQUery or the refetch function) from above?

@sibelius
Copy link
Contributor

I think you can handle this using useQuery hook

it is more composable

@morrys
Copy link
Contributor Author

morrys commented Nov 9, 2019

As @sibelius says with the introduction of hooks this can be handled in other ways.

@morrys morrys closed this as completed Nov 9, 2019
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

4 participants