import { buildSchema , InterfaceType , ObjectType } from '@apollo/federation-internals' ; import { buildQueryGraph , Edge , FieldCollection , QueryGraph , Vertex } from '@apollo/query-graphs' ; export function testGraphFromSchemaString ( schemaSDL ) { return buildQueryGraph ( "test" , buildSchema ( schemaSDL ) ) ; } function singleEdge ( graph , vertex , fieldName ) { const type = vertex . type as ( ObjectType | InterfaceType ) ; const f = type . field ( fieldName ) ; expect ( f ) . toBeDefined ( ) ; const edges = graph . outEdges ( vertex ) . filter ( e => e . matchesSupergraphTransition ( graph . sources . get ( vertex . source ) ! , new FieldCollection ( f ! ) ) ) ; expect ( edges . length ) . toBe ( 1 ) ; return edges [ 0 ] ; } export function namedEdges ( graph , vertex , ... fieldNames ) { const edges = graph . outEdges ( vertex ) ; return fieldNames . map ( name => { const edge = singleEdge ( graph , vertex , name ) ; expect ( edges [ edge . index ] ) . toBe ( edge ) ; expect ( edge . head ) . toBe ( vertex ) ; const type = vertex . type as ( ObjectType | InterfaceType ) ; const f = type . field ( name ) ; expect ( f ) . toBeDefined ( ) ; expect ( edge . transition ) . toStrictEqual ( new FieldCollection ( f ! ) ) ; return edge ; } ) ; }