Skip to content

Commit

Permalink
Remove the postPlanResolvers / addToPlanResolver system - use arg app…
Browse files Browse the repository at this point in the history
…lyPlan instead
  • Loading branch information
benjie committed Feb 19, 2025
1 parent 84e490d commit ca4ff34
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const PgConnectionArgOrderByPlugin: GraphileConfig.Plugin = {
graphql: { GraphQLList, GraphQLNonNull },
inflection,
} = build;
const { scope, Self, addToPlanResolver } = context;
const { scope, Self } = context;
const {
fieldName,
isPgFieldConnection,
Expand Down
7 changes: 0 additions & 7 deletions graphile-build/graphile-build/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,6 @@ declare global {
interface ContextObjectFieldsFieldArgs
extends Omit<ContextObjectFieldsField, "fieldWitHHooks"> {
scope: ScopeObjectFieldsFieldArgs;
addToPlanResolver<
_TArgs extends BaseGraphQLArguments,
TParentStep extends ExecutableStep | null,
TResultStep extends ExecutableStep,
>(
cb: PostPlanResolver<_TArgs, TParentStep, TResultStep>,
): void;
}

interface ScopeObjectFieldsFieldArgsArg extends ScopeObjectFieldsFieldArgs {
Expand Down
30 changes: 1 addition & 29 deletions graphile-build/graphile-build/src/newWithHooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,8 @@ export function makeNewWithHooks({ builder }: MakeNewWithHooksOptions): {
) as typeof resolvedFieldSpec;

resolvedFieldSpec.args = resolvedFieldSpec.args ?? {};
const postPlanResolvers: PostPlanResolver<any, any, any>[] = [];
exportNameHint(
postPlanResolvers,
`${Self.name}_${fieldName}_postPlanResolvers`,
);
const argsContext: GraphileBuild.ContextObjectFieldsFieldArgs =
{
...fieldContext,
addToPlanResolver(cb) {
postPlanResolvers.push(cb);
},
};
{ ...fieldContext };
const finalFieldSpec = {
...resolvedFieldSpec,
args: builder.applyHooks(
Expand Down Expand Up @@ -302,24 +292,6 @@ export function makeNewWithHooks({ builder }: MakeNewWithHooksOptions): {
);
}

if (postPlanResolvers.length > 0) {
const basePlan = finalFieldSpec.plan ?? defaultPlanResolver;
if (basePlan !== defaultPlanResolver) {
exportNameHint(basePlan, `${Self.name}_${fieldName}_plan`);
}
finalFieldSpec.plan = EXPORTABLE(
(basePlan, postPlanResolvers) =>
($parent, fieldArgs, info) => {
let $result = basePlan($parent, fieldArgs, info);
for (const ppr of postPlanResolvers) {
$result = ppr($result, $parent, fieldArgs, info);
}
return $result;
},
[basePlan, postPlanResolvers],
);
}

processedFields.push(finalFieldSpec);
return finalFieldSpec;
};
Expand Down

0 comments on commit ca4ff34

Please sign in to comment.