Skip to content
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

Merged
merged 3 commits into from
Jul 7, 2017

Conversation

shadaj
Copy link
Contributor

@shadaj shadaj commented Jun 30, 2017

Depends on #1857

TODO:

  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change

Copy link
Contributor

@stubailo stubailo left a 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.

@@ -1074,14 +1091,18 @@ export class QueryManager {

const extraReducers = this.getExtraReducers();

const variablesObject = variables as Object;
Copy link
Contributor

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.

@@ -170,6 +174,8 @@ export class QueryManager {
// updateQueries.
private queryIdsByName: { [queryName: string]: string[] };

private lastRequestId: { [queryName: string]: number } = {};
Copy link
Contributor

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;
Copy link
Contributor

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 dispatched.

updateQueries[queryId] = updateQueriesByName[queryName];
}));
}
const updateQueries: () => { [queryId: string]: QueryUpdate } = () => {
Copy link
Contributor

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 = {
Copy link
Contributor

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.

@stubailo
Copy link
Contributor

stubailo commented Jul 3, 2017

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?

@shadaj shadaj changed the title Remove the dependencies on queries in the store from the data resolver Remove the dependencies on queries and mutations in the store from the data resolver Jul 3, 2017
Copy link
Contributor

@stubailo stubailo left a 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.

fetchMoreForQueryId,
extraReducers,
});
if (requestId >= (this.lastRequestId[queryId] || 1)) {
Copy link
Contributor

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
Copy link
Contributor

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.

@stubailo
Copy link
Contributor

stubailo commented Jul 5, 2017

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?

@jbaxleyiii jbaxleyiii self-requested a review July 5, 2017 16:00
Copy link
Contributor

@jbaxleyiii jbaxleyiii left a 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!

return;
}

const { query, reducer } = updateQueries[queryId];
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

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(....

@jbaxleyiii
Copy link
Contributor

@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?

@shadaj shadaj force-pushed the data-reducer-no-queries branch 2 times, most recently from 22f0612 to ce2649a Compare July 5, 2017 19:12
@shadaj shadaj force-pushed the data-reducer-no-queries branch from ce2649a to 17fc938 Compare July 5, 2017 20:26
@shadaj
Copy link
Contributor Author

shadaj commented Jul 5, 2017

Everything should be fixed now, but we should merge #1857 before we merge this PR.

@jbaxleyiii
Copy link
Contributor

@shadaj @stubailo this will be in 1.8 👍

@jbaxleyiii jbaxleyiii merged commit de7adfe into master Jul 7, 2017
@jbaxleyiii jbaxleyiii deleted the data-reducer-no-queries branch July 7, 2017 17:19
@stubailo stubailo changed the title Remove the dependencies on queries and mutations in the store from the data resolver Remove the dependencies on queries and mutations in the store from the data reducer Jul 7, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants