Skip to content
Closed
Show file tree
Hide file tree
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
43 changes: 28 additions & 15 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,14 @@ function skipTree(skip: string[]): SkipTree {
const prop = props[i];
const all = props[i + 1] === '*';

if (!propTree[prop]) {
propTree[prop] = i === s - 1 || all ? true : {};
all && i++;
}
if (prop) {
if (!propTree[prop]) {
propTree[prop] = i === s - 1 || all ? true : {};
all && i++;
}

propTree = propTree[prop] as SkipTree;
propTree = propTree[prop] as SkipTree;
}
}
}

Expand All @@ -311,9 +313,14 @@ function verifySkip(node: string, skip: SkipValue): SkipValue {
return false;
}

// true['string'] is a valid operation is JS resulting in `undefined`
if ((skip as SkipTree)[node]) {
return (skip as SkipTree)[node];
if (skip === true) {
return false;
}

const skipValue = skip[node];

if (skipValue) {
return skipValue;
}

// lookup through wildcard patterns
Expand All @@ -324,7 +331,7 @@ function verifySkip(node: string, skip: SkipValue): SkipValue {
const rx: RegExp = new RegExp(pattern.replace(RX_AST, '.*'));

if (rx.test(node)) {
nodeTree = (skip as SkipTree)[pattern];
nodeTree = (skip as SkipTree)[pattern] ?? false;

// istanbul ignore else
if (nodeTree === true) {
Expand Down Expand Up @@ -367,8 +374,10 @@ function traverse(

const name = (node as FieldNode).name.value;

if (opts.fragments[name]) {
traverse(getNodes(opts.fragments[name]), root, opts, skip);
const selection = opts.fragments[name]

if (selection) {
traverse(getNodes(selection), root, opts, skip);

continue;
}
Expand All @@ -377,13 +386,15 @@ function traverse(
const nodeSkip = verifySkip(name, skip);

if (nodeSkip !== true) {
(root as MapResult)[name] = (root as MapResult)[name] || (
const mapResult = (root as MapResult)[name] || (
nodes.length ? {} : false
);

(root as MapResult)[name] = mapResult;

nodes.length && traverse(
nodes,
(root as MapResult)[name],
mapResult,
opts,
nodeSkip,
);
Expand Down Expand Up @@ -583,8 +594,10 @@ export function fieldsProjection(

let dotName = toDotNotation(stack[0].node, j);

if (transform[dotName]) {
dotName = transform[dotName];
const transformValue = transform[dotName];

if (transformValue) {
dotName = transformValue;
}

map[dotName] = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const schema = new GraphQLSchema({
export async function exec(query: string, vars: any) {
const queryId = uuid.v4();
await graphql(schema, query, null, { queryId }, vars);
const info: GraphQLResolveInfo = resolveInfo[queryId];
const info: GraphQLResolveInfo = resolveInfo[queryId]!;
delete resolveInfo[queryId];

return info;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dom",
"es2017",
"esnext.asynciterable"
]
],
"noUncheckedIndexedAccess": true
}
}