forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
incremental publisher should handle all response building (graphql#3930)
extracted from graphql#3929 the publisher itself can determine whether to return a single result or the initial result + stream the only desired change is to replace the following code block with the below: [FROM:](https://github.com/graphql/graphql-js/blob/fae5da500bad94c39a7ecd77a4c4361b58d6d2da/src/execution/execute.ts#L293-L340) ```ts const incrementalPublisher = exeContext.incrementalPublisher; const initialResultRecord = incrementalPublisher.prepareInitialResultRecord(); try { const result = executeOperation(exeContext, initialResultRecord); if (isPromise(result)) { return result.then( (data) => { const errors = incrementalPublisher.getInitialErrors(initialResultRecord); const initialResult = buildResponse(data, errors); incrementalPublisher.publishInitial(initialResultRecord); if (incrementalPublisher.hasNext()) { return { initialResult: { ...initialResult, hasNext: true, }, subsequentResults: incrementalPublisher.subscribe(), }; } return initialResult; }, (error) => { incrementalPublisher.addFieldError(initialResultRecord, error); const errors = incrementalPublisher.getInitialErrors(initialResultRecord); return buildResponse(null, errors); }, ); } const initialResult = buildResponse(result, initialResultRecord.errors); incrementalPublisher.publishInitial(initialResultRecord); if (incrementalPublisher.hasNext()) { return { initialResult: { ...initialResult, hasNext: true, }, subsequentResults: incrementalPublisher.subscribe(), }; } return initialResult; } catch (error) { incrementalPublisher.addFieldError(initialResultRecord, error); const errors = incrementalPublisher.getInitialErrors(initialResultRecord); return buildResponse(null, errors); } } ``` [TO:](https://github.com/yaacovCR/graphql-executor/blob/598608e8d8b23bc527dd73283b477997305afd58/src/execution/execute.ts#L234-L250): ```ts const incrementalPublisher = exeContext.incrementalPublisher; const initialResultRecord = incrementalPublisher.prepareInitialResultRecord(); try { const data = executeOperation(exeContext, initialResultRecord); if (isPromise(data)) { return data.then( (resolved) => incrementalPublisher.buildDataResponse(initialResultRecord, resolved), (error) => incrementalPublisher.buildErrorResponse(initialResultRecord, error), ); } return incrementalPublisher.buildDataResponse(initialResultRecord, data); } catch (error) { return incrementalPublisher.buildErrorResponse(initialResultRecord, error); } ``` Supporting changes are required: 1. some existing public methods no longer are required to be public and so are made private (or removed entirely!), with lint rules forcing the reordering of existing methods 2. to prevent cyclic type dependencies (not strictly necessary, but still!), types are moved from `execute.ts` to `IncrementalPublisher.ts`
- Loading branch information
Showing
10 changed files
with
190 additions
and
215 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
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
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
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
Oops, something went wrong.