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

defer stream support within stitching #1941

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5b7320e
update graphql-js version to support defer/stream
yaacovCR May 2, 2021
6362145
add changeset
yaacovCR May 2, 2021
3ba3682
update delegate to support defer/stream
yaacovCR May 2, 2021
bb8b612
remove unnecessary lint message
yaacovCR May 2, 2021
ae1e1f6
update types
yaacovCR May 2, 2021
1b0f8fa
Update mock package
yaacovCR May 2, 2021
97ae0e7
Update stitch package
yaacovCR May 2, 2021
97e8e39
remove dead code
yaacovCR May 2, 2021
bc5988e
format WrapFields transform
yaacovCR May 2, 2021
04bcba5
no longer need to add __typename within transform, as will always be …
yaacovCR May 2, 2021
09d1b30
generateProxyingResolvers should optionally take a transformedSchema …
yaacovCR May 2, 2021
29f67e3
update introspectSchema types
yaacovCR May 2, 2021
0f8c63c
update tests with __typename
yaacovCR May 2, 2021
f26739b
update batch-execute package
yaacovCR May 2, 2021
9a4ce1a
remove dead type
yaacovCR May 2, 2021
aee792c
use ValueOrPromise rather than isPromise
yaacovCR May 2, 2021
2874c6c
refactor split
yaacovCR May 7, 2021
3531495
small refactor of splitResult
yaacovCR May 7, 2021
a9e946d
remove unnecessary casts
yaacovCR May 7, 2021
6609312
add missing dependency
yaacovCR May 7, 2021
0d6fe49
fix(types): a little
yaacovCR May 7, 2021
c50a819
allow more than one type of Receiver
yaacovCR May 8, 2021
336a410
when possible, update the receiver synchronously rather than requesti…
yaacovCR May 9, 2021
cbb303c
fix split
yaacovCR May 11, 2021
c083600
remove logged payloads
yaacovCR May 11, 2021
30533c6
implement mapAsyncIterator with repeaters
yaacovCR May 11, 2021
b46a255
rename split
yaacovCR May 11, 2021
1c9e321
move splitAsyncIterator to utils package
yaacovCR May 11, 2021
5dd17dd
fix rebase
yaacovCR May 16, 2021
83103bc
further refactor
yaacovCR May 16, 2021
ec4440f
rename info => parentInfo
yaacovCR May 18, 2021
e9e11d9
change Receiver to emit graphql results instead of external objects
yaacovCR May 20, 2021
1faddee
remove unused externalValueFromPatchResult
yaacovCR May 23, 2021
2153fb0
refactor =>
yaacovCR May 23, 2021
ec352cf
no longer necessary because createExternalObject creates a new object…
yaacovCR May 23, 2021
5bd77cb
append base path to errors only when creating external values
yaacovCR May 24, 2021
e84adb8
stitch new base paths to errors only when creating leaf external valu…
yaacovCR May 24, 2021
826e84b
pare down receiver algorithm
yaacovCR May 24, 2021
0fcfc4f
simplify
yaacovCR May 24, 2021
b18c428
Reproduction test case
mjbcopland May 12, 2021
cfaea06
temporarily (?) remove valuesFromResults
yaacovCR May 27, 2021
c004429
inline delegation into batch-delegate
yaacovCR May 27, 2021
489c9bf
add TODOs
yaacovCR May 27, 2021
99bda2d
Receiver refactor
yaacovCR May 29, 2021
df69614
hew more closely to repeater js implementation
yaacovCR Jun 1, 2021
97c0328
Receiver does not have to transform results
yaacovCR Jun 1, 2021
b844c3e
refactor batchDelegateToSchema
yaacovCR Jun 1, 2021
8aac856
fix types for now
yaacovCR Jun 1, 2021
3a079fc
add polyfill back
yaacovCR Jun 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/wild-mangos-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@graphql-tools/delegate': major
'@graphql-tools/mock': major
'@graphql-tools/utils': major
'@graphql-tools/wrap': major
'@graphql-tools/batch-delegate': major
'@graphql-tools/batch-execute': major
'graphql-tools': major
'@graphql-tools/stitch': major
---

