import { IntrospectionEnumType , IntrospectionField , IntrospectionInputObjectType , IntrospectionInterfaceType , IntrospectionInputTypeRef , IntrospectionInputValue , IntrospectionListTypeRef , IntrospectionNamedTypeRef , IntrospectionNonNullTypeRef , IntrospectionObjectType , IntrospectionOutputTypeRef , IntrospectionSchema , IntrospectionType , IntrospectionTypeRef , IntrospectionUnionType , IntrospectionScalarType , } from 'graphql' ; import { filter , has , startsWith , includes } from 'lodash' ; export const isIntrospectionField = ( type ) : type is IntrospectionField => has ( type , 'args' ) ; export const isIntrospectionInputValue = ( type ) : type is IntrospectionInputValue => has ( type , 'defaultValue' ) ; export const isIntrospectionListTypeRef = ( type ) : type is IntrospectionListTypeRef => type . kind === 'LIST' ; export const isIntrospectionObjectType = ( type ) : type is IntrospectionObjectType => type . kind === 'OBJECT' ; export const isIntrospectionInputObjectType = ( type ) : type is IntrospectionInputObjectType => type . kind === 'INPUT_OBJECT' ; export const isIntrospectionInterfaceType = ( type ) : type is IntrospectionInterfaceType => type . kind === 'INTERFACE' ; export const isIntrospectionEnumType = ( type ) : type is IntrospectionEnumType => type . kind === 'ENUM' ; export const isIntrospectionUnionType = ( type ) : type is IntrospectionUnionType => type . kind === 'UNION' ; export const isNonNullIntrospectionType = ( type ) : type is IntrospectionNonNullTypeRef < IntrospectionNamedTypeRef < IntrospectionType > > => type . kind === 'NON_NULL' ; export const isIntrospectionScalarType = ( type ) : type is IntrospectionScalarType => type . kind === 'SCALAR' ; export const isIntrospectionDefaultScalarType = ( type ) : type is IntrospectionScalarType => type . kind === 'SCALAR' && includes ( [ 'Boolean' , 'String' , 'Int' , 'Float' ] , type . name ) ; export interface FilterDefinitionsTypesOptions { ignoreInternals ? : boolean ; } export const filterDefinitionsTypes = ( types , opts ? ) : IntrospectionType [ ] => { const ignoreInternals = opts && opts . ignoreInternals ; return filter ( types , ( type ) => ( ( isIntrospectionObjectType ( type ) && ! ! type . fields ) || ( isIntrospectionInputObjectType ( type ) && ! ! type . inputFields ) || ( isIntrospectionInterfaceType ( type ) && ! ! type . fields ) || ( isIntrospectionEnumType ( type ) && ! ! type . enumValues ) || ( isIntrospectionUnionType ( type ) && ! ! type . possibleTypes ) || ( isIntrospectionScalarType ( type ) && ! ! type . name ) ) && ( ! ignoreInternals || ( ignoreInternals && ! startsWith ( type . name , '__' ) ) ) ) ; } ;