From 0199cca386dc8a7b10de2b9f2eafab4592a5ceec Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Mon, 31 Dec 2018 15:18:38 -0500 Subject: [PATCH] test: start coverage of core renderer module Relates to #373 --- .../graphqlgen/src/generators/common.spec.ts | 147 ++++++++++++++++++ packages/graphqlgen/src/generators/common.ts | 4 +- 2 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 packages/graphqlgen/src/generators/common.spec.ts diff --git a/packages/graphqlgen/src/generators/common.spec.ts b/packages/graphqlgen/src/generators/common.spec.ts new file mode 100644 index 00000000..27b3c2bd --- /dev/null +++ b/packages/graphqlgen/src/generators/common.spec.ts @@ -0,0 +1,147 @@ +import * as Common from './common' + +it('deepResolveInputTypes', () => { + const typeMap: Common.InputTypesMap = { + A: { + name: 'A', + type: { + name: 'A', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + }, + fields: [ + { + name: 'b', + arguments: [], + type: { + name: 'B', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + isRequired: false, + isArray: false, + }, + }, + { + name: 'c', + arguments: [], + type: { + name: 'C', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + isRequired: false, + isArray: false, + }, + }, + ], + }, + B: { + name: 'B', + type: { + name: 'B', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + }, + fields: [ + { + name: 'd', + arguments: [], + type: { + name: 'D', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + isRequired: false, + isArray: false, + }, + }, + ], + }, + C: { + name: 'C', + type: { + name: 'C', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + }, + fields: [ + { + name: 'd', + arguments: [], + type: { + name: 'D', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + isRequired: false, + isArray: false, + }, + }, + ], + }, + D: { + name: 'D', + type: { + name: 'D', + isInput: true, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: false, + isUnion: false, + }, + fields: [ + { + name: 'foo', + arguments: [], + type: { + name: 'String', + isInput: false, + isEnum: false, + isInterface: false, + isObject: false, + isScalar: true, + isUnion: false, + isRequired: false, + isArray: false, + }, + }, + ], + }, + } + + expect(Common.deepResolveInputTypes(typeMap, 'A')).toMatchInlineSnapshot(` +Array [ + "A", + "B", + "D", + "C", + "D", +] +`) +}) diff --git a/packages/graphqlgen/src/generators/common.ts b/packages/graphqlgen/src/generators/common.ts index 3a698b01..7f11148e 100644 --- a/packages/graphqlgen/src/generators/common.ts +++ b/packages/graphqlgen/src/generators/common.ts @@ -229,10 +229,10 @@ export function getTypeFromGraphQLType( return 'string' } -function deepResolveInputTypes( +export function deepResolveInputTypes( inputTypesMap: InputTypesMap, typeName: string, - seen: { [k: string]: boolean } = {}, + seen: Record = {}, ): string[] { const type = inputTypesMap[typeName] if (type) {