rescript-relay icon indicating copy to clipboard operation
rescript-relay copied to clipboard

[feature] Figure out how to support providedVariables

Open zth opened this issue 4 years ago • 0 comments

"Provided variables" is a way of adding regular JS values as variable values in fragments. These values are resolved via JS files you specify, instead of needing to be added as an actual variable in the query, etc. In short, you can do:

fragment SomeFragment_user on User @argumentDefinitions(devicePixelRatio: {type:"Float!", provider: "DevicePixelRatioProvider"}) {
  avatarUrl(devicePixelRatio: $devicePixelRatio)
}

...and Relay will call your function in DevicePixelRatioProvider to get the value for devicePixelRatio at runtime, and wire it up for you with the GraphQL query, etc.

Quite handy for certain things. However, might be a bit hard to solve in ReScript, because the implementation involves type level dependency cycles if I recall correctly.

zth avatar Feb 04 '22 05:02 zth