You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot集成graphql-java使用BigDecimal标量提示类型不存在如何解决

Spring GraphQL 内置BigDecimal标量配置方案
  1. 保留你已经在schema.graphqls中添加的scalar BigDecimal声明,该声明是Schema识别自定义标量的前提。
  2. 新增配置类手动注册graphql-java内置的BigDecimal标量为Spring Bean,官方实验性starter会自动识别所有GraphQLScalarType类型的Bean,和Schema中声明的同名标量完成绑定:
import graphql.scalars.ExtendedScalars;
import graphql.schema.GraphQLScalarType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GraphQLCustomScalarConfig {
    @Bean
    public GraphQLScalarType bigDecimal() {
        return ExtendedScalars.GraphQLBigDecimal;
    }
}

验证说明

重启项目后即可正常使用BigDecimal类型的字段,不会再报类型不存在的错误。如果后续需要使用GraphQL Java内置的其他扩展标量(如Long、非负整数、日期时间等),都可以通过相同的方式注册对应ExtendedScalars下的标量Bean即可。

内容的提问来源于stack exchange,提问作者Bob Kuhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 13:51:02