diff --git a/argo-js/test/wire.test.ts b/argo-js/test/wire.test.ts index 30ae231..cb12323 100644 --- a/argo-js/test/wire.test.ts +++ b/argo-js/test/wire.test.ts @@ -128,3 +128,66 @@ test('Fragment with mergeable scalars', () => { const t = new Typer(schema, query).dataWireType() expect(t).toHaveProperty('fields[0].of.of.fields[0].name', 'name') }) + +test('Fragment with mergeable records', () => { + const schema = buildSchema(` + type Query { + hero: Character + } + + interface Character { id: ID! } + + type Droid implements Character { + id: ID! + properties: DroidProperties! + } + type DroidProperties { + x: Int! + y: String! + } + type Human implements Character { + id: ID! + properties: HumanProperties! + } + type HumanProperties { + x: Int! + z: String! + } + `) + + const mergeQuery = parse(` + query { + hero { + ... on Character { id } + ... on Droid { + id + properties { + x + y + } + } + ... on Human { + id + properties { + x + z + } + } + } + }`) + + const prettyWireType = (query: DocumentNode): string => Wire.print(new Typer(schema, query).dataWireType()) + + console.log(JSON.stringify(new Typer(schema, mergeQuery).dataWireType(), null, 2)) + + expect(prettyWireType(mergeQuery)).toEqual(`{ + hero: { + id?: STRING + properties?: { + x: VARINT{Int} + y?: STRING + z?: STRING + } + }? +}`) +})