graphql-java-annotations icon indicating copy to clipboard operation
graphql-java-annotations copied to clipboard

Any support for Map

Open shishuwu opened this issue 7 years ago • 3 comments

Currently, the schema supports int String... Any plan for the support of Map?

shishuwu avatar Feb 09 '17 02:02 shishuwu

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

bbakerman avatar Feb 17 '17 08:02 bbakerman

TypeFunction seems to be deprecated. What is the new way to do this?

xetra11 avatar May 14 '18 09:05 xetra11

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.

myszon01 avatar May 05 '20 16:05 myszon01

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,

Fgerthoffert avatar Jun 02 '23 08:06 Fgerthoffert