[英]Kickstarter type dictionary equivalent in spring boot graphql starter
When using spring-boot-starter-graphql
Spring is using a simple name to class mapping.使用
spring-boot-starter-graphql
时 Spring 是使用简单的名称来 class 映射。 Eg for a mutation:例如对于突变:
mutation {
addCategory(id: 6, name: "Green Fruits", products: [8, 2, 3]) {
name
products {
name
}
}
}
Spring will check for a mutation called addCategory and for a class named Product
. Spring 将检查名为 addCategory 的突变和名为
Product
的 class 的突变。
graphql-java-kickstart offers a way to maintain a dictionary for classes not matching that pattern: https://www.graphql-java-kickstart.com/tools/schema-definition/#type-dictionary graphql-java-kickstart 提供了一种方法来维护与该模式不匹配的类的字典: https://www.graphql-java-kickstart.com/tools/schema-definition/#type-dictionary
Is there anything similar for spring-boot-starter-graphql
? spring-boot-starter-graphql
有类似的东西吗?
Spring's TypeResolver seem to to this for Interfaces and Unions Spring 的TypeResolver似乎适用于接口和联合
By default Spring for GraphQL will use a ClassNameTypeResolver
to find the GraphQL Object Type from the value returned by the data fetcher.默认情况下,GraphQL 的 Spring 将使用
ClassNameTypeResolver
查找 GraphQL Z497031794414A552435F901 返回的值。 This is looking at the simple class name of the value and if it is not successful, it also navigates its super types including base classes and interfaces.这是查看值的简单 class 名称,如果不成功,它还会导航其超类型,包括基类和接口。
In case the Class name doesn't match any of the type names in the schema, you can configure a custom type resolver and have additional logic there.如果 Class 名称与架构中的任何类型名称都不匹配,您可以配置自定义类型解析器并在其中添加其他逻辑。
You can instantiate a ClassNameTypeResolver
and set its您可以实例化
ClassNameTypeResolver
并设置其
ClassNameTypeResolver classNameTypeResolver = new ClassNameTypeResolver();
classNameTypeResolver.setClassNameExtractor((klass) -> {
// Look up into a custom dictionnary
// fall back to klass.getSimpleName() if none found
});
This can be contributed through a GraphQlSourceBuilderCustomizer
in Spring Boot.这可以通过
GraphQlSourceBuilderCustomizer
Boot 中的 GraphQlSourceBuilderCustomizer 提供。 See https://docs.spring.io/spring-graphql/docs/current-SNAPSHOT/reference/html/#execution-graphqlsource-default-type-resolver .请参阅https://docs.spring.io/spring-graphql/docs/current-SNAPSHOT/reference/html/#execution-graphqlsource-default-type-resolver 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.