Is there an example somewhere of using Apollo Cli...
# prisma-whats-new
w
Is there an example somewhere of using Apollo Client's optimistic UI when doing a nested mutation?
n
@wallslide not that I'm aware of, did you set up Apollo's optimistic UI for normal mutations already?
w
I've used it before, yes
n
How does that differ from nested mutations?
w
here is the documentation I'm looking at: http://dev.apollodata.com/react/optimistic-ui.html
In their example,
submitComment
creates a comment
but if I use
updateUser
to create a team and associate that team with a user, then two things are changing, and a relationship between those two things is also created
n
Copy code
optimisticResponse: {
            __typename: 'Mutation',
            submitComment: {
              __typename: 'Comment',
              postedBy: ownProps.currentUser,
              createdAt: +new Date,
              content: commentContent,
            },
          },
you can replace
submitComment
with
updateUser
, and then have a key
team
and the value is a team object
w
so instead of
submitComment
would I just have an
updateUser
, or would I also have a
createTeam
in there?
what about under
updateQueries
?
n
Copy code
optimisticResponse: {
  __typename: 'Mutation',
  updateUser: {
    __typename: 'User',
    team: {
      __typename: 'Team'
      name: 'Some team'
    },
  },
},
that's my guess
updateQueries
works differently, you need to include a key for every query that you want to update
w
ahh, thanks. I'll try it out
n
Copy code
updateQueries: {
  // Would update the query that looks like:
  // query myUserQuery { ... }
  myUserQuery: (previousResult, { mutationResult }) => {
    // ...
  },
  myTeamQuery: (previousResult, { mutationResult }) => {
    // ...
  },
}