11package graphql.kickstart.tools
22
3- import graphql.ExecutionInput
43import graphql.GraphQL
54import graphql.kickstart.tools.resolver.FieldResolverError
65import graphql.schema.DataFetcher
76import graphql.schema.DataFetchingEnvironment
8- import org.junit.Assert
97import org.junit.Test
108import java.util.*
119
1210class MissingFieldResolverTest {
1311
1412 @Test(expected = FieldResolverError ::class )
15- fun `should throw error` () {
13+ fun `should throw error when a field is missing ` () {
1614 SchemaParser .newParser()
17- .schemaString("""
18- type Query {
19- implementedField(input: String): String
20- missingField(input: Int): Int
21- }
22- """
15+ .schemaString(
16+ """
17+ type Query {
18+ implementedField(input: String): String
19+ missingField(input: Int): Int
20+ }
21+ """
2322 )
2423 .resolvers(object : GraphQLQueryResolver {
2524 fun implementedField (input : Optional <String >) = input.toString()
@@ -31,12 +30,13 @@ class MissingFieldResolverTest {
3130 @Test
3231 fun `should call missing resolver data fetcher if provided` () {
3332 val schema = SchemaParser .newParser()
34- .schemaString("""
35- type Query {
36- implementedField(input: String): String
37- missingField(input: Int): Int
38- }
39- """
33+ .schemaString(
34+ """
35+ type Query {
36+ implementedField(input: String): String
37+ missingField(input: Int): Int
38+ }
39+ """
4040 )
4141 .resolvers(object : GraphQLQueryResolver {
4242 fun implementedField (input : Optional <String >) = input.toString()
@@ -49,23 +49,20 @@ class MissingFieldResolverTest {
4949
5050 val gql = GraphQL .newGraphQL(schema).build()
5151
52- val result = gql
53- .execute(ExecutionInput .newExecutionInput()
54- .query("""
55- query {
56- implementedField(input: "test-value")
57- missingField(input: 1)
58- }
59- """ )
60- .context(Object ())
61- .root(Object ()))
52+ val result = gql.execute(
53+ """
54+ query {
55+ implementedField(input: "test-value")
56+ missingField(input: 1)
57+ }
58+ """ )
6259
6360 val expected = mapOf (
6461 " implementedField" to " Optional[test-value]" ,
6562 " missingField" to 1
6663 )
6764
68- Assert . assertEquals(expected, result.getData())
65+ assertEquals(result.getData(), expected )
6966 }
7067
7168 class TestMissingResolverDataFetcher : DataFetcher <Any ?> {
0 commit comments