import { TypeConfig , TypeConfigMap } from './TypeConfig' ; import { TypeKind } from './TypeKind' ; import { ObjectTypeConfig } from './ObjectTypeConfig' ; import { InputObjectTypeConfig } from './InputObjectTypeConfig' ; import { InterfaceTypeConfig } from './InterfaceTypeConfig' ; import { ScalarTypeConfig } from './ScalarTypeConfig' ; import { UnionTypeConfig } from './UnionTypeConfig' ; class AssertionError extends Error { } export function isObjectTypeConfig ( type ) { return type . kind === TypeKind . OBJECT ; } export function isInputObjectTypeConfig ( type ) { return type . kind === TypeKind . INPUT_OBJECT ; } export function isInterfaceTypeConfig ( type ) { return type . kind === TypeKind . INTERFACE ; } export function isScalarTypeConfig ( type ) { return type . kind === TypeKind . SCALAR ; } export function isUnionTypeConfig ( type ) { return type . kind === TypeKind . UNION ; } export function isNode ( type ) { return type . kind === TypeKind . OBJECT && ( type . interfaces || [ ] ) . includes ( 'Node' ) ; } export function isContent ( type ) { return type . kind === TypeKind . OBJECT && ( type . interfaces || [ ] ) . includes ( 'Content' ) ; } export function isContentUnion ( type , typeMap ) { if ( type . kind !== TypeKind . UNION ) { return false ; } for ( const typeName of type . typeNames ) { const subTypeConfig = typeMap [ typeName ] ; if ( ! subTypeConfig || ! isContent ( subTypeConfig ) ) { return false ; } } return true ; } export function isTypeConfigWithFields ( type ) { return isInterfaceTypeConfig ( type ) || isObjectTypeConfig ( type ) || isInputObjectTypeConfig ( type ) ; } export function assertObjectTypeConfig ( type ) { if ( isObjectTypeConfig ( type ) ) { return type ; } else { throw new AssertionError ( 'Type is not of type ObjectTypeConfig' ) ; } } export function assertInputObjectTypeConfig ( type ) { if ( isInputObjectTypeConfig ( type ) ) { return type ; } else { throw new AssertionError ( 'Type is not of type InputObjectTypeConfig' ) ; } } export function assertInterfaceTypeConfig ( type ) { if ( isInterfaceTypeConfig ( type ) ) { return type ; } else { throw new AssertionError ( 'Type is not of type InterfaceTypeConfig' ) ; } } export function assertScalarTypeConfig ( type ) { if ( isScalarTypeConfig ( type ) ) { return type ; } else { throw new AssertionError ( 'Type is not of type ScalarTypeConfig' ) ; } } export function assertUnionTypeConfig ( type ) { if ( isUnionTypeConfig ( type ) ) { return type ; } else { throw new AssertionError ( 'Type is not of type UnionTypeConfig' ) ; } }