defer support
28 changes: 14 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
- name: Lint
run: yarn lint
build:
name: Build on ${{matrix.os}} GraphQL v${{matrix.graphql_version}}
name: Build on ${{matrix.os}} GraphQL ${{matrix.graphql_version_or_tag}}
runs-on: ubuntu-latest
strategy:
matrix:
graphql_version: [14, 15]
graphql_version_or_tag: [experimental-stream-defer]
steps:
- name: Checkout Master
uses: actions/checkout@v2
Expand All @@ -47,23 +47,23 @@ jobs:
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-16-${{matrix.graphql_version}}-yarn-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-16-${{matrix.graphql_version_or_tag}}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-16-${{matrix.graphql_version}}-yarn
- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
${{ runner.os }}-16-${{matrix.graphql_version_or_tag}}-yarn
- name: Use GraphQL ${{matrix.graphql_version_or_tag}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version_or_tag}}
- name: Install Dependencies using Yarn
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Build
run: yarn ts:transpile
test:
name: Test on ${{matrix.os}}, Node ${{matrix.node_version}} and GraphQL v${{matrix.graphql_version}}
name: Test on ${{matrix.os}}, Node ${{matrix.node_version}} and GraphQL ${{matrix.graphql_version_or_tag}}
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest] # remove windows to speed up the tests
node_version: [10, 16]
graphql_version: [14, 15]
graphql_version_or_tag: [experimental-stream-defer]
steps:
- name: Checkout Master
uses: actions/checkout@v2
Expand All @@ -75,20 +75,20 @@ jobs:
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-yarn-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version_or_tag}}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-yarn
- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version_or_tag}}-yarn
- name: Use GraphQL ${{matrix.graphql_version_or_tag}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version_or_tag}}
- name: Install Dependencies using Yarn
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Cache Jest
uses: actions/cache@v2
with:
path: .cache/jest
key: ${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-jest-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version_or_tag}}-jest-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-jest-
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version_or_tag}}-jest-
- name: Test
run: yarn test --ci
env:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "5.0.0",
"graphql": "15.5.0",
"graphql": "15.4.0-experimental-stream-defer.1",
"graphql-helix": "1.6.1",
"graphql-subscriptions": "1.2.1",
"husky": "6.0.0",
Expand Down Expand Up @@ -93,7 +93,7 @@
]
},
"resolutions": {
"graphql": "15.5.0",
"graphql": "15.4.0-experimental-stream-defer.1",
"@changesets/apply-release-plan": "5.0.0"
}
}
81 changes: 78 additions & 3 deletions packages/batch-delegate/src/batchDelegateToSchema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,89 @@
import { BatchDelegateOptions } from './types';

import { AsyncExecutionResult, ExecutionResult, getNullableType, GraphQLList } from 'graphql';

import {
DelegationContext,
createRequestFromInfo,
externalValueFromResult,
getDelegationContext,
getDelegatingOperation,
Receiver,
} from '@graphql-tools/delegate';

import { isAsyncIterable, relocatedError } from '@graphql-tools/utils';

import { getLoader } from './getLoader';

export function batchDelegateToSchema(options: BatchDelegateOptions): any {
export async function batchDelegateToSchema(options: BatchDelegateOptions): Promise<any> {
const key = options.key;
if (key == null) {
return null;
} else if (Array.isArray(key) && !key.length) {
return [];
}
const loader = getLoader(options);
return Array.isArray(key) ? loader.loadMany(key) : loader.load(key);

const {
info,
operationName,
operation = getDelegatingOperation(info.parentType, info.schema),
fieldName = info.fieldName,
returnType = info.returnType,
selectionSet,
fieldNodes,
} = options;

if (operation !== 'query' && operation !== 'mutation') {
throw new Error(`Batch delegation not possible for operation '${operation}'.`);
}

const request = createRequestFromInfo({
info,
operation,
fieldName,
selectionSet,
fieldNodes,
operationName,
});

const delegationContext = getDelegationContext({
request,
onLocatedError: originalError => relocatedError(originalError, originalError.path.slice(1)),
...options,
operation,
fieldName,
returnType,
});

const loader = getLoader(options, request, delegationContext);

if (Array.isArray(key)) {
const results = await loader.loadMany(key);

return results.map(result =>
onResult(result, {
...delegationContext,
returnType: (getNullableType(delegationContext.returnType) as GraphQLList<any>).ofType,
})
);
}

const result = await loader.load(key);
return onResult(result, delegationContext);
}

function onResult(
result: Error | ExecutionResult | AsyncIterableIterator<AsyncExecutionResult>,
delegationContext: DelegationContext
): any {
if (result instanceof Error) {
return result;
}

if (isAsyncIterable(result)) {
const receiver = new Receiver(result, delegationContext);
return receiver.getInitialValue();
}

return externalValueFromResult(result, delegationContext);
}
31 changes: 0 additions & 31 deletions packages/batch-delegate/src/createBatchDelegateFn.ts

This file was deleted.

Loading