Skip to content

make directives repeatable by default #652

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

Closed
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
6 changes: 1 addition & 5 deletions src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,11 @@ class SchemaParser internal constructor(
}

private fun buildDirectives(directives: List<Directive>, directiveLocation: Introspection.DirectiveLocation): Array<GraphQLDirective> {
val names = mutableSetOf<String>()

val output = mutableListOf<GraphQLDirective>()
for (directive in directives) {
if (!names.contains(directive.name)) {
names.add(directive.name)
val graphQLDirective = GraphQLDirective.newDirective()
.name(directive.name)
.repeatable(true)
.description(getDocumentation(directive, options))
.comparatorRegistry(runtimeWiring.comparatorRegistry)
.validLocation(directiveLocation)
Expand All @@ -320,7 +317,6 @@ class SchemaParser internal constructor(
.build()

output.add(graphQLDirective)
}
}

return output.toTypedArray()
Expand Down
30 changes: 30 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package graphql.kickstart.tools

import graphql.Scalars
import graphql.introspection.Introspection
import graphql.kickstart.tools.resolver.FieldResolverError
import graphql.language.StringValue
import graphql.schema.*
import graphql.schema.idl.SchemaDirectiveWiring
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
Expand Down Expand Up @@ -625,6 +628,33 @@ class SchemaParserTest {
assertNull(schema.description)
}

@Test
fun `parser should support repeatable directives`() {
val schema = SchemaParser.newParser()
.schemaString(
"""
schema {
query: SomeType
}

type SomeType @directive(k: "1") @directive(k: "2") {
empty: String
}
"""
)
.resolvers(object : GraphQLQueryResolver {})
.options(SchemaParserOptions.newOptions().allowUnimplementedResolvers(true).build())
.build()
.makeExecutableSchema()

val someType = schema.getType("SomeType") as GraphQLObjectType
assertEquals(someType.directives.size, 2)
someType.directives.forEach { directive ->
assertEquals(directive.name, "directive")
assertEquals(directive.isRepeatable, true)
}
}

enum class EnumType {
TEST
}
Expand Down