Skip to content

Commit b2802f9

Browse files
authored
Don't wrapPlans() fields that use resolver emulation only (#2875)
2 parents 3d4d757 + ced4abe commit b2802f9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

.changeset/lemon-cats-greet.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"graphile-utils": patch
3+
---
4+
5+
`wrapPlans()` now refuses to wrap the plan for a field that both has no plan and
6+
either has a `resolve()` or `subscribe()` method (i.e. resolver emulation will
7+
be used). This is done by simply skipping wrapping the resolver, and emitting a
8+
warning to the console. This is a breaking fix as fields that may have
9+
previously had the default plan resolver wrapped may no longer do so, but should
10+
not impact anyone running a "pure" PostGraphile/Grafast schema (it only impacts
11+
you if you are using traditional (non-plan) resolvers, e.g. via
12+
`extendSchema()`, and you're also using `wrapPlans()` to target these same
13+
fields).

graphile-build/graphile-utils/src/makeWrapPlansPlugin.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,34 @@ export function wrapPlans<T>(
141141
if (!planWrapper) {
142142
return field;
143143
}
144-
const { plan: oldPlan = defaultPlanResolver } = field;
144+
const { plan: oldPlan, resolve, subscribe } = field;
145+
146+
if (!oldPlan) {
147+
if (resolve) {
148+
console.warn(
149+
`[WARNING]: \`wrapPlans(...)\` refusing to wrap ${Self.name}.${fieldName} since it has no plan and it has a resolver.`,
150+
);
151+
return field;
152+
} else if (subscribe) {
153+
console.warn(
154+
`[WARNING]: \`wrapPlans(...)\` refusing to wrap ${Self.name}.${fieldName} since it has no plan and it has a subscription resolver.`,
155+
);
156+
return field;
157+
} else {
158+
console.warn(
159+
`[WARNING]: \`wrapPlans(...)\` wrapping default plan resolver for ${Self.name}.${fieldName}; if resolver emulation is in use then things may go awry`,
160+
);
161+
}
162+
}
163+
145164
const typeName = Self.name;
146165
return {
147166
...field,
148167
plan: EXPORTABLE(
149168
(
150169
ExecutableStep,
151170
autoApplyFieldArgs,
171+
defaultPlanResolver,
152172
fieldName,
153173
inspect,
154174
isExecutableStep,
@@ -164,7 +184,10 @@ export function wrapPlans<T>(
164184
planParams.slice(overrideParams.length),
165185
),
166186
] as typeof planParams;
167-
const $prev = oldPlan.apply(this, args);
187+
const $prev = (oldPlan ?? defaultPlanResolver).apply(
188+
this,
189+
args,
190+
);
168191
if (!($prev instanceof ExecutableStep)) {
169192
console.error(
170193
`Wrapped a plan function at ${typeName}.${fieldName}, but that function did not return a step!\n${String(
@@ -205,6 +228,7 @@ export function wrapPlans<T>(
205228
[
206229
ExecutableStep,
207230
autoApplyFieldArgs,
231+
defaultPlanResolver,
208232
fieldName,
209233
inspect,
210234
isExecutableStep,

0 commit comments

Comments
 (0)