Open alex-statsig opened 2 weeks ago
Yes! This is a much needed ability, I'm fully in favor of finding a way for us to support this. In fact, it may be that this should be the recommended default way to use mutations. Given that, we should think carefully about what would be the best API here to make it easy to get right and low-friction.
One significant challenge is that today the babel transform blindly converts the graphql
tagged template literal into a require
of the generated artifact which is the bit we want to avoid eagerly loading. And yet, defining the mutation directly in the hook that's going to dispatch it is the best low-friction developer experience.
I could also see a few options around when we load the artifact:
There are a lot of options here, so probably the next step would be to brainstorm. What timezone are you in? Would you be interested in attending one of our design discussion meetings to discuss what options we have here and decide what the next concrete steps would be?
I think this is really important work and would love to help support you get this feature added to Relay!
One significant challenge is that today the babel transform blindly converts the
graphql
tagged template literal into arequire
of the generated artifact which is the bit we want to avoid eagerly loading. And yet, defining the mutation directly in the hook that's going to dispatch it is the best low-friction developer experience.
Ah yeah I hadn't factored this in. Needing to define that in a separate file is definitely tedious (on top of likely defining a hook per mutation in its own file to capture common response handling logic)
There are a lot of options here, so probably the next step would be to brainstorm. What timezone are you in? Would you be interested in attending one of our design discussion meetings to discuss what options we have here and decide what the next concrete steps would be?
I am in PT, I'd be happy to join a design discussion meeting on this!
Almost all mutations are not needed for the initial render of a page, often being triggered by some delayed user interaction like a button click. However, it is currently hard to avoid bloating bundles with the mutation nodes when using the built-in
useMutation
hook. The mutation nodes contain JS proportional to the mutation document size (and thus potentially proportional to the page size if the page's data is included as a fragment) in the query text and operation/fragment fields.There's two main problems I've run into trying to solve this:
PreloadableConcreteRequest
), as well as a promise/JSResource for the actual mutation node (similar touseQueryLoader
, or perhapsuseEntryPointLoader
)While it would be possible to roll my own version of useMutation which allows this (the logic doesn't seem too complicated), I think it would be beneficial to provide first-class support to encourage this pattern. I'd be happy to help contribute something for this, but would like some confirmation that these are the right paths to go down