typeResolvers

Contents

Set or override the type resolver for a union or interface.

Usage

Add functions to the typeResolvers property returned by your extension function. Each key names an interface or union, and its function returns the name of the concrete GraphQL object type for a value.

import type {Extensions} from '@enonic-types/guillotine';

interface UnionValue {
    title?: string;
}

export const extensions = (): Extensions => ({
    typeResolvers: {
        CustomInterface: () => 'CustomInterfaceImpl',
        CustomUnion: (obj: UnionValue): string => {
            return obj.title ? 'GraphQLTypeNameOne' : 'GraphQLTypeNameTwo';
        },
    },
});

The interface, union and returned object types must exist in the schema. Merge these resolvers with the definitions from Interfaces, Types and Unions, replacing the example names with your own.


Contents

Contents