Search in sources :

Example 1 with Cat

use of graphql.GarfieldSchema.Cat in project graphql-java by graphql-java.

the class ReadmeExamples method unionType.

void unionType() {
    TypeResolver typeResolver = new TypeResolver() {

        @Override
        public GraphQLObjectType getType(TypeResolutionEnvironment env) {
            if (env.getObject() instanceof Cat) {
                return CatType;
            }
            if (env.getObject() instanceof Dog) {
                return DogType;
            }
            return null;
        }
    };
    GraphQLUnionType PetType = newUnionType().name("Pet").possibleType(CatType).possibleType(DogType).build();
    GraphQLCodeRegistry codeRegistry = newCodeRegistry().typeResolver("Pet", typeResolver).build();
}
Also used : GraphQLUnionType(graphql.schema.GraphQLUnionType) TypeResolver(graphql.schema.TypeResolver) Cat(graphql.GarfieldSchema.Cat) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) TypeResolutionEnvironment(graphql.TypeResolutionEnvironment) Dog(graphql.GarfieldSchema.Dog)

Aggregations

Cat (graphql.GarfieldSchema.Cat)1 Dog (graphql.GarfieldSchema.Dog)1 TypeResolutionEnvironment (graphql.TypeResolutionEnvironment)1 GraphQLCodeRegistry (graphql.schema.GraphQLCodeRegistry)1 GraphQLUnionType (graphql.schema.GraphQLUnionType)1 TypeResolver (graphql.schema.TypeResolver)1