Skip to content

Commit 7028213

Browse files
committed
Add test for enums in directives
1 parent 8207ab5 commit 7028213

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package graphql.kickstart.tools
2+
3+
import graphql.GraphQL
4+
import graphql.execution.AsyncExecutionStrategy
5+
import graphql.schema.GraphQLFieldDefinition
6+
import graphql.schema.idl.SchemaDirectiveWiring
7+
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
8+
import org.junit.Ignore
9+
import org.junit.Test
10+
11+
class DirectiveTest {
12+
13+
@Test
14+
@Ignore("Ignore until enums work in directives")
15+
fun `should compile schema with directive that has enum parameter`() {
16+
val schema = SchemaParser.newParser().schemaString("""
17+
directive @allowed(state: [AllowedState!]) on FIELD_DEFINITION
18+
19+
enum AllowedState {
20+
ALLOWED
21+
DISALLOWED
22+
}
23+
24+
type Book {
25+
id: Int!
26+
name: String! @allowed(state: [ALLOWED])
27+
}
28+
29+
type Query {
30+
books: [Book!]
31+
}
32+
""")
33+
.resolvers(QueryResolver())
34+
.directive("allowed", AllowedDirective())
35+
.build()
36+
.makeExecutableSchema()
37+
38+
GraphQL.newGraphQL(schema)
39+
.queryExecutionStrategy(AsyncExecutionStrategy())
40+
.build()
41+
}
42+
43+
class QueryResolver : GraphQLQueryResolver {
44+
fun books(): List<Book> {
45+
return listOf(Book(42L, "Test Book"))
46+
}
47+
}
48+
49+
data class Book(
50+
val id: Long,
51+
val name: String
52+
)
53+
54+
enum class AllowedState {
55+
ALLOWED,
56+
DISALLOWED
57+
}
58+
59+
class AllowedDirective : SchemaDirectiveWiring {
60+
override fun onField(environment: SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition>): GraphQLFieldDefinition {
61+
val field = environment.element
62+
63+
// TODO
64+
65+
return field
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)