Hello! I'm new to graph cool and graphql and have ...
# prisma-whats-new
j
Hello! I'm new to graph cool and graphql and have a qeustion about updating the store after a mutation. What is the best pattern to do this? Right now i'm refreshing the store by doing the same query after the mutation, but i don't get the refreshed result every time.
h
You are using apollo?
j
Yes, i'm using apollo.
Okey, thanks! This is a normal pattern to use?
j
Thanks!!
It don't look like it will work when i have multiple mutation, because of the name property? https://www.apollographql.com/docs/react/basics/mutations.html#multiple-mutations
I don't understand how to have both the name property and the update code
When i add the props property, calling this.props[name] dont work any more
h
i suggest follow code snippet in section i sent you last
In return of props you have name of mutation in that example it is submit
you can name it like you want
and thne you can acess it with
this.props.NAME
For example something like this:
Copy code
graphql(createFolder, {
    props: ({ ownProps, mutate }) => ({
      createFolder: data =>
        mutate({
          variables: data,
          update: (proxy, { data: { createFolder } }) => {
            try {
              const data = proxy.readQuery({
                query: organizationDetail,
                variables: { name: ownProps.activeOrganization }
              })
              data.Organization.folders.push(createFolder)
              proxy.writeQuery({
                query: organizationDetail,
                data: data,
                variables: { name: ownProps.activeOrganization }
              })
            } catch (e) {
              console.log(e)
            }
          }
        })
    })
  })
j
ah, i didn't see the submit name there. Thanks
k
@Jarand the easiest way is to call client.resetStore() after a mutation. This will trigger new network requests for the queries, but it saves you the trouble of updating the store manually.
you can get
client
by wrapping a React component with
withApollo()
HOC
j
aha, thats great to now. I wil ltry that out
So i can just await the mutation, and then call client.resetStore()?
Is there any reason to not do it this way?
h
Save data transfered between sever and client
When you update store you don't need to make request and wait for response etc