Search in sources :

Example 1 with ElideTypeConverter

use of com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter in project elide by yahoo.

the class GraphQLConversionUtils method registerCustomScalars.

private void registerCustomScalars() {
    CoerceUtil.getSerdes().forEach((type, serde) -> {
        SerdeCoercing<?, ?> serdeCoercing = new SerdeCoercing<>(ERROR_MESSAGE, serde);
        ElideTypeConverter elideTypeConverter = serde.getClass().getAnnotation(ElideTypeConverter.class);
        String name = elideTypeConverter != null ? elideTypeConverter.name() : type.getSimpleName();
        String description = elideTypeConverter != null ? elideTypeConverter.description() : type.getSimpleName();
        scalarMap.put(ClassType.of(type), GraphQLScalarType.newScalar().name(name).description(description).coercing(serdeCoercing).build());
    });
}
Also used : ElideTypeConverter(com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter)

Example 2 with ElideTypeConverter

use of com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter in project elide by yahoo.

the class Elide method registerCustomSerde.

protected void registerCustomSerde() {
    Injector injector = elideSettings.getDictionary().getInjector();
    Set<Class<?>> classes = registerCustomSerdeScan();
    for (Class<?> clazz : classes) {
        if (!Serde.class.isAssignableFrom(clazz)) {
            log.warn("Skipping Serde registration (not a Serde!): {}", clazz);
            continue;
        }
        Serde serde = (Serde) injector.instantiate(clazz);
        injector.inject(serde);
        ElideTypeConverter converter = clazz.getAnnotation(ElideTypeConverter.class);
        Class baseType = converter.type();
        registerCustomSerde(baseType, serde, converter.name());
        for (Class type : converter.subTypes()) {
            if (!baseType.isAssignableFrom(type)) {
                throw new IllegalArgumentException("Mentioned type " + type + " not subtype of " + baseType);
            }
            registerCustomSerde(type, serde, converter.name());
        }
    }
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Injector(com.yahoo.elide.core.dictionary.Injector) ElideTypeConverter(com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter)

Aggregations

ElideTypeConverter (com.yahoo.elide.core.utils.coerce.converters.ElideTypeConverter)2 Injector (com.yahoo.elide.core.dictionary.Injector)1 Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)1