@@ -13,7 +13,13 @@ import {
1313 SequenceNode ,
1414 serializeQueryPlan ,
1515} from '../QueryPlan' ;
16- import { FieldNode , OperationDefinitionNode , parse , validate , GraphQLError } from 'graphql' ;
16+ import {
17+ FieldNode ,
18+ OperationDefinitionNode ,
19+ parse ,
20+ validate ,
21+ GraphQLError ,
22+ } from 'graphql' ;
1723import {
1824 composeAndCreatePlanner ,
1925 composeAndCreatePlannerWithOptions ,
@@ -5048,101 +5054,99 @@ describe('Named fragments preservation', () => {
50485054 name : 'subgraph1' ,
50495055 typeDefs : gql `
50505056 type Query {
5051- theEntity: AnyEntity
5057+ theEntity: AnyEntity
50525058 }
50535059
50545060 union AnyEntity = EntityTypeA | EntityTypeB
50555061
50565062 type EntityTypeA @key(fields: "unifiedEntityId") {
5057- unifiedEntityId: ID!
5058- unifiedEntity: UnifiedEntity
5063+ unifiedEntityId: ID!
5064+ unifiedEntity: UnifiedEntity
50595065 }
50605066
50615067 type EntityTypeB @key(fields: "unifiedEntityId") {
5062- unifiedEntityId: ID!
5063- unifiedEntity: UnifiedEntity
5068+ unifiedEntityId: ID!
5069+ unifiedEntity: UnifiedEntity
50645070 }
50655071
50665072 interface UnifiedEntity {
5067- id: ID!
5073+ id: ID!
50685074 }
50695075
5070- type Generic implements UnifiedEntity @key(fields: "id"){
5071- id: ID!
5076+ type Generic implements UnifiedEntity @key(fields: "id") {
5077+ id: ID!
50725078 }
50735079
50745080 type Movie implements UnifiedEntity @key(fields: "id") {
5075- id: ID!
5081+ id: ID!
50765082 }
50775083
50785084 type Show implements UnifiedEntity @key(fields: "id") {
5079- id: ID!
5085+ id: ID!
50805086 }
5081- ` ,
5087+ ` ,
50825088 } ;
50835089
50845090 const subgraph2 = {
50855091 name : 'subgraph2' ,
50865092 typeDefs : gql `
50875093 interface Video {
5088- videoId: Int!
5089- taglineMessage(uiContext: String): String
5094+ videoId: Int!
5095+ taglineMessage(uiContext: String): String
50905096 }
50915097
50925098 interface UnifiedEntity {
5093- id: ID!
5099+ id: ID!
50945100 }
50955101
50965102 type Generic implements UnifiedEntity @key(fields: "id") {
5097- id: ID!
5098- taglineMessage(uiContext: String): String
5103+ id: ID!
5104+ taglineMessage(uiContext: String): String
50995105 }
51005106
51015107 type Movie implements UnifiedEntity & Video @key(fields: "id") {
5102- videoId: Int!
5103- id: ID!
5104- taglineMessage(uiContext: String): String
5108+ videoId: Int!
5109+ id: ID!
5110+ taglineMessage(uiContext: String): String
51055111 }
51065112
51075113 type Show implements UnifiedEntity & Video @key(fields: "id") {
5108- videoId: Int!
5109- id: ID!
5110- taglineMessage(uiContext: String): String
5114+ videoId: Int!
5115+ id: ID!
5116+ taglineMessage(uiContext: String): String
51115117 }
5112- ` ,
5118+ ` ,
51135119 } ;
51145120
5115- const [ api , queryPlanner ] = composeAndCreatePlannerWithOptions ( [ subgraph1 , subgraph2 ] ,
5116- { reuseQueryFragments : true } ) ;
5121+ const [ api , queryPlanner ] = composeAndCreatePlannerWithOptions (
5122+ [ subgraph1 , subgraph2 ] ,
5123+ { reuseQueryFragments : true } ,
5124+ ) ;
51175125
51185126 let query = gql `
51195127 query Search {
5120- theEntity {
5121- ... on EntityTypeA {
5122- unifiedEntity {
5123- ... on Generic {
5124- taglineMessage(uiContext: "Generic")
5125- }
5126- }
5127- }
5128- ... on EntityTypeB {
5129- unifiedEntity {
5130- ...VideoSummary
5131- }
5128+ theEntity {
5129+ ... on EntityTypeA {
5130+ unifiedEntity {
5131+ ... on Generic {
5132+ taglineMessage(uiContext: "Generic")
51325133 }
5134+ }
51335135 }
5136+ ... on EntityTypeB {
5137+ unifiedEntity {
5138+ ...VideoSummary
5139+ }
5140+ }
5141+ }
51345142 }
51355143
51365144 fragment VideoSummary on Video {
5137- videoId # Note: This extra field selection is necessary, so this fragment is not ignored.
5138- taglineMessage(uiContext: "Video")
5145+ videoId # Note: This extra field selection is necessary, so this fragment is not ignored.
5146+ taglineMessage(uiContext: "Video")
51395147 }
5140- ` ;
5141- const operation = operationFromDocument (
5142- api ,
5143- query ,
5144- { validate : true }
5145- ) ;
5148+ ` ;
5149+ const operation = operationFromDocument ( api , query , { validate : true } ) ;
51465150
51475151 const plan = queryPlanner . buildQueryPlan ( operation ) ;
51485152 let validationErrors = validateSubFetches ( plan . node , subgraph2 ) ;
@@ -5155,21 +5159,41 @@ describe('Named fragments preservation', () => {
51555159 * @param plan
51565160 * @param subgraphs
51575161 */
5158- function validateSubFetches ( plan : any , subgraphDef : ServiceDefinition ) :
5159- { errors : readonly GraphQLError [ ] , serviceName : string , fetchNode : FetchNode } [ ]
5160- {
5162+ function validateSubFetches (
5163+ plan : any ,
5164+ subgraphDef : ServiceDefinition ,
5165+ ) : {
5166+ errors : readonly GraphQLError [ ] ;
5167+ serviceName : string ;
5168+ fetchNode : FetchNode ;
5169+ } [ ] {
51615170 if ( ! plan ) {
51625171 return [ ] ;
51635172 }
51645173 let fetches = findFetchNodes ( subgraphDef . name , plan ) ;
5165- var results : { errors : readonly GraphQLError [ ] , serviceName : string , fetchNode : FetchNode } [ ] = [ ] ;
5174+ var results : {
5175+ errors : readonly GraphQLError [ ] ;
5176+ serviceName : string ;
5177+ fetchNode : FetchNode ;
5178+ } [ ] = [ ] ;
51665179 for ( let fetch of fetches ) {
51675180 let subgraphName : string = fetch . serviceName ;
51685181 let operation : string = fetch . operation ;
5169- let subgraph = buildSubgraph ( subgraphName , 'http://subgraph' , subgraphDef . typeDefs ) ;
5170- let gql_errors = validate ( subgraph . schema . toGraphQLJSSchema ( ) , parse ( operation ) ) ;
5182+ let subgraph = buildSubgraph (
5183+ subgraphName ,
5184+ 'http://subgraph' ,
5185+ subgraphDef . typeDefs ,
5186+ ) ;
5187+ let gql_errors = validate (
5188+ subgraph . schema . toGraphQLJSSchema ( ) ,
5189+ parse ( operation ) ,
5190+ ) ;
51715191 if ( gql_errors . length > 0 ) {
5172- results . push ( { errors : gql_errors , serviceName : subgraphName , fetchNode : fetch } ) ;
5192+ results . push ( {
5193+ errors : gql_errors ,
5194+ serviceName : subgraphName ,
5195+ fetchNode : fetch ,
5196+ } ) ;
51735197 }
51745198 }
51755199 return results ;
0 commit comments