-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the dependencies on queries and mutations in the store from the data reducer #1845
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, this is a big improvement! Just a few suggestions.
src/core/QueryManager.ts
Outdated
@@ -1074,14 +1091,18 @@ export class QueryManager { | |||
|
|||
const extraReducers = this.getExtraReducers(); | |||
|
|||
const variablesObject = variables as Object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd - is there a mismatch between the type here and in the Redux action? I feel like we should fix that instead of casting somehow.
src/core/QueryManager.ts
Outdated
@@ -170,6 +174,8 @@ export class QueryManager { | |||
// updateQueries. | |||
private queryIdsByName: { [queryName: string]: string[] }; | |||
|
|||
private lastRequestId: { [queryName: string]: number } = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want queryId
instead of queryName
here (it doesn't actually matter what that's called but best to be accurate)
src/actions.ts
Outdated
operationName: string | null; | ||
requestId: number; | ||
lastRequestId: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked, and I don't think we need this in the action at all. As far as I can tell, APOLLO_QUERY_RESULT
actions are completely ignored if requestId < lastRequestId
, so we can just not send them. This means adding this conditional before the action is dispatch
ed.
src/core/QueryManager.ts
Outdated
updateQueries[queryId] = updateQueriesByName[queryName]; | ||
})); | ||
} | ||
const updateQueries: () => { [queryId: string]: QueryUpdate } = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this something a bit more descriptive like generateUpdateQueriesInfo
.
src/actions.ts
Outdated
@@ -88,6 +95,11 @@ export function isQueryStopAction(action: ApolloAction): action is QueryStopActi | |||
return action.type === 'APOLLO_QUERY_STOP'; | |||
} | |||
|
|||
export type QueryUpdate = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this type could have a more descriptive name, or at least a comment describing what it's for.
I'm not sure why the package lock changed - can we commit that in a separate PR rather than making it part of this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just add one comment and we're good to merge!
Don't forget to add to the change log.
src/core/QueryManager.ts
Outdated
fetchMoreForQueryId, | ||
extraReducers, | ||
}); | ||
if (requestId >= (this.lastRequestId[queryId] || 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of an odd boolean expression here. Can we add a comment explaining what it does?
CHANGELOG.md
Outdated
@@ -1,7 +1,7 @@ | |||
# Change log | |||
|
|||
### vNEXT | |||
|
|||
- Remove the dependency on the query and mutation store from the data reducer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the link to the PR as well? I also just noticed we didn't have that in a previous entry, but let's make sure to keep doing it so it's easy to find where the change was added.
I think this can be released as 1.8? It changes the format of Redux actions which I feel is enough for a minor change. Thoughts, @jbaxleyiii? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shadaj I left one comment to make sure we don't miss a possible throw, otherwise I'm good with it! Great work!
src/data/store.ts
Outdated
return; | ||
} | ||
|
||
const { query, reducer } = updateQueries[queryId]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shadaj there isn't a chance that updateQueries[queryId]
could return undefined
right? If it did, this would throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to worry about it returning undefined
, since we are only using keys from iterating over Object.keys(updateQueries)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shadaj that will only ensure that the key exists, not that the value is there :(
https://runkit.com/jbaxleyiii/595d29c0e60f6b0012bffe69
You could also something like this:
Object.keys(updateQueries).filter(id => queries[id]).forEach(....
@stubailo I think we can release it as 1.8 but maybe lets put a larger note in the changelog for anyone relying on it with custom redux work? |
22f0612
to
ce2649a
Compare
ce2649a
to
17fc938
Compare
Everything should be fixed now, but we should merge #1857 before we merge this PR. |
Depends on #1857
TODO: