-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Run batching queries in parallel (#176) #273
Changes from all commits
ad4ce9a
47e341f
1234541
0a7b566
3c249eb
f0127a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
GraphQLSchema, | ||
GraphQLObjectType, | ||
GraphQLString, | ||
GraphQLInt, | ||
GraphQLError, | ||
GraphQLNonNull, | ||
introspectionQuery, | ||
|
@@ -29,6 +30,17 @@ const queryType = new GraphQLObjectType({ | |
return 'it works'; | ||
}, | ||
}, | ||
testStringWithDelay: { | ||
type: GraphQLString, | ||
args: { | ||
delay: { type: new GraphQLNonNull(GraphQLInt) }, | ||
}, | ||
resolve(root, args) { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => resolve('it works'), args['delay']); | ||
}); | ||
}, | ||
}, | ||
testContext: { | ||
type: GraphQLString, | ||
resolve(_, args, context) { | ||
|
@@ -457,6 +469,29 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => { | |
}); | ||
}); | ||
|
||
it('can handle batch requests in parallel', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another potential testing strategy that doesn't require the test to take a long time is to have much shorter timeouts in the queries but to expect the part of one query after a timeout to be able to observe the effect of another query. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i thought about creating a promise and resolve it on the other query. |
||
// this test will fail due to timeout if running serially. | ||
const parallels = 100; | ||
const delayPerReq = 40; | ||
this.timeout(3000); | ||
|
||
app = createApp(); | ||
const expected = Array(parallels).fill({ | ||
data: { testStringWithDelay: 'it works' }, | ||
}); | ||
const req = request(app) | ||
.post('/graphql') | ||
.send(Array(parallels).fill({ | ||
query: `query test($delay: Int!) { testStringWithDelay(delay: $delay) }`, | ||
operationName: 'test', | ||
variables: { delay: delayPerReq }, | ||
})); | ||
return req.then((res) => { | ||
expect(res.status).to.equal(200); | ||
return expect(res.body).to.deep.equal(expected); | ||
}); | ||
}); | ||
|
||
it('clones batch context', () => { | ||
app = createApp({graphqlOptions: { | ||
schema, | ||
|
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.
How is this change related to this PR?
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.
Node 4 is much slower then Node 6.
I increase those 2 tests timeout since there is timeout after exhausting node abit..