Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 071c274

Browse files
machi1990wtrocki
authored andcommitted
Revert "refactor: avoid creating a new context object when adding options"
This reverts commit c85634a.
1 parent 8451a79 commit 071c274

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

packages/graphback-codegen-schema/src/SchemaCRUDPlugin.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,12 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
441441
}
442442

443443
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
444-
context.graphback.options = { selectedFields };
444+
const graphback = {
445+
services: context.graphback.services,
446+
options: { selectedFields }
447+
};
445448

446-
return context.graphback.services[modelName].create(args.input, context);
449+
return context.graphback.services[modelName].create(args.input, {...context, graphback});
447450
}
448451
}
449452

@@ -463,9 +466,12 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
463466
}
464467

465468
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
466-
context.graphback.options = { selectedFields };
469+
const graphback = {
470+
services: context.graphback.services,
471+
options: { selectedFields }
472+
};
467473

468-
return context.graphback.services[modelName].update(args.input, context)
474+
return context.graphback.services[modelName].update(args.input, {...context, graphback})
469475
}
470476
}
471477

@@ -485,9 +491,12 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
485491
}
486492

487493
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
488-
context.graphback.options = { selectedFields };
494+
const graphback = {
495+
services: context.graphback.services,
496+
options: { selectedFields }
497+
};
489498

490-
return context.graphback.services[modelName].delete(args.input, context)
499+
return context.graphback.services[modelName].delete(args.input, {...context, graphback})
491500
}
492501
}
493502

@@ -502,15 +511,15 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
502511
const modelName = modelType.name;
503512
const findField = getFieldName(modelName, GraphbackOperationType.FIND);
504513

505-
queryObj[findField] = (_: any, args: any, context: GraphbackContext, info: GraphQLResolveInfo ) => {
506-
if (!context.graphback || !context.graphback.services || !context.graphback.services[modelName]) {
507-
throw new Error(`Missing service for ${modelName}`);
508-
}
514+
queryObj[findField] = async (_: any, args: any, context: GraphbackContext, info: GraphQLResolveInfo ) => {
509515
const selectedFields = getSelectedFieldsFromResolverInfo(info, model, "items");
510516
const count = getSelectedFieldsFromResolverInfo(info, model).some((field: string ) => field === "count");
511-
context.graphback.options = { selectedFields, aggregations: { count } };
517+
const graphback = {
518+
services: context.graphback.services,
519+
options: { selectedFields, aggregations: { count } }
520+
};
512521

513-
return context.graphback.services[modelName].findBy(args.filter, context, args.orderBy, args.page)
522+
return context.graphback.services[modelName].findBy(args.filter, {...context, graphback}, args.orderBy, args.page)
514523
}
515524
}
516525

@@ -533,9 +542,12 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
533542
}
534543

535544
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
536-
context.graphback.options = { selectedFields };
545+
const graphback = {
546+
services: context.graphback.services,
547+
options: { selectedFields }
548+
};
537549

538-
return context.graphback.services[modelName].findOne({ [primaryKeyLabel]: args.id }, context)
550+
return context.graphback.services[modelName].findOne({ [primaryKeyLabel]: args.id }, {...context, graphback})
539551
}
540552
}
541553

@@ -622,13 +634,16 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
622634

623635
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
624636
selectedFields.push(relationship.relationForeignKey);
625-
context.graphback.options = { selectedFields };
637+
const graphback = {
638+
services: context.graphback.services,
639+
options: { selectedFields }
640+
};
626641

627642
return context.graphback.services[modelName].batchLoadData(
628643
relationship.relationForeignKey,
629644
parent[relationIdField.name],
630645
args.filter,
631-
context
646+
{...context, graphback}
632647
);
633648
}
634649
}
@@ -652,9 +667,12 @@ export class SchemaCRUDPlugin extends GraphbackPlugin {
652667
}
653668

654669
const selectedFields = getSelectedFieldsFromResolverInfo(info, model);
655-
context.graphback.options = { selectedFields };
670+
const graphback = {
671+
services: context.graphback.services,
672+
options: { selectedFields }
673+
};
656674

657-
return context.graphback.services[modelName].findOne({ [relationIdField.name]: parent[relationship.relationForeignKey] }, context);
675+
return context.graphback.services[modelName].findOne({ [relationIdField.name]: parent[relationship.relationForeignKey] }, {...context, graphback});
658676
}
659677
}
660678

packages/graphback-datasync/src/DataSyncPlugin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ export class DataSyncPlugin extends GraphbackPlugin {
140140
}
141141

142142
const selectedFields = getSelectedFieldsFromResolverInfo(info, model, "items");
143-
context.graphback.options = { selectedFields };
143+
const graphback = {
144+
services: context.graphback.services,
145+
options: { selectedFields }
146+
};
144147

145-
return dataSyncService.sync(args.lastSync, context, args.filter);
148+
return dataSyncService.sync(args.lastSync, {...context, graphback }, args.filter);
146149
}
147150
}
148151

0 commit comments

Comments
 (0)