@@ -5203,3 +5203,225 @@ describe('@source* directives', () => {
5203
5203
} ) ;
5204
5204
} ) ;
5205
5205
} ) ;
5206
+
5207
+ describe ( "connect spec and join__directive" , ( ) => {
5208
+ it ( "composes" , ( ) => {
5209
+ const subgraphs = [
5210
+ {
5211
+ name : "with-connectors" ,
5212
+ typeDefs : gql `
5213
+ extend schema
5214
+ @link(
5215
+ url: "https://specs.apollo.dev/federation/v2.7"
5216
+ import: ["@key"]
5217
+ )
5218
+ @link(
5219
+ url: "https://specs.apollo.dev/connect/v0.1"
5220
+ import: ["@connect", "@source"]
5221
+ )
5222
+ @source(name: "v1", http: { baseURL: "http://v1" })
5223
+
5224
+ type Query {
5225
+ resources: [Resource!]!
5226
+ @connect(source: "v1", http: { GET: "/resources" })
5227
+ }
5228
+
5229
+ type Resource @key(fields: "id") {
5230
+ id: ID!
5231
+ name: String!
5232
+ }
5233
+ ` ,
5234
+ } ,
5235
+ ] ;
5236
+
5237
+ const result = composeServices ( subgraphs ) ;
5238
+ expect ( result . errors ?? [ ] ) . toEqual ( [ ] ) ;
5239
+ const printed = printSchema ( result . schema ! ) ;
5240
+ expect ( printed ) . toMatchInlineSnapshot ( `
5241
+ "schema
5242
+ @link(url: \\"https://specs.apollo.dev/link/v1.0\\")
5243
+ @link(url: \\"https://specs.apollo.dev/join/v0.4\\", for: EXECUTION)
5244
+ @join__directive(graphs: [WITH_CONNECTORS], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.1\\", import: [\\"@connect\\", \\"@source\\"]})
5245
+ @join__directive(graphs: [WITH_CONNECTORS], name: \\"source\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
5246
+ {
5247
+ query: Query
5248
+ }
5249
+
5250
+ directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
5251
+
5252
+ directive @join__graph(name: String!, url: String!) on ENUM_VALUE
5253
+
5254
+ directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
5255
+
5256
+ directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean, overrideLabel: String) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
5257
+
5258
+ directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
5259
+
5260
+ directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
5261
+
5262
+ directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
5263
+
5264
+ directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION
5265
+
5266
+ enum link__Purpose {
5267
+ \\"\\"\\"
5268
+ \`SECURITY\` features provide metadata necessary to securely resolve fields.
5269
+ \\"\\"\\"
5270
+ SECURITY
5271
+
5272
+ \\"\\"\\"
5273
+ \`EXECUTION\` features provide metadata necessary for operation execution.
5274
+ \\"\\"\\"
5275
+ EXECUTION
5276
+ }
5277
+
5278
+ scalar link__Import
5279
+
5280
+ enum join__Graph {
5281
+ WITH_CONNECTORS @join__graph(name: \\"with-connectors\\", url: \\"\\")
5282
+ }
5283
+
5284
+ scalar join__FieldSet
5285
+
5286
+ scalar join__DirectiveArguments
5287
+
5288
+ type Query
5289
+ @join__type(graph: WITH_CONNECTORS)
5290
+ {
5291
+ resources: [Resource!]! @join__directive(graphs: [WITH_CONNECTORS], name: \\"connect\\", args: {source: \\"v1\\", http: {GET: \\"/resources\\"}})
5292
+ }
5293
+
5294
+ type Resource
5295
+ @join__type(graph: WITH_CONNECTORS, key: \\"id\\")
5296
+ {
5297
+ id: ID!
5298
+ name: String!
5299
+ }"
5300
+ ` ) ;
5301
+
5302
+ if ( result . schema ) {
5303
+ expect ( printSchema ( result . schema . toAPISchema ( ) ) ) . toMatchInlineSnapshot ( `
5304
+ "type Query {
5305
+ resources: [Resource!]!
5306
+ }
5307
+
5308
+ type Resource {
5309
+ id: ID!
5310
+ name: String!
5311
+ }"
5312
+ ` ) ;
5313
+ }
5314
+ } ) ;
5315
+
5316
+ it ( "composes with renames" , ( ) => {
5317
+ const subgraphs = [
5318
+ {
5319
+ name : "with-connectors" ,
5320
+ typeDefs : gql `
5321
+ extend schema
5322
+ @link(
5323
+ url: "https://specs.apollo.dev/federation/v2.7"
5324
+ import: ["@key"]
5325
+ )
5326
+ @link(
5327
+ url: "https://specs.apollo.dev/connect/v0.1"
5328
+ as: "http"
5329
+ import: [
5330
+ { name: "@connect", as: "@http" }
5331
+ { name: "@source", as: "@api" }
5332
+ ]
5333
+ )
5334
+ @api(name: "v1", http: { baseURL: "http://v1" })
5335
+
5336
+ type Query {
5337
+ resources: [Resource!]!
5338
+ @http(source: "v1", http: { GET: "/resources" })
5339
+ }
5340
+
5341
+ type Resource @key(fields: "id") {
5342
+ id: ID!
5343
+ name: String!
5344
+ }
5345
+ ` ,
5346
+ } ,
5347
+ ] ;
5348
+
5349
+ const result = composeServices ( subgraphs ) ;
5350
+ expect ( result . errors ?? [ ] ) . toEqual ( [ ] ) ;
5351
+ const printed = printSchema ( result . schema ! ) ;
5352
+ expect ( printed ) . toMatchInlineSnapshot ( `
5353
+ "schema
5354
+ @link(url: \\"https://specs.apollo.dev/link/v1.0\\")
5355
+ @link(url: \\"https://specs.apollo.dev/join/v0.4\\", for: EXECUTION)
5356
+ @join__directive(graphs: [WITH_CONNECTORS], name: \\"link\\", args: {url: \\"https://specs.apollo.dev/connect/v0.1\\", as: \\"http\\", import: [{name: \\"@connect\\", as: \\"@http\\"}, {name: \\"@source\\", as: \\"@api\\"}]})
5357
+ @join__directive(graphs: [WITH_CONNECTORS], name: \\"api\\", args: {name: \\"v1\\", http: {baseURL: \\"http://v1\\"}})
5358
+ {
5359
+ query: Query
5360
+ }
5361
+
5362
+ directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
5363
+
5364
+ directive @join__graph(name: String!, url: String!) on ENUM_VALUE
5365
+
5366
+ directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
5367
+
5368
+ directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean, overrideLabel: String) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
5369
+
5370
+ directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
5371
+
5372
+ directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
5373
+
5374
+ directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
5375
+
5376
+ directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION
5377
+
5378
+ enum link__Purpose {
5379
+ \\"\\"\\"
5380
+ \`SECURITY\` features provide metadata necessary to securely resolve fields.
5381
+ \\"\\"\\"
5382
+ SECURITY
5383
+
5384
+ \\"\\"\\"
5385
+ \`EXECUTION\` features provide metadata necessary for operation execution.
5386
+ \\"\\"\\"
5387
+ EXECUTION
5388
+ }
5389
+
5390
+ scalar link__Import
5391
+
5392
+ enum join__Graph {
5393
+ WITH_CONNECTORS @join__graph(name: \\"with-connectors\\", url: \\"\\")
5394
+ }
5395
+
5396
+ scalar join__FieldSet
5397
+
5398
+ scalar join__DirectiveArguments
5399
+
5400
+ type Query
5401
+ @join__type(graph: WITH_CONNECTORS)
5402
+ {
5403
+ resources: [Resource!]! @join__directive(graphs: [WITH_CONNECTORS], name: \\"http\\", args: {source: \\"v1\\", http: {GET: \\"/resources\\"}})
5404
+ }
5405
+
5406
+ type Resource
5407
+ @join__type(graph: WITH_CONNECTORS, key: \\"id\\")
5408
+ {
5409
+ id: ID!
5410
+ name: String!
5411
+ }"
5412
+ ` ) ;
5413
+
5414
+ if ( result . schema ) {
5415
+ expect ( printSchema ( result . schema . toAPISchema ( ) ) ) . toMatchInlineSnapshot ( `
5416
+ "type Query {
5417
+ resources: [Resource!]!
5418
+ }
5419
+
5420
+ type Resource {
5421
+ id: ID!
5422
+ name: String!
5423
+ }"
5424
+ ` ) ;
5425
+ }
5426
+ } ) ;
5427
+ } ) ;
0 commit comments