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

updateQueries by id (dataIdFromObject) #565

Closed
deoqc opened this issue Aug 19, 2016 · 3 comments
Closed

updateQueries by id (dataIdFromObject) #565

deoqc opened this issue Aug 19, 2016 · 3 comments

Comments

@deoqc
Copy link

deoqc commented Aug 19, 2016

Related to this, but instead of reading from cache, writing to cache.


Is it possible to update a mutation by some id (when using dataIdFromObject), instead of by query name (as is done now)?

Let me be more clear:

const query = gql`
  query {
    user {
      id
      friends {
        id
        name
        age
      }
    }
  }
`

const mutation = gql`
  mutation makingFriends($id: ID!) {
    letsMakeFriend(id: $id) {
      id
      name
      age
    }
  }

I know the user id (say id='123'), then I want to:

updateObject: {
  '123': (previousObject, { mutationResult }) => // do the logic
}

When using dataIdFromObject we prefer to reason in a object by id sense instead of query / paths. For more complicated and nested situations (more common than this example above) is much better to reason and much less error prone.

Let's compare these 2:

update by query name / path

updateQueries: {
  myChoosenQueryAmongMany: (previousQueryResult, { mutationResult }) => (
    deepmerge(
      previousQueryResult,
      {my: {very: {deep: {nested: {structure: [mutationResult.data.myMutation]}}}}}
    )
  )
}

update by id

updateObject: {
  myUniqueIdOfStruture: (previousObject, { mutationResult }) => ([
    ...previousObject,
    mutationResult.data.myMutation
  ])
}

Edit: most of the cases I will just return the parent object and refetch the entire updated child (and let the automatic update by id kick in). But on few important cases, the updated child is huge and I want to return only the relevant data.

@helfer
Copy link
Contributor

helfer commented Sep 6, 2016

@deoqc I think this could be quite useful in some edge cases. Would you be willing to make a PR for this and get it implemented?

@helfer helfer added this to the New API/Refactor milestone Sep 29, 2016
@helfer helfer removed this from the Release 0.5 milestone Oct 26, 2016
@helfer
Copy link
Contributor

helfer commented Jan 26, 2017

We've decided to implement this kind of imperative API for dealing with store updates right after we implement some logic for refetching, and before we implement any declarative API.

Closing this issue for lack of activity.

@helfer helfer closed this as completed Jan 26, 2017
@Clcll
Copy link

Clcll commented Dec 18, 2017

@deoqc Did you solve your issue?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants