Skip to content

Support interfaces implmenting interfaces when --includeDirectives is… #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion fixtures/directiveSchemas/baseTypes.graphql
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 10 additions & 1 deletion fixtures/expectedOutput/directiveSchemas/printedDefault.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 11 additions & 5 deletions src/printers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down