【问题标题】:Graphql java spring boot -- Scalar type error -- There is no scalar implementation for the named 'XXX' scalar typeGraphql java spring boot - 标量类型错误 - 没有命名'XXX'标量类型的标量实现
【发布时间】:2022-07-30 19:38:30
【问题描述】:

我想做标量类型会报错 即使我使用扩展标量,它也根本不起作用。

  • 版本:

弹簧启动:2.7.0

    <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>graphql-spring-boot-starter</artifactId>
        <version>12.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>graphql-java-tools</artifactId>
        <version>12.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphiql-spring-boot-starter</artifactId>
        <version>5.0.2</version>
    </dependency>
  • 代码
@Configuration
public class Conf {

    @Bean
    public GraphQLScalarType graphQLLong() {
        return ExtendedScalars.GraphQLLong;
    }
}
Caused by: SchemaProblem{errors=[There is no scalar implementation for the named  'Long' scalar type]}
  • Schema 结构(很简单的一种)
scalar Long

type Mutation {

}
  • yml 配置

那么我丢失了什么配置?

【问题讨论】:

  • 您的架构是什么样的?
  • 我用一个很简单的模式来测试
  • 我把它添加到我的问题中

标签: java spring-boot graphql


【解决方案1】:

包含graphql-java-extended-scalars 依赖:

https://github.com/graphql-java/graphql-java-extended-scalars

并确保在您使用的 @Configuration 课程中:

@Bean
public graphql.schema.GraphQLScalarType extendedScalarLong() {
    return graphql.scalars.ExtendedScalars.GraphQLLong;
}

此外,如果您将 ExtendedScalar 定义为 @Bean,则无需在 graphql.extended-scalars 属性中指定它。

【讨论】:

    【解决方案2】:

    使用这个: @豆 公共 RuntimeWiringConfigurer runtimeWiringConfigurer() { 返回接线构建器->接线构建器.scalar(ExtendedScalars.GraphQLLong); }

    而不是: @豆 公共 GraphQLScalarType graphQLLong() { 返回 ExtendedScalars.GraphQLlong; }

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 1970-01-01
      • 2021-05-14
      • 2021-05-04
      • 1970-01-01
      • 2019-12-06
      • 2019-10-12
      • 2022-07-02
      相关资源
      最近更新 更多