-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support returning async iterables from resolver functions (#2712)
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com> support async benchmark tests add benchmark tests for list fields add test for error from completeValue in AsyncIterable resolver change execute implementation for async iterable resolvers correctly handle promises returned by completeValue in async iterable resovlers
- Loading branch information
1 parent
4e722a8
commit b137dba
Showing
6 changed files
with
293 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const { parse } = require('graphql/language/parser.js'); | ||
const { execute } = require('graphql/execution/execute.js'); | ||
const { buildSchema } = require('graphql/utilities/buildASTSchema.js'); | ||
|
||
const schema = buildSchema('type Query { listField: [String] }'); | ||
const document = parse('{ listField }'); | ||
|
||
function listField() { | ||
const results = []; | ||
for (let index = 0; index < 100000; index++) { | ||
results.push(Promise.resolve(index)); | ||
} | ||
return results; | ||
} | ||
|
||
module.exports = { | ||
name: 'Execute Asynchronous List Field', | ||
count: 10, | ||
async measure() { | ||
await execute({ | ||
schema, | ||
document, | ||
rootValue: { listField }, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const { parse } = require('graphql/language/parser.js'); | ||
const { execute } = require('graphql/execution/execute.js'); | ||
const { buildSchema } = require('graphql/utilities/buildASTSchema.js'); | ||
|
||
const schema = buildSchema('type Query { listField: [String] }'); | ||
const document = parse('{ listField }'); | ||
|
||
async function* listField() { | ||
for (let index = 0; index < 100000; index++) { | ||
yield index; | ||
} | ||
} | ||
|
||
module.exports = { | ||
name: 'Execute Async Iterable List Field', | ||
count: 10, | ||
async measure() { | ||
await execute({ | ||
schema, | ||
document, | ||
rootValue: { listField }, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const { parse } = require('graphql/language/parser.js'); | ||
const { execute } = require('graphql/execution/execute.js'); | ||
const { buildSchema } = require('graphql/utilities/buildASTSchema.js'); | ||
|
||
const schema = buildSchema('type Query { listField: [String] }'); | ||
const document = parse('{ listField }'); | ||
|
||
function listField() { | ||
const results = []; | ||
for (let index = 0; index < 100000; index++) { | ||
results.push(index); | ||
} | ||
return results; | ||
} | ||
|
||
module.exports = { | ||
name: 'Execute Synchronous List Field', | ||
count: 10, | ||
async measure() { | ||
await execute({ | ||
schema, | ||
document, | ||
rootValue: { listField }, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters