Skip to content

Commit

Permalink
fix: use option to compute path based skip/include (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi authored Apr 17, 2023
1 parent 5645871 commit 0b1070e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe("json schema creator", () => {
document
})
: (buildExecutionContext as any)(blogSchema, document);
context.options = {};
const jsonSchema = queryToJSONSchema(context);
test("json schema creation", () => {
expect(jsonSchema).toMatchSnapshot();
Expand Down Expand Up @@ -213,6 +214,7 @@ describe("JSON schema creation with abstract types", () => {
document
})
: (buildExecutionContext as any)(schema, document);
context.options = {};

const jsonSchema = queryToJSONSchema(context);
test("json schema creation", () => {
Expand Down
52 changes: 28 additions & 24 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,21 @@ function collectFieldsImpl(
* -----------------------------
* `should include`s generated for the current fieldNode
*/
fieldNode.__internalShouldIncludePath[currentPath] =
joinShouldIncludeCompilations(
fieldNode.__internalShouldIncludePath?.[currentPath] ?? "",
if (compilationContext.options.useExperimentalPathBasedSkipInclude) {
fieldNode.__internalShouldIncludePath[currentPath] =
joinShouldIncludeCompilations(
fieldNode.__internalShouldIncludePath?.[currentPath] ?? "",
previousShouldInclude,
compiledSkipInclude
);
} else {
// @deprecated
fieldNode.__internalShouldInclude = joinShouldIncludeCompilations(
fieldNode.__internalShouldInclude ?? "",
previousShouldInclude,
compiledSkipInclude
);

// @deprecated
fieldNode.__internalShouldInclude = joinShouldIncludeCompilations(
fieldNode.__internalShouldInclude ?? "",
previousShouldInclude,
compiledSkipInclude
);

}
/**
* We augment the entire subtree as the parent object's skip/include
* directives influence the child even if the child doesn't have
Expand Down Expand Up @@ -328,19 +329,22 @@ function augmentFieldNodeTree(
if (!jitFieldNode.__internalShouldIncludePath)
jitFieldNode.__internalShouldIncludePath = {};

jitFieldNode.__internalShouldIncludePath[currentPath] =
joinShouldIncludeCompilations(
parentFieldNode.__internalShouldIncludePath?.[
parentResponsePath
] ?? "",
jitFieldNode.__internalShouldIncludePath?.[currentPath] ?? ""
);

// @deprecated
jitFieldNode.__internalShouldInclude = joinShouldIncludeCompilations(
parentFieldNode.__internalShouldInclude ?? "",
jitFieldNode.__internalShouldInclude ?? ""
);
if (compilationContext.options.useExperimentalPathBasedSkipInclude) {
jitFieldNode.__internalShouldIncludePath[currentPath] =
joinShouldIncludeCompilations(
parentFieldNode.__internalShouldIncludePath?.[
parentResponsePath
] ?? "",
jitFieldNode.__internalShouldIncludePath?.[currentPath] ?? ""
);
} else {
// @deprecated
jitFieldNode.__internalShouldInclude =
joinShouldIncludeCompilations(
parentFieldNode.__internalShouldInclude ?? "",
jitFieldNode.__internalShouldInclude ?? ""
);
}
}
// go further down the query tree
for (const selection of jitFieldNode.selectionSet?.selections ?? []) {
Expand Down
26 changes: 10 additions & 16 deletions src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,25 +873,19 @@ function compileObjectType(
name
);

const oldFieldCondition =
fieldNodes
.map((it) => it.__internalShouldInclude)
.filter((it) => it)
.join(" || ") || /* if(true) - default */ "true";

const fieldCondition =
fieldNodes
.map((it) => it.__internalShouldIncludePath?.[serializedResponsePath])
.filter((it) => it)
.join(" || ") || /* if(true) - default */ "true";
const fieldCondition = context.options.useExperimentalPathBasedSkipInclude
? fieldNodes
.map((it) => it.__internalShouldIncludePath?.[serializedResponsePath])
.filter((it) => it)
.join(" || ") || /* if(true) - default */ "true"
: fieldNodes
.map((it) => it.__internalShouldInclude)
.filter((it) => it)
.join(" || ") || /* if(true) - default */ "true";

body(`
(
${
context.options.useExperimentalPathBasedSkipInclude
? fieldCondition
: oldFieldCondition
}
${fieldCondition}
)
`);

Expand Down

0 comments on commit 0b1070e

Please sign in to comment.