-
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
incremental: subsequent result records should not store parent references #3929
Merged
Conversation
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
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋 Supported commandsPlease post this commands in separate comments and only one per comment:
|
…nces as memory then cannot be freed
yaacovCR
force-pushed
the
free-parent
branch
3 times, most recently
from
July 3, 2023 12:28
0694bab
to
8371586
Compare
as then memory for the result record tree cannot be freed
robrichard
approved these changes
Jul 5, 2023
yaacovCR
added a commit
that referenced
this pull request
Aug 18, 2023
extracted from #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`
sakesun
pushed a commit
to sakesun/graphql-js
that referenced
this pull request
Sep 1, 2023
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`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
as memory then cannot be freed
This affects both the existing branching executor on main as well as the non-branching, deduplicated version in #3886
We want to ensure that after an incremental result is sent to the client, no subsequent results reference this result so that garbage collection can free the memory associated with the result. To effect this, two changes are required: