Skip to content
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

fix(astprinter): implement transitive interface output #1021

Merged
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
14 changes: 14 additions & 0 deletions pkg/astprinter/astprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ func (p *printVisitor) EnterInterfaceTypeDefinition(ref int) {
p.write(p.document.InterfaceTypeDefinitionNameBytes(ref))
p.write(literal.SPACE)

if len(p.document.InterfaceTypeDefinitions[ref].ImplementsInterfaces.Refs) != 0 {
p.write(literal.IMPLEMENTS)
p.write(literal.SPACE)
for i, j := range p.document.InterfaceTypeDefinitions[ref].ImplementsInterfaces.Refs {
if i != 0 {
p.write(literal.SPACE)
p.write(literal.AND)
p.write(literal.SPACE)
}
p.must(p.document.PrintType(j, p.out))
}
p.write(literal.SPACE)
}

p.inputValueDefinitionOpener = literal.LPAREN
p.inputValueDefinitionCloser = literal.RPAREN
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/astprinter/astprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ vary: [String]! = []) on QUERY directive @include(if: Boolean!) repeatable on FI
`scalar Date schema {query: Query} type Query {me: User! user(id: ID!): User allUsers: [User] search(term: String!): [SearchResult!]! myChats: [Chat!]!} enum Role {USER ADMIN} interface Node {id: ID!} union SearchResult = User | Chat | ChatMessage type User implements Node {id: ID! username: String! email: String! role: Role!} type Chat implements Node {id: ID! users: [User!]! messages: [ChatMessage!]!} type ChatMessage implements Node {id: ID! content: String! time: Date! user: User!}`)
})
})
t.Run("transitive interfaces", func(t *testing.T) {
run(t, "interface I1 {id: ID!} interface I2 implements I1 {id: ID!} interface I3 implements I1 & I2 {id: ID!}",
"interface I1 {id: ID!} interface I2 implements I1 {id: ID!} interface I3 implements I1 & I2 {id: ID!}")
})
}

func TestPrintArgumentWithBeforeAfterValue(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions v2/pkg/astprinter/astprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,20 @@ func (p *printVisitor) EnterInterfaceTypeDefinition(ref int) {
p.write(p.document.InterfaceTypeDefinitionNameBytes(ref))
p.write(literal.SPACE)

if len(p.document.InterfaceTypeDefinitions[ref].ImplementsInterfaces.Refs) != 0 {
p.write(literal.IMPLEMENTS)
p.write(literal.SPACE)
for i, j := range p.document.InterfaceTypeDefinitions[ref].ImplementsInterfaces.Refs {
if i != 0 {
p.write(literal.SPACE)
p.write(literal.AND)
p.write(literal.SPACE)
}
p.must(p.document.PrintType(j, p.out))
}
p.write(literal.SPACE)
}

p.inputValueDefinitionOpener = literal.LPAREN
p.inputValueDefinitionCloser = literal.RPAREN
}
Expand Down
4 changes: 4 additions & 0 deletions v2/pkg/astprinter/astprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ fragment NameFragment on Dog {
`scalar Date schema {query: Query} type Query {me: User! user(id: ID!): User allUsers: [User] search(term: String!): [SearchResult!]! myChats: [Chat!]!} enum Role {USER ADMIN} interface Node {id: ID!} union SearchResult = User | Chat | ChatMessage type User implements Node {id: ID! username: String! email: String! role: Role!} type Chat implements Node {id: ID! users: [User!]! messages: [ChatMessage!]!} type ChatMessage implements Node {id: ID! content: String! time: Date! user: User!}`)
})
})
t.Run("transitive interfaces", func(t *testing.T) {
run(t, "interface I1 {id: ID!} interface I2 implements I1 {id: ID!} interface I3 implements I1 & I2 {id: ID!}",
"interface I1 {id: ID!} interface I2 implements I1 {id: ID!} interface I3 implements I1 & I2 {id: ID!}")
})
}

func TestPrintArgumentWithBeforeAfterValue(t *testing.T) {
Expand Down
Loading