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
Copy file name to clipboardExpand all lines: README.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -335,3 +335,19 @@ Options:
335
335
*`useDefaultGenericWrappers`: Defaults to `true`. Tells the parser whether or not to add it's own list of well-known generic wrappers, such as `Future` and `CompletableFuture`.
336
336
*`allowUnimplementedResolvers`: Defaults to `false`. Allows a schema to be created even if not all GraphQL fields have resolvers. Intended only for development, it will log a warning to remind you to turn it off for production. Any unimplemented resolvers will throw errors when queried.
337
337
*`objectMapperConfigurer`: Exposes the Jackson `ObjectMapper` that handles marshalling arguments in method resolvers. Every method resolver gets its own mapper, and the configurer can configure it differently based on the GraphQL field definition.
338
+
*`preferGraphQLResolver`: In cases where you have a Resolver class and legacy class that conflict on type arguements, use the Resolver class instead of throwing an error.
339
+
340
+
Specificly this situation can occur when you have a graphql schema type `Foo` with a `bars` property and classes:
341
+
```java
342
+
// legacy class you can't change
343
+
classFoo {
344
+
Set<Bar>getBars() {...returns set of bars...}
345
+
}
346
+
347
+
// nice resolver that does what you want
348
+
classFooResolverimplementsGraphQLResolver<Foo> {
349
+
Set<BarDTO>getBars() {...converts Bar objects to BarDTO objects and retunrs set...}
350
+
}
351
+
```
352
+
You will now have the code find two different return types for getBars() and application will not start with the error ```Caused by:com.coxautodev.graphql.tools.SchemaClassScannerError:Two different classes used for type```
353
+
Ifthis property is true it will ignore the legacy version.
Copy file name to clipboardExpand all lines: src/main/kotlin/com/coxautodev/graphql/tools/SchemaClassScanner.kt
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -260,7 +260,11 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
260
260
typeWasSet = realEntry.setTypeIfMissing(clazz)
261
261
262
262
if (realEntry.typeClass != clazz) {
263
-
throwSchemaClassScannerError("Two different classes used for type ${type.name}:\n${realEntry.joinReferences()}\n\n- $clazz:\n| ${reference.getDescription()}")
263
+
if (options.preferGraphQLResolver && realEntry.hasResolverRef()) {
264
+
log.warn("The real entry ${realEntry.joinReferences()} is a GraphQLResolver so ignoring this one $clazz$reference")
265
+
} else {
266
+
throwSchemaClassScannerError("Two different classes used for type ${type.name}:\n${realEntry.joinReferences()}\n\n- $clazz:\n| ${reference.getDescription()}")
267
+
}
264
268
}
265
269
}
266
270
@@ -346,8 +350,16 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
0 commit comments