[英]Validation error of type SubSelectionRequired: Sub selection required for type Timestamp of field
I use GraphQL-SPQR Library The problem is "Validation error of type SubSelectionRequired: Sub selection required for type Timestamp" Maybe there is expression in query for timestamp or format in Entity我使用 GraphQL-SPQR 库问题是“SubSelectionRequired 类型的验证错误:Timestamp 类型需要子选择”也许在查询中存在对 Entity 中的时间戳或格式的表达式
{"query":
"{findUserPointByUserId(userId:73){rowNum userAccountPointUserId totalPoint pointTypeDescription point userAccountCreatedDate} findUserAccountImgByUserId(userId:73){imageId,userId,presentImgNum}}"
}
Error错误
{
"errors": [
{
"message": "Validation error of type SubSelectionRequired: Sub selection required for type Timestamp of field userAccountCreatedDate",
"locations": [
{
"line": 1,
"column": 103
}
]
}
]
}
Entity实体
@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;
Service服务
public List<ViewUserAccountPoint> findUserPointByUserId(@GraphQLArgument(name = "userId") Integer userId){
return viewUserAccountPointRepository.findByUserAccountPointUserIdOrderByUserAccountCreatedDateDesc(userId);
}
Controller控制器
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();
}
I search through all query timestamp format However, i couldn't find i hope to hear the solution.我搜索了所有查询时间戳格式但是,我找不到我希望听到解决方案。 thank you
谢谢你
For one reason or another, Timestamp
got mapped incorrectly.出于某种原因,
Timestamp
被错误地映射。 It ended up being an object and not a scalar.它最终成为一个对象而不是标量。 As mentioned in the issue you opened , it's unclear where is
Timestamp
in your code coming from.正如您在打开的问题中提到的,目前还不清楚您的代码中的
Timestamp
来自哪里。
java.sql.Timestamp
is supported out of the box in recent versions of GraphQL SPQR, so you might be on an older version. GraphQL SPQR 的最新版本支持
java.sql.Timestamp
,因此您可能使用的是旧版本。
If that's not the case, it would mean Timestamp
is some other than java.sql.Timestamp
, and you'd need to register a custom mapper for it.如果不是这种情况,则意味着
Timestamp
不是java.sql.Timestamp
,您需要为它注册一个自定义映射器。
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);
}
}
Then register your mapper:然后注册您的映射器:
generator.withTypeMappers(new TimestampMapper())
对于我的情况,这是不正确的查询正文,请确保您拥有正确的查询正文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.