v16 APIgraphql/utilitiesType Comparisons

graphql/utilities/type-comparisons

Functions

isEqualType()

Provided two types, return true if the types are equal (invariant).

Signature:

isEqualType(typeA: GraphQLType, typeB: GraphQLType): boolean

Arguments

NameTypeDescription
typeAGraphQLTypeThe first GraphQL type to compare.
typeBGraphQLTypeThe second GraphQL type to compare.

Returns

TypeDescription
booleanTrue when the value matches this type.

Example

import { isEqualType, GraphQLString } from 'graphql/type';
 
const result = isEqualType(GraphQLString);
 
// result: true for matching GraphQL types

isTypeSubTypeOf()

Provided a type and a super type, return true if the first type is either equal or a subset of the second super type (covariant).

Signature:

isTypeSubTypeOf(schema: GraphQLSchema, maybeSubType: GraphQLType, superType: GraphQLType): boolean

Arguments

NameTypeDescription
schemaGraphQLSchemaThe GraphQL schema to use.
maybeSubTypeGraphQLTypeThe possible subtype to compare.
superTypeGraphQLTypeThe possible supertype to compare.

Returns

TypeDescription
booleanTrue when the value matches this type.

Example

import { isTypeSubTypeOf, GraphQLString } from 'graphql/type';
 
const result = isTypeSubTypeOf(GraphQLString);
 
// result: true for matching GraphQL types

doTypesOverlap()

Provided two composite types, determine if they “overlap”. Two composite types overlap when the Sets of possible concrete types for each intersect.

This is often used to determine if a fragment of a given type could possibly be visited in a context of another type.

This function is commutative.

Signature:

doTypesOverlap(schema: GraphQLSchema, typeA: GraphQLCompositeType, typeB: GraphQLCompositeType): boolean

Arguments

NameTypeDescription
schemaGraphQLSchemaThe GraphQL schema to use.
typeAGraphQLCompositeTypeThe first GraphQL type to compare.
typeBGraphQLCompositeTypeThe second GraphQL type to compare.

Returns

TypeDescription
booleanTrue when the two composite types can apply to at least one common object type.

Example

import { doTypesOverlap } from 'graphql/utilities';
 
const result = doTypesOverlap(schema, typeA, typeB);
 
// result contains the doTypesOverlap return value