Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error of type SubSelectionRequired: Sub selection required for type Timestamp of field #251

Closed
JieunSon96 opened this issue May 2, 2019 · 5 comments

Comments

@JieunSon96
Copy link

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

`{"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

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

I use @GraphQLQuery is there annotation for timestamp format??

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

I search through all query timestamp format However, i couldn't find
hope to hear the solution. thank you

@codelizrd
Copy link

The timestamp object is treated as an object/entity and it does not have any (exposed) members; that's why.

You either need to expose members within the Timestamp object, or create and register a custom TypeMapper that convert between your Timestamp types and a scalar like an integer (so in your schema the ViewUserAccountPoint entity has an userAccountCreatedDate which is an integer).

@kaqqao
Copy link
Member

kaqqao commented May 2, 2019

@codelizrd is right. If Timestamp gets mapped incorrectly, you must register a custom TypeMapper. Look at ScalarMapper for inspiration.

But, is Timestamp a standard type? You didn't list your imports so I can't tell which package it's coming from.
If it's standard, I'll gladly add support for it out of the box.

@kaqqao
Copy link
Member

kaqqao commented May 4, 2019

Now that I look, if your Timestamp is java.sql.Timestamp it is already supported out of the box.
Are you on the latest version?

I also now see that Timestamp can (and thus should) be in UTC time zone (unlike java.sql.Date). I'm changing this for the following release. This is a breaking change.

kaqqao added a commit that referenced this issue May 4, 2019
@kaqqao
Copy link
Member

kaqqao commented May 5, 2019

Answered your StackOverflow question as well.

Quoting:

For one reason or another, Timestamp got mapped incorrectly. 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.

java.sql.Timestamp is supported out of the box in recent versions of GraphQL SPQR, so you might be on an older version.

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.

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

@kaqqao
Copy link
Member

kaqqao commented May 21, 2019

I'll close this one since there's no feedback and it seems sufficiently addressed.
If you have further questions, feel free to reopen.

@kaqqao kaqqao closed this as completed May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants