Aleksandr Savvopulo
Aleksandr Savvopulo

Reputation: 157

Overriding standard ID scalar

I want to use UUID as an identifier but standard scalar ID is coerced as string. So have to parse uuid from string everywhere I use ID type.

I wonder is it possible to override ID type with my own implementation? This scalar type has some special meaning or I can just use my own scalar called UUID as identifier?

Upvotes: 4

Views: 1367

Answers (1)

Deepak Patankar
Deepak Patankar

Reputation: 3302

We can not override the available scalers, please refer this link for discussion.

You can define a UUIDScalar in your code, for the same you will have to override the following methods

@Override
public Object serialize(Object dataFetcherResult) {
    //
}

@Override
public Object parseValue(Object input) {
    //
}

@Override
public Object parseLiteral(Object input) {
    //
}

Reference: Making custom scalars in graphql java

Luckily the code for making custom scalar for UUID is available online, you can use this PR

Upvotes: 2

Related Questions