首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型SubSelectionRequired的验证错误:字段的类型Timestamp需要子选择

类型SubSelectionRequired的验证错误:字段的类型Timestamp需要子选择
EN

Stack Overflow用户
提问于 2019-05-02 09:14:41
回答 2查看 3.6K关注 0票数 0

我使用的是GraphQL-SPQR Library,问题是“SubSelectionRequired类型的验证错误:类型timestamp需要子选择”可能在查询timestamp或Entity中的格式中有表达式

代码语言:javascript
复制
{"query":
"{findUserPointByUserId(userId:73){rowNum userAccountPointUserId totalPoint pointTypeDescription point userAccountCreatedDate} findUserAccountImgByUserId(userId:73){imageId,userId,presentImgNum}}"


}

错误

代码语言:javascript
复制
{
    "errors": [
        {
            "message": "Validation error of type SubSelectionRequired: Sub selection required for type Timestamp of field userAccountCreatedDate",
            "locations": [
                {
                    "line": 1,
                    "column": 103
                }
            ]
        }
    ]
}

实体

代码语言:javascript
复制
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "view_user_account_point", schema = "public", catalog = "corus")
public class ViewUserAccountPoint {
    @Id
    @Basic
    @GraphQLQuery(name = "rowNum")
    @Column(name = "row_num", nullable = true)
    private Long rowNum;

    @Basic
    @Column(name = "user_account_point_userid", nullable = true)
    @GraphQLQuery(name = "userAccountPointUserId")
    private Integer userAccountPointUserId;

    @Basic
    @Column(name = "subject_id", nullable = true)
    @GraphQLQuery(name = "subjectId")
    private Integer subjectId;

    @Basic
    @Column(name = "point", nullable = true)
    @GraphQLQuery(name = "point")
    private Integer point;

    @Basic
    @Column(name = "user_account_point_typeid", nullable = true)
    @GraphQLQuery(name = "userAccountPointTypeId")
    private Integer userAccountPointTypeId;

    @Basic
    @Column(name = "date_created", nullable = true)
    @GraphQLQuery(name = "userAccountCreatedDate")
    private Timestamp userAccountCreatedDate;

服务

代码语言:javascript
复制
public List<ViewUserAccountPoint> findUserPointByUserId(@GraphQLArgument(name = "userId") Integer userId){
        return viewUserAccountPointRepository.findByUserAccountPointUserIdOrderByUserAccountCreatedDateDesc(userId);
    }

控制器

代码语言:javascript
复制
 private final GraphQL graphQL;

    public UserController(UserAccountService userAccountService) {
        GraphQLSchema schema = new GraphQLSchemaGenerator()
                .withResolverBuilders(
                        //Resolve by annotations
                        new AnnotatedResolverBuilder())
                .withOperationsFromSingleton(userAccountService,UserAccountService.class)
                .withValueMapperFactory(new JacksonValueMapperFactory())
                .generate();
        graphQL = GraphQL.newGraphQL(schema).build();
    }

    @PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Map<String, Object> graphql(@RequestBody Map<String, String> request, HttpServletRequest raw) {
        ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput()
                .query(request.get("query"))
                .operationName(request.get("operationName"))
                .context(raw)
                .build());
        return executionResult.toSpecification();
    }

我搜索了所有的查询时间戳格式,但是我找不到我希望听到的解决方案。谢谢

EN

回答 2

Stack Overflow用户

发布于 2019-05-05 08:10:57

由于这样或那样的原因,Timestamp映射不正确。它最终是一个对象,而不是一个标量。正如在the issue you opened中提到的,不清楚代码中的Timestamp来自何处。

在GraphQL的最新版本中,java.sql.Timestampsupported out of the box,所以您可能使用的是较旧的版本。

如果不是这样,就意味着Timestamp不是java.sql.Timestamp,您需要为它注册一个自定义映射器。

代码语言:javascript
复制
public class TimestampMapper implements TypeMapper {

    // Define the scalar as needed, see io.leangen.graphql.util.Scalars for inspiration
    private static final GraphQLScalarType TIMESTAMP = ...;

    @Override
    public GraphQLOutputType toGraphQLType(AnnotatedType javaType, OperationMapper operationMapper, Set<Class<? extends TypeMapper>> mappersToSkip, BuildContext buildContext) {
        return TIMESTAMP; //it's important to always return the same instance
    }

    @Override
    public GraphQLInputType toGraphQLInputType(AnnotatedType javaType, OperationMapper operationMapper, Set<Class<? extends TypeMapper>> mappersToSkip, BuildContext buildContext) {
        return TIMESTAMP; //same as above
    }

    @Override
    public boolean supports(AnnotatedType type) {
        return ClassUtils.isSuperClass(Timestamp.class, type);
    }
}

然后注册您的映射器:

代码语言:javascript
复制
generator.withTypeMappers(new TimestampMapper())
票数 0
EN

Stack Overflow用户

发布于 2020-02-11 09:26:58

对于我的案例,这是错误的查询正文,请确保您有正确的正文。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55944508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档