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

fix(middleware): Correlate responses by index when server does not re… #56

Merged
merged 1 commit into from
Nov 24, 2017

Conversation

janmeier
Copy link
Contributor

…turn ID

},
method: 'POST',
});

const req1 = mockReq(1);
const req2 = mockReq(2);
const req3 = mockReq(3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test description says duplicated ids, but the IDs were not actually duplicated :)

@@ -63,7 +101,7 @@ describe('batchMiddleware', () => {
matcher: '/graphql/batch',
response: {
status: 200,
body: [{ data: {} }, { id: 2, data: { ok: 2 } }],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to preserve the original error message - Otherwise it will hit the new path, because a response does not have an id. Alternatively I can change it to return an ID that has not been requested

@@ -174,9 +174,16 @@ function sendRequests(requestMap: BatchRequestMap, next, opts) {
throw new Error('Wrong response from server');
}

batchResponse.payload.forEach(res => {
const responseHasIds: boolean = batchResponse.payload.every(response => response.id);
if (!responseHasIds && ids.length !== batchResponse.payload.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could be worthwile to have in any case - I guess the number of responses should always be the same as the number of requests?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who knows. Any server may have bugs, and we should catch this somehow and reject with error by spec.

@janmeier
Copy link
Contributor Author

By the way, this closes #55

@nodkz nodkz merged commit 3af7e69 into relay-tools:master Nov 24, 2017
@janmeier janmeier deleted the response-id-optional branch November 24, 2017 12:12
@nodkz
Copy link
Collaborator

nodkz commented Nov 24, 2017

Awesome work! 👍
Tnx!

New package version will be published from minute to minute.

@janmeier
Copy link
Contributor Author

janmeier commented Nov 24, 2017

No problem, thanks for creating this library 🌮 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants