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

remove need for separate pointer type #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
49 changes: 15 additions & 34 deletions src/stitch/compose.ts
Original file line number Diff line number Diff line change
@@ -19,15 +19,11 @@ export interface SubschemaPlanResult {
initialResult: PromiseOrValue<ExecutionResult>;
}

interface Pointer {
parent: ObjMap<unknown>;
responseKey: string | number;
}

interface Stitch {
subschemaPlan: SubschemaPlan;
target: ObjMap<unknown>;
pointer: Pointer;
parent: ObjMap<unknown>;
responseKey: string | number;
}

interface CompositionContext {
@@ -67,10 +63,8 @@ export function compose(
const stitch: Stitch = {
subschemaPlan,
target: data,
pointer: {
parent: context as unknown as ObjMap<unknown>,
responseKey: 'data',
},
parent: context as unknown as ObjMap<unknown>,
responseKey: 'data',
};
handleMaybeAsyncResult(context, stitch, initialResult);
}
@@ -139,11 +133,7 @@ function handleResult(
context.errors.push(...result.errors);
}

const {
subschemaPlan,
target,
pointer: { parent, responseKey },
} = stitch;
const { subschemaPlan, target, parent, responseKey } = stitch;

if (parent[responseKey] === null) {
return;
@@ -177,10 +167,8 @@ function walkStitchPlans(
collectPossibleListStitches(
context,
stitchMap,
{
parent: target,
responseKey,
},
target,
responseKey,
stitchPlan,
);
}
@@ -190,36 +178,28 @@ function walkStitchPlans(
function collectPossibleListStitches(
context: CompositionContext,
stitchMap: AccumulatorMap<Subschema, Stitch>,
pointer: Pointer,
parent: ObjMap<unknown>,
responseKey: string | number,
stitchPlan: StitchPlan,
): void {
const { parent, responseKey } = pointer;
const target = parent[responseKey] as ObjMap<unknown>;
if (Array.isArray(target)) {
for (let i = 0; i < target.length; i++) {
collectStitches(
context,
stitchMap,
{
parent: target,
responseKey: i,
},
stitchPlan,
);
collectStitches(context, stitchMap, target, i, stitchPlan);
}
return;
}

collectStitches(context, stitchMap, pointer, stitchPlan);
collectStitches(context, stitchMap, parent, responseKey, stitchPlan);
}

function collectStitches(
context: CompositionContext,
stitchMap: AccumulatorMap<Subschema, Stitch>,
pointer: Pointer,
parent: ObjMap<unknown>,
responseKey: string | number,
stitchPlan: StitchPlan,
): void {
const { parent, responseKey } = pointer;
const target = parent[responseKey] as ObjMap<unknown>;

const newTarget = Object.create(null);
@@ -255,7 +235,8 @@ function collectStitches(
for (const subschemaPlan of fieldPlan.subschemaPlans) {
const stitch: Stitch = {
subschemaPlan,
pointer,
parent,
responseKey,
target: newTarget,
};
stitchMap.add(subschemaPlan.toSubschema, stitch);