Skip to content
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
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@
</goals>
</execution>
<execution>
<!-- before javac, so the Java tests can use the Kotlin test helpers -->
<id>test-compile</id>
<phase>test-compile</phase>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface Animal {
.resolvers(new PetQuery(), new AnimalQuery())
.build()
.makeExecutableSchema();
EveryFieldResolvesKt.assertEveryFieldResolves(schema);

ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(ExecutionInput.newExecutionInput().query("""
query {
Expand Down
6 changes: 6 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/BuiltInIdTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class BuiltInIdTest {
.queryExecutionStrategy(AsyncExecutionStrategy())
.build()

@Test
fun `every field resolves`() {
// the made-up ID "1" isn't a UUID
schema.assertEveryFieldResolves(except = setOf("Query.itemByUuidId(id:)", "Query.itemsByUuidIds(ids:)"))
}

@Test
fun `supports Long as ID as input`() {
val data = assertNoGraphQlErrors(gql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class CustomScalarInputTest {
.options(options)
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()
return GraphQL.newGraphQL(graphQLSchema).build()
}

Expand Down Expand Up @@ -265,7 +266,7 @@ class CustomScalarInputTest {
fun optionalEvent(input: Optional<EventInput>): String = input.map { event(it) }.orElse("empty")
fun message(input: MessageInput): String = "${input.name}: ${(listOfNotNull(input.file) + input.files).joinToString(" ") { it.content() }}"
fun label(input: LabelInput): String = "${input.date} ${input.opaque}"
fun dateNode(input: ObjectNode): String = (input["date"] as POJONode).pojo.let { "${it.javaClass.simpleName} $it" }
fun dateNode(input: ObjectNode): String = (input["date"] as POJONode?)?.pojo?.let { "${it.javaClass.simpleName} $it" }.orEmpty()
fun priceNode(input: ObjectNode): String = input.toString()
fun payment(input: PaymentInput): String = listOfNotNull(input.price, input.reference, input.date, input.box).joinToString(" ")
fun price(price: MoneyDto): String = price.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PlaceTest {
.file("Place.graphqls")
.resolvers(PlaceQuery())
.build().makeExecutableSchema()
.assertEveryFieldResolves()

val graphql = GraphQL.newGraphQL(schema).build()
val query = "query { places1 { id } places2 { id } }"
Expand Down
57 changes: 41 additions & 16 deletions src/test/kotlin/graphql/kickstart/tools/DeprecatedDirectiveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val userType = schema.getType("User") as GraphQLObjectType
val nameDefinition = userType.getField("name")
Expand Down Expand Up @@ -68,6 +69,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val userType = schema.getType("User") as GraphQLObjectType
val nameDefinition = userType.getField("name")
Expand Down Expand Up @@ -108,6 +110,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val userTypeEnum = schema.getType("UserType") as GraphQLEnumType
val droidValue = userTypeEnum.getValue("DROID")
Expand Down Expand Up @@ -148,6 +151,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val userTypeEnum = schema.getType("UserType") as GraphQLEnumType
val droidValue = userTypeEnum.getValue("DROID")
Expand Down Expand Up @@ -178,9 +182,10 @@ class DeprecatedDirectiveTest {
name: String
}
""")
.resolvers(UsersQueryResolver())
.resolvers(UsersWithFirstQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val usersQuery = schema.queryType.getField("users")
val firstArgument = usersQuery.getArgument("first")
Expand Down Expand Up @@ -211,9 +216,10 @@ class DeprecatedDirectiveTest {
name: String
}
""")
.resolvers(UsersQueryResolver())
.resolvers(UsersWithFirstQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val usersQuery = schema.queryType.getField("users")
val firstArgument = usersQuery.getArgument("first")
Expand Down Expand Up @@ -249,6 +255,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val directive = schema.getDirective("uppercase")
val argument = directive!!.getArgument("firstCharacterOnly")
Expand Down Expand Up @@ -284,6 +291,7 @@ class DeprecatedDirectiveTest {
.resolvers(UsersQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val directive = schema.getDirective("uppercase")
val argument = directive!!.getArgument("firstCharacterOnly")
Expand Down Expand Up @@ -318,9 +326,10 @@ class DeprecatedDirectiveTest {
name: String
}
""")
.resolvers(UsersQueryResolver())
.resolvers(UsersWithConnectionInputQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val connectionInputType = schema.getType("ConnectionInput") as GraphQLInputObjectType
val firstField = connectionInputType.getField("first")
Expand Down Expand Up @@ -355,9 +364,10 @@ class DeprecatedDirectiveTest {
name: String
}
""")
.resolvers(UsersQueryResolver())
.resolvers(UsersWithConnectionInputQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val connectionInputType = schema.getType("ConnectionInput") as GraphQLInputObjectType
val firstField = connectionInputType.getField("first")
Expand Down Expand Up @@ -395,9 +405,10 @@ class DeprecatedDirectiveTest {
type: UserType @deprecated(reason: "custom")
}
""")
.resolvers(UsersQueryResolver())
.resolvers(UsersWithFirstQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val name = (schema.getType("User") as GraphQLObjectType).getField("name")
assertEquals("No longer supported", name.getAppliedDirective("deprecated").getArgument("reason")!!.getValue<String>())
Expand All @@ -415,16 +426,30 @@ class DeprecatedDirectiveTest {
}

private class UsersQueryResolver : GraphQLQueryResolver {
fun users(env: DataFetchingEnvironment): Connection<User> {
return SimpleListConnection(listOf(User(1L, "Luke Skywalker", "Luke", "Skywalker", UserType.JEDI))).get(env)
}

private data class User(
val id: Long,
val name: String,
val firstName: String,
val lastName: String,
val type: UserType
)
fun users(env: DataFetchingEnvironment): Connection<User> = SimpleListConnection(users).get(env)
}

private class UsersWithFirstQueryResolver : GraphQLQueryResolver {
fun users(first: Int?, env: DataFetchingEnvironment): Connection<User> = SimpleListConnection(users).get(env)
}

private class UsersWithConnectionInputQueryResolver : GraphQLQueryResolver {
fun users(connectionInput: ConnectionInput?, env: DataFetchingEnvironment): Connection<User> = SimpleListConnection(users).get(env)
}

data class ConnectionInput(
val first: Int?
)

private data class User(
val id: Long,
val name: String,
val firstName: String,
val lastName: String,
val type: UserType
)

companion object {
private val users = listOf(User(1L, "Luke Skywalker", "Luke", "Skywalker", UserType.JEDI))
}
}
26 changes: 22 additions & 4 deletions src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DirectiveTest {
.directive("uppercase", UppercaseDirective())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -93,6 +94,7 @@ class DirectiveTest {
.directive("uppercase", UppercaseDirective())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -137,6 +139,7 @@ class DirectiveTest {
.directive("uppercase", UppercaseDirective())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -179,6 +182,7 @@ class DirectiveTest {
.directive("double", DoubleDirective())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -215,11 +219,14 @@ class DirectiveTest {
name: String @auth @log
}
""")
.resolvers(NameResolver())
.resolvers(object : GraphQLQueryResolver {
fun name(): String? = null
})
.directive("auth", DescriptionDirective("auth"))
.directive("log", DescriptionDirective("log"))
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

assertEquals(schema.queryType.getField("name").description, "Name +auth +log")
}
Expand All @@ -236,11 +243,14 @@ class DirectiveTest {
name: String @auth
}
""")
.resolvers(NameResolver())
.resolvers(object : GraphQLQueryResolver {
fun name(): String? = null
})
.directive("auth", DescriptionDirective("auth"))
.directiveWiring(DescriptionDirective("static"))
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

assertEquals(schema.queryType.getField("name").description, "Name +auth +static")
}
Expand Down Expand Up @@ -285,6 +295,7 @@ class DirectiveTest {
.directive("uppercase", UppercaseDirective())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -337,6 +348,7 @@ class DirectiveTest {
.dictionary(AllowedState::class)
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -365,6 +377,7 @@ class DirectiveTest {
.resolvers(BookQueryResolver())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val filter = schema.getType("BookFilter") as GraphQLInputObjectType
assert(filter.isOneOf)
Expand Down Expand Up @@ -404,6 +417,7 @@ class DirectiveTest {
.directive("email", emailDirective)
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val expectedMessages = mapOf(
"contactEmail" to "{path} must be a valid email",
Expand Down Expand Up @@ -452,6 +466,7 @@ class DirectiveTest {
.directive("option", recorder)
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val inputObject = listOf("GraphQLInputObjectType")
val expectedTypes = mapOf("name" to inputObject, "ConfigInput" to inputObject, "level" to inputObject)
Expand Down Expand Up @@ -490,6 +505,7 @@ class DirectiveTest {
})
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

assert(wiredFields == listOf("max")) { "$wiredFields with directives declared as $directives" }
val limit = (schema.getType("BoundInput") as GraphQLInputObjectType).getField("max").getAppliedDirective("limit")
Expand Down Expand Up @@ -531,6 +547,7 @@ class DirectiveTest {
.dictionary(LinkPurpose::class)
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

assertEquals(schema.schemaAppliedDirectives.map { it.name }, listOf("contact", "link", "link"))
assertEquals(
Expand Down Expand Up @@ -594,6 +611,7 @@ class DirectiveTest {
.options(SchemaParserOptions.newOptions().allowUndeclaredDirectives(true).build())
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val link = schema.getSchemaAppliedDirective("link")
assertEquals(link.getArgument("import")?.getValue<List<String>>(), listOf("@key", "@shareable"))
Expand Down Expand Up @@ -644,7 +662,7 @@ class DirectiveTest {
fun book(filter: BookFilter): Book? = null
}

private data class BookFilter(
data class BookFilter(
val id: Int?,
val name: String?
)
Expand All @@ -655,7 +673,7 @@ class DirectiveTest {
fun updatePerson(person: PersonInput?, state: AllowedState?): String? = null
}

private data class PersonInput(
data class PersonInput(
val email: String?
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
fun itemsWithOptionalInput(input: ItemSearchInput?) = if (input == null) items else items(input)
fun itemsWithOptionalInputExplicit(input: Optional<ItemSearchInput>?) = if (input?.isPresent == true) items(input.get()) else items
fun enumInputType(type: Type) = type
fun customScalarMapInputType(customScalarMap: Map<String, Any>) = customScalarMap
fun customScalarMapInputType(customScalarMap: Map<String, Any>?) = customScalarMap
fun itemWithGenericProperties() = ItemWithGenericProperties(listOf("A", "B"))

fun defaultArgument(arg: Boolean) = arg
Expand Down
9 changes: 9 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/EndToEndTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class EndToEndTest {
.queryExecutionStrategy(AsyncExecutionStrategy())
.build()

@Test
fun `every field resolves`() {
val newItem = Item(1, "item", Type.TYPE_1, UUID.randomUUID(), listOf())
// throws on purpose to test that the original exception is passed on
schema.assertEveryFieldResolves(except = setOf("Query.throwsIllegalArgumentException")) {
graphQLContext(mapOf("newItem" to newItem))
}
}

@Test
fun `schema comments are used as descriptions`() {
val type = schema.allTypesAsList.find { it.name == "Type" } as GraphQLEnumType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class EnumDefaultValueTest {
})
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val ggl = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(AsyncExecutionStrategy())
Expand Down Expand Up @@ -64,6 +65,7 @@ class EnumDefaultValueTest {
})
.build()
.makeExecutableSchema()
.assertEveryFieldResolves()

val ggl = GraphQL.newGraphQL(schema).build()

Expand Down
Loading
Loading