I want to introduce a scalar type to the graphql scheme and provide resolver for it.
I believe what I need to do is to provide the corresponding resolver for the new type as described here
I use spring boot starter to implement the server.
com.graphql-java:graphql-spring-boot-starter:5.0.2
There is schema.graphqls
:
type Query {
pets(last: Int): [Pet]
}
type Pet {
id: ID
name: String
}
and QueryResolver
:
@Component
public class Query implements GraphQLQueryResolver {
@Autowired
PetStore petStore;
public Pet pet(long id) {
return petStore.pet(id);
}
public List<Pet> pets(Integer last) {
return petStore.pets().stream()
.limit(last != null ? last : Integer.MAX_VALUE)
.collect(Collectors.toList());
}
}
I believe that there is a way to update a scheme like this:
type Pet {
id: ID
name: String
dateOfBirth: LocalDateTime
}
scalar LocalDateTime
and provide resolver to define how new field value should be processed, like this:
@Component
public class DateResolver extends GraphQLScalarType {
// serialize/deserialize logic
}
Unfochinatly I get following exception:
com.coxautodev.graphql.tools.SchemaClassScannerError: Expected a user-defined GraphQL scalar type with name 'LocalDateTime' but found none!