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
| Name | Type | Description |
|---|---|---|
| typeA | GraphQLType | The first GraphQL type to compare. |
| typeB | GraphQLType | The second GraphQL type to compare. |
Returns
| Type | Description |
|---|---|
boolean | True when the value matches this type. |
Example
import { isEqualType, GraphQLString } from 'graphql/type';
const result = isEqualType(GraphQLString);
// result: true for matching GraphQL typesisTypeSubTypeOf()
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
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| maybeSubType | GraphQLType | The possible subtype to compare. |
| superType | GraphQLType | The possible supertype to compare. |
Returns
| Type | Description |
|---|---|
boolean | True when the value matches this type. |
Example
import { isTypeSubTypeOf, GraphQLString } from 'graphql/type';
const result = isTypeSubTypeOf(GraphQLString);
// result: true for matching GraphQL typesdoTypesOverlap()
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
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| typeA | GraphQLCompositeType | The first GraphQL type to compare. |
| typeB | GraphQLCompositeType | The second GraphQL type to compare. |
Returns
| Type | Description |
|---|---|
boolean | True 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