diff --git a/fixtures/directiveSchemas/baseTypes.graphql b/fixtures/directiveSchemas/baseTypes.graphql index d06139d..3ef5274 100644 --- a/fixtures/directiveSchemas/baseTypes.graphql +++ b/fixtures/directiveSchemas/baseTypes.graphql @@ -1,4 +1,13 @@ -type Foo @noArg { +interface BarInterface { + bar: String! +} + +interface FooInterface implements BarInterface { + bar: String! + nestedFoo: NestedFoo! @nullArg(stringArg: null) +} + +type Foo implements FooInterface @noArg { bar: String! qux: Int! nestedFoo: NestedFoo! @nullArg(stringArg: null) diff --git a/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql b/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql index 2d57ef6..aa18f8d 100644 --- a/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql +++ b/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql @@ -9,7 +9,16 @@ directive @nullArg(stringArg: String) on ENUM_VALUE | FIELD_DEFINITION | INPUT_F """The directives decorates unions.""" directive @nestedFooUnion on UNION -type Foo { +interface BarInterface { + bar: String! +} + +interface FooInterface implements BarInterface { + bar: String! + nestedFoo: NestedFoo! +} + +type Foo implements FooInterface { bar: String! qux: Int! nestedFoo: NestedFoo! diff --git a/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql b/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql index 748beab..487c2b6 100644 --- a/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql +++ b/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql @@ -15,12 +15,21 @@ enum Bar { EVERYONE } -type Foo @noArg { +interface BarInterface { + bar: String! +} + +type Foo implements FooInterface @noArg { bar: String! qux: Int! nestedFoo: NestedFoo! @nullArg(stringArg: null) } +interface FooInterface implements BarInterface { + bar: String! + nestedFoo: NestedFoo! @nullArg(stringArg: null) +} + input Input { field: String @nullArg(stringArg: "string") oldAttribute: String! @deprecated(reason: "reason") diff --git a/src/printers.ts b/src/printers.ts index 25c15b1..1c40148 100644 --- a/src/printers.ts +++ b/src/printers.ts @@ -107,22 +107,28 @@ function printScalar(type: GraphQLScalarType): string { return printDescription(type) + `scalar ${type.name}`; } -function printObject(type: GraphQLObjectType): string { + +function getImplementedInterfaces(type: GraphQLObjectType | GraphQLInterfaceType): string { const interfaces = type.getInterfaces(); const implementedInterfaces = interfaces.length ? ' implements ' + interfaces.map((i) => i.name).join(' & ') : ''; + return implementedInterfaces; +} + +function printInterface(type: GraphQLInterfaceType): string { + const implementedInterfaces = getImplementedInterfaces(type); return ( printDescription(type) + - `type ${type.name}${implementedInterfaces}` + + `interface ${type.name}${implementedInterfaces}` + printFields(type) ); } - -function printInterface(type: GraphQLInterfaceType): string { +function printObject(type: GraphQLObjectType): string { + const implementedInterfaces = getImplementedInterfaces(type); return ( printDescription(type) + - `interface ${type.name}` + + `type ${type.name}${implementedInterfaces}` + printFields(type) ); }