Comments (6)
Nope. Would love to see that. Unsure if it's orthogonal to #20 or if it should be tackled at the same time. Do you have an idea of what changes would need to be made to support this?
from ember-apollo-client.
I'll read through #20 closer tomorrow, but a quick skim tells me yes and no. Yes, it's helpful, because those updates would automatically be shown, but no, because there is a separate API for writing directly to the local store. The only approach I know of this so far is how react-apollos
handles it. I'll dig into that implementation and see what I can reason about.
Thanks for the quick response! I'm excited to see people actively finding this library and inquiring about it. Makes it a stronger library in the end!
from ember-apollo-client.
Okay, I did some more research on this.
Apollo's mutate
can take an optional update
function which is called after the server responds. Here is a simple example that adds a new link that was just mutated (createLink
) into the store cache:
update: (store, { data: { createLink } }) => {
const data = store.readQuery({ query: ALL_LINKS_QUERY })
store.writeQuery({ query: ALL_LINKS_QUERY, data })
}
The best I can tell, I would propose that this function happen within mutate
's then
block. Looks like you should take the current store
, the result of the mutation and pass them into the update
function. The user then uses the Apollo API to manipulate the store.
Does this make sense?
from ember-apollo-client.
@DevanB @bgentry I'm heavily using the imperative store api for optimistic ui updates. This is a apollo-client feature not an react-apollo feature. You can just pass an update function to the apollo services mutate function.
Here some example:
apollo.mutate({
mutation: DeleteWrapperMutation,
variables: {wrapperId},
optimisticResponse: {
__typename: `Mutation`,
deleteWrapper: true,
},
update(proxy, {data: {deleteWrapper: success}}) {
if (!success) {
return
}
const questionnaireFragment = proxy.readFragment({
fragment: BlockMutateWrappersFragment,
fragmentName: `BlockMutateWrappersFragment`,
id: blockFragmentId,
})
questionnaireFragment.wrappers = questionnaireFragment.wrappers
.filter(wrapper => wrapper.id !== wrapperId)
.sort((w1, w2) => w1.sort - w2.sort)
questionnaireFragment.wrappers.forEach((wrapper, i) => wrapper.sort = i + 1)
proxy.writeFragment({
fragment: BlockMutateWrappersFragment,
fragmentName: `BlockMutateWrappersFragment`,
id: blockFragmentId,
data: questionnaireFragment,
})
},
})
from ember-apollo-client.
@n1ru4l This is great news! I literally just got it working, however I'm seeing odd warnings in my console about __typename
missing (I know this is an ongoing issue that will soon be resolved!) and what could be warnings caused by other documents in my store that don't meet the schema I built.
@bgentry I'd love to help you and others that use this library by writing some documentation on the README on the update
options usages; if this is something you would be prepared to merge in.
Additionally, you will probably see an influx of traffic to this add-on in the next 2-3 weeks as I wrap up the screencast and tutorial writing and it is published on How To GraphQL. I'd love to dedicate more time to helping maintain this library if you are looking for others to help you.
Thanks again!
from ember-apollo-client.
@DevanB I think it would be enough to add a link to http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient.mutate would be enough for the moment.
However having docs like the react-apollo docs would definitely encourage more users to use ember-apollo-client 🤔
from ember-apollo-client.
Related Issues (20)
- Subscription implementation questions HOT 2
- ember install ember-apollo-client broken
- ember-simple-auth example is out of date HOT 2
- Disable "Download the Apollo DevTools for a better development experience" warning HOT 2
- TS errors due to no react present HOT 1
- Cache is updating but computed property is not. HOT 2
- ReferenceError: react is not defined HOT 3
- Question: Ember Apollo Client and file uploads HOT 1
- Error using typescript HOT 1
- Can't build app due to dependencies placement in package.json
- Add a service override environment variable
- Build error when using Embroider HOT 3
- Update watchQuery results in the next runloop
- Could not find module `@apollo/client/core` imported from `ember-apollo-client/services/apollo` HOT 1
- Out of date client.
- @defer support HOT 1
- V4 service extension / v4 fails on ember 3.28 HOT 1
- Much bigger bundle size after upgrading @apollo/client HOT 1
- Define the types of the parameters from Apollo service's most used methods
- Service implementation question HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-apollo-client.