简体   繁体   English

在 spring 启动 graphql 启动器中等效的 Kickstarter 类型字典

[英]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

There is no such dictionary, but you can override the default behavior and customize the type resolver.没有这样的字典,但您可以覆盖默认行为并自定义类型解析器。

Take a look here :看看这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring boot starter graphql无法正常工作 - spring boot starter graphql not working 为什么我会收到与使用 graphql-spqr-spring-boot-starter 的“类型名称冲突”相关的警告? - Why am I getting a warning related to 'type name collision' using graphql-spqr-spring-boot-starter? graphql-spring-boot-starter 应用程序只有 websockets - graphql-spring-boot-starter Application with only websockets spring 引导包含 com.graphql-java 和 graphql-java-spring-boot-starter-webmvc - spring boot containing com.graphql-java and graphql-java-spring-boot-starter-webmvc 如何使用 spring-spqr graphql-spqr-spring-boot-starter graphQL 的注释创建片段 - how to create fragments using Annotations of spring-spqr graphql-spqr-spring-boot-starter graphQL 使用 graphql-java-tools 和 graphql-spring-boot-starter 进行错误处理 - Error handling with graphql-java-tools and graphql-spring-boot-starter Spring 引导启动器 - RestTemplate - Spring Boot starter - RestTemplate 我们如何从 GraphQL 的 RequestContextHolder 中获取 GraphQL 的 HttpServletRequest(DefaultGlobalContext)(使用 graphql-spqr-spring-boot-starter)? - How can we get HttpServletRequest(DefaultGlobalContext) for GraphQL from RequestContextHolder for GraphQL (using graphql-spqr-spring-boot-starter)? 我可以将 HandshakeInterceptor 与 graphql-spring-boot-starter 一起使用来获取 Cookies 吗? - Can I use HandshakeInterceptor With graphql-spring-boot-starter To Get Cookies? 如何使用 spqr-spring-boot-starter 在 graphql 中获取模式文件? - How to get a schema file in graphql using spqr-spring-boot-starter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM