Ошибка проверки типа SubSelectionRequired: требуется дополнительный выбор для типа Timestamp поля - PullRequest
0 голосов
/ 02 мая 2019

Я использую библиотеку GraphQL-SPQR. Проблема заключается в том, что «ошибка проверки типа SubSelectionRequired: требуется дополнительный выбор для типа отметки времени».*

{
    "errors": [
        {
            "message": "Validation error of type SubSelectionRequired: Sub selection required for type Timestamp of field userAccountCreatedDate",
            "locations": [
                {
                    "line": 1,
                    "column": 103
                }
            ]
        }
    ]
}

Сущность

@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;

Служба

public List<ViewUserAccountPoint> findUserPointByUserId(@GraphQLArgument(name = "userId") Integer userId){
        return viewUserAccountPointRepository.findByUserAccountPointUserIdOrderByUserAccountCreatedDateDesc(userId);
    }

Контроллер

 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();
    }

Я ищу по всему формату отметки времени запроса Однако я не смогнайти, я надеюсь услышать решение.спасибо

1 Ответ

0 голосов
/ 05 мая 2019

По тем или иным причинам Timestamp отображен неправильно.В итоге это был объект, а не скаляр.Как уже упоминалось в проблеме, которую вы открыли , неясно, откуда в вашем коде Timestamp.

java.sql.Timestamp поддерживается из коробки в последнее времяверсии GraphQL SPQR, поэтому вы можете использовать более старую версию.

Если это не так, это будет означать, что 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);
    }
}

Затем зарегистрируйте свой картограф:

generator.withTypeMappers(new TimestampMapper())
...