-
-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor externalObject internals into separate file add tests from #2951 and fix them by reworking batch delegation buildDelegationPlan can be used to calculate the rounds of delegation necessary to completely merge an object given the stitching metadata stored within the schema and a given set of fieldNodes TODO: change buildDelegationPlan function to method on MergedTypeInfo as class? move back to stitch package?
- Loading branch information
Showing
38 changed files
with
1,482 additions
and
905 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@graphql-tools/batch-delegate': major | ||
'@graphql-tools/delegate': major | ||
'@graphql-tools/stitch': major | ||
'@graphql-tools/stitching-directives': major | ||
'@graphql-tools/utils': major | ||
'@graphql-tools/wrap': major | ||
--- | ||
|
||
use lazy query planner |
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 |
---|---|---|
@@ -1,14 +1,60 @@ | ||
import { BatchDelegateOptions } from './types'; | ||
|
||
import { getNullableType, GraphQLError, GraphQLList } from 'graphql'; | ||
|
||
import { externalValueFromResult } from '@graphql-tools/delegate'; | ||
import { relocatedError } from '@graphql-tools/utils'; | ||
|
||
import { getLoader } from './getLoader'; | ||
|
||
export function batchDelegateToSchema<TContext = any>(options: BatchDelegateOptions<TContext>): any { | ||
export async function batchDelegateToSchema<TContext = any>(options: BatchDelegateOptions<TContext>): Promise<any> { | ||
const key = options.key; | ||
if (key == null) { | ||
return null; | ||
} else if (Array.isArray(key) && !key.length) { | ||
return []; | ||
} | ||
|
||
const { | ||
schema, | ||
info, | ||
fieldName = info.fieldName, | ||
returnType = info.returnType, | ||
context, | ||
onLocatedError = (originalError: GraphQLError) => | ||
relocatedError(originalError, originalError.path ? originalError.path.slice(1) : []), | ||
} = options; | ||
|
||
const loader = getLoader(options); | ||
return Array.isArray(key) ? loader.loadMany(key) : loader.load(key); | ||
|
||
if (Array.isArray(key)) { | ||
const results = await loader.loadMany(key); | ||
|
||
return results.map(result => | ||
result instanceof Error | ||
? result | ||
: externalValueFromResult({ | ||
result, | ||
schema, | ||
info, | ||
context, | ||
fieldName, | ||
returnType: (getNullableType(returnType) as GraphQLList<any>).ofType, | ||
onLocatedError, | ||
}) | ||
); | ||
} | ||
|
||
const result = await loader.load(key); | ||
return result instanceof Error | ||
? result | ||
: externalValueFromResult({ | ||
result, | ||
schema, | ||
info, | ||
context, | ||
fieldName, | ||
returnType, | ||
onLocatedError, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './batchDelegateToSchema'; | ||
export * from './createBatchDelegateFn'; | ||
|
||
export * from './types'; |
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.