import { Types } from '@graphql-codegen/plugin-helpers' ; import { isDocumentNode } from '@graphql-tools/utils' ; import { DocumentNode , GraphQLSchema , isSchema , Kind } from 'graphql' ; export function isObjectMap ( obj ) { return obj && typeof obj === 'object' && ! Array . isArray ( obj ) ; } export function prioritize < T > ( ... values ) { const picked = values . find ( val => typeof val === 'boolean' ) ; if ( typeof picked !== 'boolean' ) { return values [ values . length - 1 ] ; } return picked ; } export function pickFlag < TConfig , TKey extends keyof TConfig > ( flag , config ) { return isObjectMap ( config ) ? config [ flag ] : undefined ; } export function shouldValidateDuplicateDocuments ( skipDocumentsValidationOption ) { if ( skipDocumentsValidationOption === true ) { return false ; } if ( typeof skipDocumentsValidationOption === 'object' && skipDocumentsValidationOption . skipDuplicateValidation ) { return false ; } return true ; } export function shouldValidateDocumentsAgainstSchema ( skipDocumentsValidationOption ) { if ( skipDocumentsValidationOption === true ) { return false ; } if ( typeof skipDocumentsValidationOption === 'object' && skipDocumentsValidationOption . skipValidationAgainstSchema ) { return false ; } return true ; } export function getSkipDocumentsValidationOption ( options ) { if ( options . skipDocumentsValidation ) { return options . skipDocumentsValidation ; } const flagFromConfig = pickFlag ( 'skipDocumentsValidation' , options . config ) ; if ( flagFromConfig ) { return flagFromConfig ; } return false ; } const federationDirectives = [ 'key' , 'requires' , 'provides' , 'external' ] ; export function hasFederationSpec ( schemaOrAST ) { if ( isSchema ( schemaOrAST ) ) { return federationDirectives . some ( directive => schemaOrAST . getDirective ( directive ) ) ; } else if ( isDocumentNode ( schemaOrAST ) ) { return schemaOrAST . definitions . some ( def => def . kind === Kind . DIRECTIVE_DEFINITION && federationDirectives . includes ( def . name . value ) ) ; } return false ; }