Comments (9)
➤ Leonardo Garcia Crespo commented:
@jurosh yeah the problem with that is that by design the graphql HoC works for both queries and mutations, and the decision to act as one of those is determined dynamically by inspecting the graphql document being passed in. If it has a mutation operation, then it acts as a mutation container, otherwise as a query container. This is not possible for Typescript to know in advance, which leads to these types that have everything optional. I think maybe the types could be improved a bit more so that at least the developer can specify if the types for the container should be for querying or for mutating, with a type parameter for example.
from apollo-link-state.
➤ Leonardo Garcia Crespo commented:
I'd like to add to this one that instead of data being optional, it is the results that should be optional, in the OptionProps case, TResult should have all nullable fields (for the case where they are loading).
export interface OptionProps<TProps, TResult> {
ownProps: TProps;
data: QueryProps & Partial;
mutate?: MutationFunc;
}Are you willing to accept a PR for this? Is there any caveat with this proposed change?
from apollo-link-state.
➤ Christian Hoffmeister commented:
What you call Nullable should be TypeScript's Partial I guess.
from apollo-link-state.
➤ Leonardo Garcia Crespo commented:
Yeah, duh, good call! haha will update
from apollo-link-state.
➤ Christian Hoffmeister commented:
Did look up here https://www.typescriptlang.org/docs/handbook/advanced-types.html. Actually both Nullable and Partial exist (did only know about Partial). Still if I recall correctly the unloaded props are undefined, so Partial should be the correct one. If there are now objections I would create a PR tomorrow for that.
from apollo-link-state.
➤ Jonathan Mourtada commented:
Looks as this was merged and included in version 1.4.16 but data is still optional but now with Partial ?
export type ChildProps<P, R> = P & {
data?: QueryProps & Partial;
mutate?: MutationFunc;
};https://github.com/apollographql/react-apollo/blame/3e245205097d427daaac7cb89c0f97eea78032ae/src/types.ts#L70
Edit: Saw apollographql/react-apollo#1143 (comment) now. Looks like this is the reason
from apollo-link-state.
➤ Leonardo Garcia Crespo commented:
Yeah, I think the reason it was set back to optional is that since the HOC is used for both queries and mutations, and since currently there's no way to tell Typescript how the HOC will act like, the type definitions need to allow both to be optional, since for queries you'll get data, and for mutations you'll get mutate.
from apollo-link-state.
➤ stale[bot] commented:
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!
from apollo-link-state.
➤ Jurosh commented:
@leoasis Maybe would be good to create another type for props with queries only Eg. ChildQueryProps where types would be stronger, but not optional. Otherwise it's really complicated to work with those types in components.
Also this official example doesn't work now because of optional typings https://www.apollographql.com/docs/react/features/static-typing.html#classes-vs-functions
from apollo-link-state.
Related Issues (20)
- how to query local state by Id HOT 9
- Feature Request: Add an Opt In for using Service Workers or Workers for state management
- How to pass variable from local state HOT 2
- Is clientState.resolvers required or optional?
- Apollo: Problem triggering local state mutation via componentDidMount() HOT 1
- How should I update local state after fetching remote data? HOT 1
- Cannot read property '__typename' of undefined
- Client mutation failed to update (array of objects with different shapes)
- Missing field session in {} HOT 1
- Stupid docs HOT 7
- When calling execute directly on link, resolver cache argument is undefined
- Support for custom scalars
- ⚠️ This project is being deprecated ⚠️ HOT 2
- Store function references?
- Defining fragment properties on resolvers
- How to read Data one object from array of objects from cache. HOT 1
- Slow function call to store
- Not compatible with [email protected]: Cannot find module 'graphql-anywhere/lib/async' HOT 9
- How to let Query componet only fetch cache data only in first time componet building?
- Is it possible to have computed / derived state?
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 apollo-link-state.