Search in sources :

Example 1 with TypeResolverProxy

use of graphql.schema.TypeResolverProxy in project graphql-java by graphql-java.

the class SchemaGenerator method getTypeResolverForUnion.

@SuppressWarnings("Duplicates")
private TypeResolver getTypeResolverForUnion(BuildContext buildCtx, UnionTypeDefinition unionType) {
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    RuntimeWiring wiring = buildCtx.getWiring();
    WiringFactory wiringFactory = wiring.getWiringFactory();
    TypeResolver typeResolver;
    UnionWiringEnvironment environment = new UnionWiringEnvironment(typeRegistry, unionType);
    if (wiringFactory.providesTypeResolver(environment)) {
        typeResolver = wiringFactory.getTypeResolver(environment);
        assertNotNull(typeResolver, "The WiringFactory indicated it union provides a type resolver but then returned null");
    } else {
        typeResolver = wiring.getTypeResolvers().get(unionType.getName());
        if (typeResolver == null) {
            // this really should be checked earlier via a pre-flight check
            typeResolver = new TypeResolverProxy();
        }
    }
    return typeResolver;
}
Also used : TypeResolver(graphql.schema.TypeResolver) TypeResolverProxy(graphql.schema.TypeResolverProxy)

Example 2 with TypeResolverProxy

use of graphql.schema.TypeResolverProxy in project graphql-java by graphql-java.

the class SchemaGenerator method getTypeResolverForInterface.

@SuppressWarnings("Duplicates")
private TypeResolver getTypeResolverForInterface(BuildContext buildCtx, InterfaceTypeDefinition interfaceType) {
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    RuntimeWiring wiring = buildCtx.getWiring();
    WiringFactory wiringFactory = wiring.getWiringFactory();
    TypeResolver typeResolver;
    InterfaceWiringEnvironment environment = new InterfaceWiringEnvironment(typeRegistry, interfaceType);
    if (wiringFactory.providesTypeResolver(environment)) {
        typeResolver = wiringFactory.getTypeResolver(environment);
        assertNotNull(typeResolver, "The WiringFactory indicated it provides a interface type resolver but then returned null");
    } else {
        typeResolver = wiring.getTypeResolvers().get(interfaceType.getName());
        if (typeResolver == null) {
            // this really should be checked earlier via a pre-flight check
            typeResolver = new TypeResolverProxy();
        }
    }
    return typeResolver;
}
Also used : TypeResolver(graphql.schema.TypeResolver) TypeResolverProxy(graphql.schema.TypeResolverProxy)

Aggregations

TypeResolver (graphql.schema.TypeResolver)2 TypeResolverProxy (graphql.schema.TypeResolverProxy)2