Skip to content

Commit

Permalink
Merge 50e0645 into e66c2aa
Browse files Browse the repository at this point in the history
  • Loading branch information
tafelnl committed Aug 23, 2022
2 parents e66c2aa + 50e0645 commit 57c6b87
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
43 changes: 28 additions & 15 deletions index.ts
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
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
Expand Up @@ -17,6 +17,7 @@
"dom",
"es2017",
"esnext.asynciterable"
]
],
"noUncheckedIndexedAccess": true
}
}

0 comments on commit 57c6b87

Please sign in to comment.