Skip to content

Commit 2928c8c

Browse files
smyrickdariuszkuc
authored andcommitted
fix: remove directive duplication in the generator (#176)
1 parent 193871a commit 2928c8c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/kotlin/com/expedia/graphql/generator/types/DirectiveTypeBuilder.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ internal class DirectiveTypeBuilder(generator: SchemaGenerator) : TypeBuilder(ge
2020

2121
private fun getDirective(directiveInfo: DirectiveInfo): GraphQLDirective {
2222

23+
val existingDirective = state.directives.find { it.name == directiveInfo.effectiveName }
24+
25+
if (existingDirective != null) {
26+
return existingDirective
27+
}
28+
2329
val directiveClass = directiveInfo.directive.annotationClass
2430

2531
val builder = GraphQLDirective.newDirective()

src/test/kotlin/com/expedia/graphql/generator/types/DirectiveTypeBuilderTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,11 @@ internal class DirectiveTypeBuilderTest {
7979
fun `has directive with class`() {
8080
assertEquals(expected = 1, actual = basicGenerator.directives(MyClass::directiveWithClass).size)
8181
}
82+
83+
@Test
84+
fun `directives are not duplicated in the schema`() {
85+
basicGenerator.directives(MyClass::simpleDirective)
86+
basicGenerator.directives(MyClass::simpleDirective)
87+
assertEquals(1, basicGenerator.state.directives.size)
88+
}
8289
}

0 commit comments

Comments
 (0)