Skip to content

Commit fa998b6

Browse files
committed
Fix nulls
1 parent 594809f commit fa998b6

File tree

7 files changed

+37
-25
lines changed

7 files changed

+37
-25
lines changed

src/main/kotlin/graphql/kickstart/tools/relay/RelayConnectionFactory.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RelayConnectionFactory : TypeDefinitionFactory {
5454
.fieldDefinition(FieldDefinition("pageInfo", TypeName("PageInfo")))
5555
.build()
5656

57-
private fun createEdgeDefinition(connectionType: String, nodeType: String): ObjectTypeDefinition =
57+
private fun createEdgeDefinition(connectionType: String, nodeType: String?): ObjectTypeDefinition =
5858
ObjectTypeDefinition.newObjectTypeDefinition()
5959
.name(connectionType + "Edge")
6060
.fieldDefinition(FieldDefinition("cursor", TypeName("String")))
@@ -70,7 +70,7 @@ class RelayConnectionFactory : TypeDefinitionFactory {
7070
.fieldDefinition(FieldDefinition("endCursor", TypeName("String")))
7171
.build()
7272

73-
private fun Directive.forTypeName(): String {
73+
private fun Directive.forTypeName(): String? {
7474
return (this.getArgument("for").value as StringValue).value
7575
}
7676

@@ -82,7 +82,13 @@ class RelayConnectionFactory : TypeDefinitionFactory {
8282
return this.directives.map { it.withField(this) }
8383
}
8484

85-
class DirectiveWithField(val field: FieldDefinition, name: String, arguments: List<Argument>, sourceLocation: SourceLocation, comments: List<Comment>) : Directive(name, arguments, sourceLocation, comments, IgnoredChars.EMPTY, emptyMap()) {
85+
class DirectiveWithField(
86+
val field: FieldDefinition,
87+
name: String,
88+
arguments: List<Argument>,
89+
sourceLocation: SourceLocation?,
90+
comments: List<Comment>
91+
) : Directive(name, arguments, sourceLocation, comments, IgnoredChars.EMPTY, emptyMap()) {
8692
fun getTypeName(): String {
8793
val type = field.type
8894
if (type is NonNullType) {

src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolverScanner.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
202202
isSubscription = isSubscription || search.source is GraphQLSubscriptionResolver
203203
}
204204

205-
val sourceName = if (field.sourceLocation != null && field.sourceLocation.sourceName != null) field.sourceLocation.sourceName else "<unknown>"
206-
val sourceLocation = if (field.sourceLocation != null) "$sourceName:${field.sourceLocation.line}" else "<unknown>"
205+
val sourceName = field.sourceLocation?.sourceName ?: "<unknown>"
206+
val sourceLocation = field.sourceLocation?.let { "$sourceName:${it.line}" } ?: "<unknown>"
207+
207208
return "No method${if (scannedProperties) " or field" else ""} found as defined in schema $sourceLocation with any of the following signatures " +
208209
"(with or without one of $allowedLastArgumentTypes as the last argument), in priority order:\n${signatures.joinToString("\n ")}" +
209210
if (isSubscription) "\n\nNote that a Subscription data fetcher must return a Publisher of events" else ""

src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ val customScalarUUID = GraphQLScalarType.newScalar()
501501
val customScalarMap = GraphQLScalarType.newScalar()
502502
.name("customScalarMap")
503503
.description("customScalarMap")
504-
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {
504+
.coercing(object : Coercing<Map<String, Any?>, Map<String, Any?>> {
505505

506506
@Suppress("UNCHECKED_CAST")
507507
override fun parseValue(input: Any, context: GraphQLContext, locale: Locale): Map<String, Any> = input as Map<String, Any>
@@ -515,8 +515,10 @@ val customScalarMap = GraphQLScalarType.newScalar()
515515
variables: CoercedVariables,
516516
context: GraphQLContext,
517517
locale: Locale
518-
): Map<String, Any> =
519-
(input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value }
518+
): Map<String, Any?> =
519+
(input as ObjectValue).objectFields
520+
.associateBy { it.name }
521+
.mapValues { (it.value.value as StringValue).value }
520522
})
521523
.build()
522524

src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverDataFetcherTest.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,25 @@ class MethodFieldResolverDataFetcherTest {
296296
return FieldResolverScanner(options).findFieldResolver(field, resolverInfo).createDataFetcher()
297297
}
298298

299-
private fun createEnvironment(source: Any = Object(), arguments: Map<String, Any> = emptyMap(), context: GraphQLContext? = null): DataFetchingEnvironment {
300-
return DataFetchingEnvironmentImpl.newDataFetchingEnvironment(buildExecutionContext())
301-
.source(source)
302-
.arguments(arguments)
303-
.graphQLContext(context)
304-
.build()
305-
}
306-
307-
private fun buildExecutionContext(): ExecutionContext {
299+
private fun createEnvironment(
300+
source: Any = Object(),
301+
arguments: Map<String, Any> = emptyMap(),
302+
context: GraphQLContext = GraphQLContext.newContext().build()
303+
) = DataFetchingEnvironmentImpl.newDataFetchingEnvironment(buildExecutionContext(context))
304+
.source(source)
305+
.arguments(arguments)
306+
.graphQLContext(context)
307+
.build()
308+
309+
private fun buildExecutionContext(context: GraphQLContext): ExecutionContext {
308310
val executionStrategy = object : ExecutionStrategy() {
309311
override fun execute(executionContext: ExecutionContext, parameters: ExecutionStrategyParameters): CompletableFuture<ExecutionResult> {
310312
throw AssertionError("should not be called")
311313
}
312314
}
313315
val executionId = ExecutionId.from("executionId123")
314316
return ExecutionContextBuilder.newExecutionContextBuilder()
317+
.graphQLContext(context)
315318
.instrumentation(SimplePerformantInstrumentation.INSTANCE)
316319
.executionId(executionId)
317320
.queryStrategy(executionStrategy)

src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class MethodFieldResolverTest {
246246
val value get() = internalValue
247247

248248
companion object {
249-
fun of(input: Any) = when (input) {
249+
fun of(input: Any?) = when (input) {
250250
is String -> CustomScalar(input)
251251
else -> throw IllegalArgumentException()
252252
}

src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerDirectiveTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SchemaClassScannerDirectiveTest {
3737
assertEquals(value.value, "some thing")
3838
}
3939

40-
data class CustomValue(val value: String)
40+
data class CustomValue(val value: String?)
4141
private val customValueScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
4242
.name("CustomValue")
4343
.coercing(object : Coercing<CustomValue, String> {

src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class SchemaParserTest {
263263
.getFieldDefinition("id")
264264
.definition!!.sourceLocation
265265
assertNotNull(sourceLocation)
266-
assertEquals(sourceLocation.line, 2)
267-
assertEquals(sourceLocation.column, 5)
268-
assertNull(sourceLocation.sourceName)
266+
assertEquals(sourceLocation?.line, 2)
267+
assertEquals(sourceLocation?.column, 5)
268+
assertNull(sourceLocation?.sourceName)
269269
}
270270

271271
@Test
@@ -280,9 +280,9 @@ class SchemaParserTest {
280280
.getFieldDefinition("id")
281281
.definition!!.sourceLocation
282282
assertNotNull(sourceLocation)
283-
assertEquals(sourceLocation.line, 2)
284-
assertEquals(sourceLocation.column, 3)
285-
assertEquals(sourceLocation.sourceName, "Test.graphqls")
283+
assertEquals(sourceLocation?.line, 2)
284+
assertEquals(sourceLocation?.column, 3)
285+
assertEquals(sourceLocation?.sourceName, "Test.graphqls")
286286
}
287287

288288
@Test

0 commit comments

Comments
 (0)