Comments (11)
results
is a Vulcan specific shortcut (btw in NPM version I renamed it documents
for consistency with mutations) so we are free to implement whatever default behaviour we want, no need for an option, and I think what you proposed is the best approach as it prevents a breaking change in Vulcan.
People can still access the default data
object from Apollo if they want the default behaviour.
from vulcan.
Thank you for bringing this to our attention. I say we upgrade to @apollo/[email protected]
and try the suggested change to multi2.js
. I would be happy to look at multi.js
as well.
from vulcan.
Seems beta.10
is latest; should work, too. And is there a better variable name than 'existingData'. Probably, I didn't think about that very long! Anyway, my two-repo install seems to be working fine with these two changes.
from vulcan.
If that's just a matter of waiting Apollo to update you can probably quickfix in your codebase and let them fix it. Is there an action required from Vulcan in the long run?
from vulcan.
The Apollo breaking change is intentional and probably won't be fixed, in the sense of reverted to previous behavior, so I think Vulcan needs to change its codebase. I do not yet know if the suggested fix from Apollo comments (data ?? previousData
) is the change for Vulcan to make in the long run, however.
from vulcan.
Ok makes sense, I'll check that. In the meantime you can implement the "data/previousData" stuff locally with useState
.
I'll do a big pass on all tickets when the NPM version is a bit more advanced (it is easier to test so I am more productive than with Meteor).
from vulcan.
In the meantime you can implement the "data/previousData" stuff locally with useState.
@eric-burel I am sorry, maybe I misunderstand what you are suggesting, but that would require changes in 30+ components in my own codebase and would be a big setback to productivity.
from vulcan.
Yeah makes sense indeed. I would be happy to merge the proposed change asap, it sounds relevant to me.
from vulcan.
What if we create a new setting acceptPossiblyStaleDataFromApollo
? It defaults to true
so that nobody has to set it unless they know the complexities of this issue. It tells multi and multi2 (and perhaps others) to use data ?? previousData
if the setting is true
.
from vulcan.
Hey all,
I was just wondering if you solved this, and if you did, what implementation did you use?
We ran into the same issue and luckily we already had a custom hook useSafeQuery
we were using for queries that throws errors for our error boundaries. Since every one of our queries was already using this we created a custom hook to persist the data and implemented that in our existing hook.
In the interest of avoiding the beta release of Apollo, we chose to store the data in useState
and only update it when loading
is false
.
We flagged it with a custom option called clearPreviousDataOnLoad
which defaults to false
, this way we didn’t have to update a single component that depends on it, and if we wanted the functionality we can simply call it like this.
const { data } = useSafeQuery(query, { clearPreviousDataOnLoad: true });
It works great but I’m just curious what other people are using to get around this. I feel like we got lucky that we already had useQuery
wrapped in a custom hook.
from vulcan.
I'm using oldschool react classes, so keep the results in component state. Then I check and update the results in componentDidUpdate
, and render from the state's copy:
constructor(props) {
super(props)
this.state = {
results: props.results
}
}
componentDidUpdate(prevProps, prevState) {
if (this.props.results && (this.props.results != prevProps.results)) {
if (this.props.results.length > 0) {
this.setState({
results: this.props.results
})
}
}
}
render() {
<>
{this.state.results && this.state.results.map(user => {
return (
<ProfileCard user={user} />
);
})
}
</>
}
Then showing loading state based on whether there are results:
{(!this.props.results && this.props.results!==0) && 'Loading...'}
It's not ideal but does the trick for now
from vulcan.
Related Issues (20)
- Input filter operator _nin is not yet implemented HOT 7
- Support "reverse belongsTo" relations HOT 1
- Migrate cache to Apollo v3 HOT 2
- Renaming Material UI base form controls HOT 12
- Cannot use SmartForm for creating new documents SmartForm.submitForm
- Smartform shows delete button regardless of collection.permissions.canDelete HOT 3
- RTL support for UI by adding top level class in HTML HOT 4
- Add more flexible low level GraphQL checks HOT 2
- objectSpread2 error after running unit test HOT 2
- Nested Schema document update not working HOT 2
- How do we coordinate work among Vulcan contributors? HOT 1
- useCookies is not a function or its return value is not iterable HOT 2
- I can't run the project Vulcan(Lubuntu) HOT 8
- collection.addField not working if schema is simpl-schema HOT 3
- Relations hasMany bug. HOT 12
- Duplicate Item with withMulti HOT 4
- Add className to FormComponentLoader
- Attempting to implement multiple interfaces on a type causes an error HOT 3
- Error: Cannot find module '@graphql-tools/utils'
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 vulcan.