Skip to content

Proxy style mutation hook #1602

@vicary

Description

@vicary

Users want useMutation to work just like useQuery, not callback style like useLazyQuery.

We have been experimenting with proxy-style mutations in the past, during the early days of core v3 refactoring. Users tend to store proxy objects in states, when properties are being accessed in future renders, unexpected mutation fetches will happen, frequently so in some cases.

It is possible to allow the storage of stale accessors in states, by stripping their ability of triggering further fetches after the first fetch is happened.

  1. For queries and mutations, accessors are deep frozen into the respond data. That is, their ability to trigger fetches is removed after their first fetch.
  2. Caches are only read by accessors before their first fetch happens.
  3. Our current memo of context should be scrapped, do benchmarks if we actually re-create resolver contexts every single render.

Subscriptions should not be affected, since reconnection is always allowed and should not have side effects.


Originally posted by @hyusetiawan in #1601 (reply in thread)

@vicary for both modes, where do you get the variable mutation in the button onclick?

the API is rather awkward, I am sure there is an engineering reasoning behind it, is it not possible to do:

const {login} = useMutation()
const [mutation, state] = login

so it is more consistent with the useQuery?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions