All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.schema.GraphqlTypeBuilder Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.schema;

import com.google.common.collect.ImmutableList;
import graphql.Internal;

import java.util.Comparator;
import java.util.List;
import java.util.Map;

import static graphql.util.FpKit.valuesToList;

@SuppressWarnings("unchecked")
@Internal
public abstract class GraphqlTypeBuilder> {

    protected String name;
    protected String description;
    protected GraphqlTypeComparatorRegistry comparatorRegistry = GraphqlTypeComparatorRegistry.AS_IS_REGISTRY;

    public B name(String name) {
        this.name = name;
        return (B) this;
    }

    public B description(String description) {
        this.description = description;
        return (B) this;
    }

    public B comparatorRegistry(GraphqlTypeComparatorRegistry comparatorRegistry) {
        this.comparatorRegistry = comparatorRegistry;
        return (B) this;
    }


     List sort(Map types, Class parentType, Class elementType) {
        return sort(valuesToList(types), parentType, elementType);
    }

     List sort(List types, Class parentType, Class elementType) {
        Comparator comparator = getComparatorImpl(comparatorRegistry, parentType, elementType);
        return ImmutableList.copyOf(GraphqlTypeComparators.sortTypes(comparator, types));
    }

    Comparator getComparator(Class parentType, Class elementType) {
        return getComparatorImpl(comparatorRegistry, parentType, elementType);
    }

    private static Comparator getComparatorImpl(GraphqlTypeComparatorRegistry comparatorRegistry, Class parentType, Class elementType) {
        GraphqlTypeComparatorEnvironment environment = GraphqlTypeComparatorEnvironment.newEnvironment()
                .parentType(parentType)
                .elementType(elementType)
                .build();
        return comparatorRegistry.getComparator(environment);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy