-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(federation/stitch/delegate): handle complex nested keys (#6150)
* fix(federation/stitch/delegate): handle complex nested keys * Remove the need of interval * Better comment and remove anys * Better comment and remove anys * Fix * Refactor * Go * Remove anys * f
- Loading branch information
Showing
8 changed files
with
523 additions
and
9 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,9 @@ | ||
--- | ||
"@graphql-tools/delegate": patch | ||
"@graphql-tools/stitch": patch | ||
--- | ||
|
||
If there are some fields depending on a nested type resolution, wait until it gets resolved then resolve the rest. | ||
|
||
See packages/federation/test/fixtures/complex-entity-call example for more details. | ||
You can see `ProductList` needs some fields from `Product` to resolve `first` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { FieldNode } from 'graphql'; | ||
import { Subschema } from './Subschema.js'; | ||
import { DelegationPlanBuilder, ExternalObject } from './types.js'; | ||
|
||
export interface Deferred<T = unknown> { | ||
promise: Promise<T>; | ||
resolve: (value: T) => void; | ||
reject: (error: unknown) => void; | ||
} | ||
|
||
export function createDeferred<T>(): Deferred<T> { | ||
let resolve: (value: T) => void; | ||
let reject: (error: unknown) => void; | ||
const promise = new Promise<T>((_resolve, _reject) => { | ||
resolve = _resolve; | ||
reject = _reject; | ||
}); | ||
return { promise, resolve: resolve!, reject: reject! }; | ||
} | ||
|
||
export interface DelegationPlanLeftOver { | ||
unproxiableFieldNodes: Array<FieldNode>; | ||
nonProxiableSubschemas: Array<Subschema>; | ||
missingFieldsParentMap: Map<ExternalObject, Array<FieldNode>>; | ||
missingFieldsParentDeferredMap: Map<ExternalObject, Map<string, Deferred>>; | ||
} | ||
export const leftOverByDelegationPlan = new WeakMap< | ||
ReturnType<DelegationPlanBuilder>, | ||
DelegationPlanLeftOver | ||
>(); | ||
export const PLAN_LEFT_OVER = Symbol('PLAN_LEFT_OVER'); | ||
export function getPlanLeftOverFromParent(parent: unknown): DelegationPlanLeftOver | undefined { | ||
if (parent != null && typeof parent === 'object') { | ||
return parent[PLAN_LEFT_OVER]; | ||
} | ||
} |
Oops, something went wrong.