You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 910756f
Browse filesBrowse the repository at this point in the historyBrowse files
Simplify the input field scan and the type error messages
- Fix the two compiler warnings for the java.util.Map and Object class
literals in isPropertyMap
- Flatten handleInputObjectFields with early returns
- Give the three enum-without-class messages the same fix hint, so only
the reason differs
- Pick the type kind in unexpectedTypeError without a triple negation
- Write the source name as "in <file>", like the syntax errors from #838
- Drop "javax." from the library class prefixes, nothing there is an
input class
- Shorten the missing property warning
- Fold the ObjectNode method name test and the Map subclass enum error
test into their neighbours
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
log.warn("Cannot find a public getter or field for field '${inputValueDefinition.name}: ${inputGraphQLType.name}' of input type '${graphQLType.name}' on ${clazz.name}. "+
505
-
"Unless Jackson maps it some other way, e.g. through @JsonProperty, check that the property name matches the schema, "+
506
-
"otherwise the field's value is rejected or dropped when the input is deserialized.")
507
+
"If Jackson doesn't map it some other way, e.g. through @JsonProperty, the field's value is rejected or dropped when the input is deserialized.")
507
508
}
508
509
509
510
when (val definition = definitionsByName[inputGraphQLType.name]) {
@@ -523,23 +524,22 @@ internal class SchemaClassScanner(
523
524
}
524
525
}
525
526
527
+
// an input bound to Any gets a Map at runtime too
val problem ="Enum type '${enum.name}' is used by field '$field' of input type '${graphQLType.name}', but its Java enum can't be determined"
535
-
returnwhen {
536
-
clazz ==null->"$problem because no class was found for input type '${graphQLType.name}'. "+
537
-
"Pass the enum class for type '${enum.name}' in the parser's dictionary, or a class for '${graphQLType.name}' with a public getter or field '$field'."
538
-
isPropertyMap(clazz) && isLibraryClass(clazz) ->"$problem because '${graphQLType.name}' is bound to ${clazz.name}, which has no type information for its fields. "+
539
-
"Pass the enum class for type '${enum.name}' in the parser's dictionary, or use a class for '${graphQLType.name}' with a public getter or field '$field'."
540
-
else->"$problem because ${clazz.name} has no public getter or field named '$field'. "+
541
-
"Add a public getter or field '$field' to the class used for '${graphQLType.name}', or pass the enum class for type '${enum.name}' in the parser's dictionary."
536
+
val reason =when {
537
+
clazz ==null->"no class was found for input type '${graphQLType.name}'"
538
+
isPropertyMap(clazz) && isLibraryClass(clazz) ->"'${graphQLType.name}' is bound to ${clazz.name}, which has no type information for its fields"
539
+
else->"${clazz.name} has no public getter or field named '$field'"
542
540
}
541
+
return"Enum type '${enumType.name}' is used by field '$field' of input type '${graphQLType.name}', but its Java enum can't be determined because $reason. "+
542
+
"Pass the enum class for type '${enumType.name}' in the parser's dictionary, or use a class for '${graphQLType.name}' with a public getter or field '$field'."
Copy file name to clipboardExpand all lines: src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt
+24-42Lines changed: 24 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -283,7 +283,7 @@ class SchemaParserTest {
283
283
.makeExecutableSchema()
284
284
}
285
285
286
-
assertEquals(error.message, "Type 'Cat' used by field 'Pet.friend' at line 6, column 11 of UnreachedType.graphqls is defined in the schema, "+
286
+
assertEquals(error.message, "Type 'Cat' used by field 'Pet.friend' at line 6, column 11 in UnreachedType.graphqls is defined in the schema, "+
287
287
"but was not reached while scanning the resolvers and the classes they use, so it wasn't built. "+
288
288
"Return it from a resolver method or one of those classes, or set SchemaParserOptions.includeUnusedTypes and pass a class for it in the parser's dictionary.")
289
289
}
@@ -572,60 +572,42 @@ class SchemaParserTest {
572
572
573
573
@Test
574
574
fun`parser should throw descriptive exception when enum is only used in input Map without a class`() {
575
-
val error = assertThrows(SchemaClassScannerError::class.java) {
576
-
SchemaParser.newParser()
577
-
.schemaString(
578
-
"""
579
-
type Query {
580
-
save(input: SaveInput!): Boolean
581
-
}
575
+
val schema ="""
576
+
type Query {
577
+
save(input: SaveInput!): Boolean
578
+
}
582
579
583
-
input SaveInput {
584
-
type: EnumType!
585
-
}
580
+
input SaveInput {
581
+
type: EnumType!
582
+
}
586
583
587
-
enum EnumType {
588
-
TEST
589
-
}
590
-
""")
584
+
enum EnumType {
585
+
TEST
586
+
}
587
+
"""
588
+
val mapError = assertThrows(SchemaClassScannerError::class.java) {
589
+
SchemaParser.newParser()
590
+
.schemaString(schema)
591
591
.resolvers(object:GraphQLQueryResolver {
592
592
funsave(input:Map<*, *>): Boolean=false
593
593
})
594
594
.build()
595
595
}
596
-
597
-
assertEquals(error.message, "Enum type 'EnumType' is used by field 'type' of input type 'SaveInput', but its Java enum can't be determined "+
598
-
"because 'SaveInput' is bound to java.util.Map, which has no type information for its fields. Pass the enum class for type "+
599
-
"'EnumType' in the parser's dictionary, or use a class for 'SaveInput' with a public getter or field 'type'.")
600
-
}
601
-
602
-
@Test
603
-
fun`parser should throw descriptive exception when enum is only used in input Map subclass without a getter for it`() {
604
-
val error = assertThrows(SchemaClassScannerError::class.java) {
596
+
val subclassError = assertThrows(SchemaClassScannerError::class.java) {
605
597
SchemaParser.newParser()
606
-
.schemaString(
607
-
"""
608
-
type Query {
609
-
save(input: SaveInput!): Boolean
610
-
}
611
-
612
-
input SaveInput {
613
-
type: EnumType!
614
-
}
615
-
616
-
enum EnumType {
617
-
TEST
618
-
}
619
-
""")
598
+
.schemaString(schema)
620
599
.resolvers(object:GraphQLQueryResolver {
621
600
funsave(input:SaveInputMap): Boolean=false
622
601
})
623
602
.build()
624
603
}
625
604
626
-
assertEquals(error.message, "Enum type 'EnumType' is used by field 'type' of input type 'SaveInput', but its Java enum can't be determined "+
627
-
"because ${SaveInputMap::class.java.name} has no public getter or field named 'type'. Add a public getter or field 'type' to the class "+
628
-
"used for 'SaveInput', or pass the enum class for type 'EnumType' in the parser's dictionary.")
605
+
assertEquals(mapError.message, "Enum type 'EnumType' is used by field 'type' of input type 'SaveInput', but its Java enum can't be determined "+
606
+
"because 'SaveInput' is bound to java.util.Map, which has no type information for its fields. Pass the enum class for type "+
607
+
"'EnumType' in the parser's dictionary, or use a class for 'SaveInput' with a public getter or field 'type'.")
608
+
assertEquals(subclassError.message, "Enum type 'EnumType' is used by field 'type' of input type 'SaveInput', but its Java enum can't be determined "+
609
+
"because ${SaveInputMap::class.java.name} has no public getter or field named 'type'. Pass the enum class for type "+
610
+
"'EnumType' in the parser's dictionary, or use a class for 'SaveInput' with a public getter or field 'type'.")
629
611
}
630
612
631
613
@Test
@@ -658,7 +640,7 @@ class SchemaParserTest {
658
640
659
641
assertEquals(error.message, "Enum type 'EnumType' is used by field 'type' of input type 'NestedInput', but its Java enum can't be determined "+
660
642
"because no class was found for input type 'NestedInput'. Pass the enum class for type 'EnumType' in the parser's dictionary, "+
661
-
"or a class for 'NestedInput' with a public getter or field 'type'.")
643
+
"or use a class for 'NestedInput' with a public getter or field 'type'.")
0 commit comments