graphql-java-annotations
graphql-java-annotations copied to clipboard
Any support for Map
Currently, the schema supports int
String
... Any plan for the support of Map
?
For the record you can register your own TypeFunctions into the system to gain access to Maps (or another type)
public static GraphQLScalarType GraphQLMap = new GraphQLScalarType("Map", "Coercing Map", new OutboundOnlyCoercing() {
@Override
public Object serialize(Object input) {
if (input instanceof Map) {
return input;
} else {
return null;
}
}
});
public static class MapTypeFunction extends AbstractTypeFunction {
MapTypeFunction() {
super(GraphQLMap, Collections.singletonList(Map.class));
}
}
static abstract class AbstractTypeFunction implements TypeFunction {
private final GraphQLType qlType;
private final Collection<Class<?>> acceptedTypes;
AbstractTypeFunction(GraphQLType qlType, Collection<Class<?>> acceptedTypes) {
this.qlType = qlType;
this.acceptedTypes = acceptedTypes;
}
@Override
public GraphQLType apply(Class<?> aClass, AnnotatedType annotatedType) {
return qlType;
}
@Override
public Collection<Class<?>> getAcceptedTypes() {
return acceptedTypes;
}
}
However I can see a point for the base library to allow Maps to be passed back out as a special type. After all its just a scalar that expands to being a object thing
TypeFunction seems to be deprecated. What is the new way to do this?
TypeFunction seems to be deprecated. What is the new way to do this?
That might be stupid question but how do you know TypeFunction is deprecated? From what I see this library heavily depends on graphql.annotations.processor.typeFunctions.TypeFunction to generate all scalars.
I was able to make the map work for me creating new TypeFunction for specific scalar object from graphql-java-extended-scalars library.
Hi @shishuwu,
We're helping with project maintenance and reviewing the list of opened PRs and Issues.
This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.
Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).
Thanks,