@graphql-tools/delegate
Advanced tools
Comparing version 10.0.18-alpha-20240807141317-3efbf2deab26a368a29197eede202b3b1d57a39b to 10.0.18-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4
@@ -60,3 +60,4 @@ "use strict"; | ||
} | ||
const rootFieldName = targetFieldName ?? fieldNodes?.[0]?.name.value; | ||
const fieldNode = fieldNodes?.[0]; | ||
const rootFieldName = targetFieldName ?? fieldNode?.name.value; | ||
if (rootFieldName === undefined) { | ||
@@ -73,2 +74,3 @@ throw new Error(`Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`); | ||
selectionSet: newSelectionSet, | ||
directives: fieldNode?.directives, | ||
}; | ||
@@ -75,0 +77,0 @@ const operationName = targetOperationName |
@@ -8,2 +8,3 @@ "use strict"; | ||
const utils_1 = require("@graphql-tools/utils"); | ||
const repeater_1 = require("@repeaterjs/repeater"); | ||
const applySchemaTransforms_js_1 = require("./applySchemaTransforms.js"); | ||
@@ -57,5 +58,42 @@ const createRequest_js_1 = require("./createRequest.js"); | ||
if ((0, utils_1.isAsyncIterable)(executorResult)) { | ||
const iterator = executorResult[Symbol.asyncIterator](); | ||
// "subscribe" to the subscription result and map the result through the transforms | ||
return (0, utils_1.mapAsyncIterator)(iterator, result => transformer.transformResult(result)); | ||
// This might be a stream | ||
if (delegationContext.operation === 'query' && (0, graphql_1.isListType)(delegationContext.returnType)) { | ||
return new repeater_1.Repeater(async (push, stop) => { | ||
const pushed = new WeakSet(); | ||
let stopped = false; | ||
stop.finally(() => { | ||
stopped = true; | ||
}); | ||
try { | ||
for await (const result of executorResult) { | ||
if (stopped) { | ||
break; | ||
} | ||
const transformedResult = await transformer.transformResult(result); | ||
// @stream needs to get the results one by one | ||
if (Array.isArray(transformedResult)) { | ||
for (const individualResult$ of transformedResult) { | ||
if (stopped) { | ||
break; | ||
} | ||
const individualResult = await individualResult$; | ||
// Avoid pushing the same result multiple times | ||
if (!pushed.has(individualResult)) { | ||
pushed.add(individualResult); | ||
await push(individualResult); | ||
} | ||
} | ||
} | ||
else { | ||
await push(await transformedResult); | ||
} | ||
} | ||
stop(); | ||
} | ||
catch (error) { | ||
stop(error); | ||
} | ||
}); | ||
} | ||
return (0, utils_1.mapAsyncIterator)(executorResult, result => transformer.transformResult(result)); | ||
} | ||
@@ -62,0 +100,0 @@ return transformer.transformResult(executorResult); |
@@ -56,3 +56,4 @@ import { Kind, typeFromAST, } from 'graphql'; | ||
} | ||
const rootFieldName = targetFieldName ?? fieldNodes?.[0]?.name.value; | ||
const fieldNode = fieldNodes?.[0]; | ||
const rootFieldName = targetFieldName ?? fieldNode?.name.value; | ||
if (rootFieldName === undefined) { | ||
@@ -69,2 +70,3 @@ throw new Error(`Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`); | ||
selectionSet: newSelectionSet, | ||
directives: fieldNode?.directives, | ||
}; | ||
@@ -71,0 +73,0 @@ const operationName = targetOperationName |
@@ -1,5 +0,6 @@ | ||
import { validate, } from 'graphql'; | ||
import { isListType, validate, } from 'graphql'; | ||
import { getBatchingExecutor } from '@graphql-tools/batch-execute'; | ||
import { normalizedExecutor } from '@graphql-tools/executor'; | ||
import { getDefinedRootType, getOperationASTFromRequest, isAsyncIterable, isPromise, mapAsyncIterator, memoize1, } from '@graphql-tools/utils'; | ||
import { Repeater } from '@repeaterjs/repeater'; | ||
import { applySchemaTransforms } from './applySchemaTransforms.js'; | ||
@@ -52,5 +53,42 @@ import { createRequest, getDelegatingOperation } from './createRequest.js'; | ||
if (isAsyncIterable(executorResult)) { | ||
const iterator = executorResult[Symbol.asyncIterator](); | ||
// "subscribe" to the subscription result and map the result through the transforms | ||
return mapAsyncIterator(iterator, result => transformer.transformResult(result)); | ||
// This might be a stream | ||
if (delegationContext.operation === 'query' && isListType(delegationContext.returnType)) { | ||
return new Repeater(async (push, stop) => { | ||
const pushed = new WeakSet(); | ||
let stopped = false; | ||
stop.finally(() => { | ||
stopped = true; | ||
}); | ||
try { | ||
for await (const result of executorResult) { | ||
if (stopped) { | ||
break; | ||
} | ||
const transformedResult = await transformer.transformResult(result); | ||
// @stream needs to get the results one by one | ||
if (Array.isArray(transformedResult)) { | ||
for (const individualResult$ of transformedResult) { | ||
if (stopped) { | ||
break; | ||
} | ||
const individualResult = await individualResult$; | ||
// Avoid pushing the same result multiple times | ||
if (!pushed.has(individualResult)) { | ||
pushed.add(individualResult); | ||
await push(individualResult); | ||
} | ||
} | ||
} | ||
else { | ||
await push(await transformedResult); | ||
} | ||
} | ||
stop(); | ||
} | ||
catch (error) { | ||
stop(error); | ||
} | ||
}); | ||
} | ||
return mapAsyncIterator(executorResult, result => transformer.transformResult(result)); | ||
} | ||
@@ -57,0 +95,0 @@ return transformer.transformResult(executorResult); |
{ | ||
"name": "@graphql-tools/delegate", | ||
"version": "10.0.18-alpha-20240807141317-3efbf2deab26a368a29197eede202b3b1d57a39b", | ||
"version": "10.0.18-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -11,5 +11,6 @@ "sideEffects": false, | ||
"@graphql-tools/batch-execute": "^9.0.4", | ||
"@graphql-tools/executor": "^1.3.0", | ||
"@graphql-tools/executor": "1.3.1-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4", | ||
"@graphql-tools/schema": "^10.0.4", | ||
"@graphql-tools/utils": "^10.2.3", | ||
"@graphql-tools/utils": "10.3.4-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4", | ||
"@repeaterjs/repeater": "^3.0.6", | ||
"dataloader": "^2.2.2", | ||
@@ -16,0 +17,0 @@ "tslib": "^2.5.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232068
4587
8
+ Added@repeaterjs/repeater@^3.0.6
+ Added@graphql-tools/executor@1.3.1-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4(transitive)
+ Added@graphql-tools/utils@10.3.4-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4(transitive)
- Removed@graphql-tools/executor@1.3.1(transitive)
Updated@graphql-tools/executor@1.3.1-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4
Updated@graphql-tools/utils@10.3.4-alpha-20240807152423-200dbd3752cf6ffce464f6da92cdb9894ab8e5e4