Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
perf(core): do not deeply resolve an input type more than once (#373)
Browse files Browse the repository at this point in the history
Relates to #310
  • Loading branch information
zazido authored and Jason Kuhrt committed Jan 1, 2019
1 parent bd44b33 commit ae1b596
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/graphqlgen/src/generators/common.spec.ts
Expand Up @@ -141,7 +141,6 @@ Array [
"B",
"D",
"C",
"D",
]
`)
})
15 changes: 12 additions & 3 deletions packages/graphqlgen/src/generators/common.ts
Expand Up @@ -239,9 +239,18 @@ export function deepResolveInputTypes(
const childTypes = type.fields
.filter(t => t.type.isInput && !seen[t.type.name])
.map(t => t.type.name)
.map(name =>
deepResolveInputTypes(inputTypesMap, name, { ...seen, [name]: true }),
)
.map(name => {
/**
* Mutate so that we track state across tree branches.
*
* Example, only visit "C" once:
* A
* ├── B ── C
* └── D ── C
*/
seen[name] = true
return deepResolveInputTypes(inputTypesMap, name, seen)
})
.reduce(concat, [])
return [typeName, ...childTypes]
} else {
Expand Down

0 comments on commit ae1b596

Please sign in to comment.