@@ -62,10 +62,14 @@ describe("mapDirectives", () => {
62
62
const schema = transform ( gql `
63
63
interface Entity
64
64
@implements(interface: "Node")
65
- @discriminates(with: "kind")
66
- @discriminationAlias(value: "component", type: "Component")
67
- @discriminationAlias(value: "template", type: "Template")
68
- @discriminationAlias(value: "location", type: "Location") {
65
+ @discriminates(
66
+ with: "kind"
67
+ aliases: [
68
+ { value: "component", type: "Component" }
69
+ { value: "template", type: "Template" }
70
+ { value: "location", type: "Location" }
71
+ ]
72
+ ) {
69
73
totalCount: Int!
70
74
}
71
75
@@ -390,14 +394,18 @@ describe("mapDirectives", () => {
390
394
) ;
391
395
} ) ;
392
396
393
- void test ( `should fail if @discriminationAlias has ambiguous types` , ( ) => {
397
+ void test ( `should fail if discrimination aliases have ambiguous types` , ( ) => {
394
398
expect ( ( ) =>
395
399
transform ( gql `
396
400
interface Entity
397
401
@implements(interface: "Node")
398
- @discriminates(with: "kind")
399
- @discriminationAlias(value: "component", type: "EntityComponent")
400
- @discriminationAlias(value: "component", type: "Component") {
402
+ @discriminates(
403
+ with: "kind"
404
+ aliases: [
405
+ { value: "component", type: "EntityComponent" }
406
+ { value: "component", type: "Component" }
407
+ ]
408
+ ) {
401
409
name: String!
402
410
}
403
411
@@ -414,20 +422,6 @@ describe("mapDirectives", () => {
414
422
) ;
415
423
} ) ;
416
424
417
- void test ( `should fail if @discriminationAlias is used without @discriminates` , ( ) => {
418
- expect ( ( ) =>
419
- transform ( gql `
420
- interface Entity
421
- @implements(interface: "Node")
422
- @discriminationAlias(value: "component", type: "EntityComponent") {
423
- name: String!
424
- }
425
- ` ) ,
426
- ) . toThrow (
427
- `The "Entity" interface has @discriminationAlias directive but doesn't have @discriminates directive` ,
428
- ) ;
429
- } ) ;
430
-
431
425
void test ( `should fail if interface has multiple implementations and @discriminates is not specified` , ( ) => {
432
426
expect ( ( ) =>
433
427
transform ( gql `
@@ -565,9 +559,11 @@ describe("mapDirectives", () => {
565
559
expect ( ( ) =>
566
560
transform ( gql `
567
561
interface Entity
568
- @discriminates(with: "kind")
569
- @implements(interface: "Node")
570
- @discriminationAlias(value: "component", type: "Component") {
562
+ @discriminates(
563
+ with: "kind"
564
+ aliases: [{ value: "component", type: "Component" }]
565
+ )
566
+ @implements(interface: "Node") {
571
567
name: String!
572
568
}
573
569
type Resource @implements(interface: "Entity") {
@@ -580,7 +576,7 @@ describe("mapDirectives", () => {
580
576
}
581
577
` ) ,
582
578
) . toThrow (
583
- 'Type(-s) "Component" in `interface Entity @discriminationAlias(value: ..., type: ... )` must implement "Entity" interface by using @implements directive' ,
579
+ 'Type(-s) "Component" in `interface Entity @discriminates(aliases: [ ...] )` must implement "Entity" interface by using @implements directive' ,
584
580
) ;
585
581
} ) ;
586
582
@@ -895,9 +891,13 @@ describe("mapDirectives", () => {
895
891
id : "test" ,
896
892
typeDefs : gql `
897
893
interface Node
898
- @discriminates(with: "__source")
899
- @discriminationAlias(value: "Mock", type: "Entity")
900
- @discriminationAlias(value: "GraphQL", type: "GraphQLEntity")
894
+ @discriminates(
895
+ with: "__source"
896
+ aliases: [
897
+ { value: "Mock", type: "Entity" }
898
+ { value: "GraphQL", type: "GraphQLEntity" }
899
+ ]
900
+ )
901
901
902
902
type Entity @implements(interface: "Node") {
903
903
parent: GraphQLEntity @resolve(at: "spec.parentId", from: "GraphQL")
@@ -965,9 +965,13 @@ describe("mapDirectives", () => {
965
965
id : "test" ,
966
966
typeDefs : gql `
967
967
interface Node
968
- @discriminates(with: "__source")
969
- @discriminationAlias(value: "Mock", type: "Entity")
970
- @discriminationAlias(value: "Tasks", type: "TaskProperty")
968
+ @discriminates(
969
+ with: "__source"
970
+ aliases: [
971
+ { value: "Mock", type: "Entity" }
972
+ { value: "Tasks", type: "TaskProperty" }
973
+ ]
974
+ )
971
975
972
976
type Entity @implements(interface: "Node") {
973
977
property(name: String!): TaskProperty
@@ -1051,9 +1055,13 @@ describe("mapDirectives", () => {
1051
1055
id : "test" ,
1052
1056
typeDefs : gql `
1053
1057
interface Node
1054
- @discriminates(with: "__source")
1055
- @discriminationAlias(value: "Mock", type: "Entity")
1056
- @discriminationAlias(value: "Tasks", type: "Task")
1058
+ @discriminates(
1059
+ with: "__source"
1060
+ aliases: [
1061
+ { value: "Mock", type: "Entity" }
1062
+ { value: "Tasks", type: "Task" }
1063
+ ]
1064
+ )
1057
1065
1058
1066
type Entity @implements(interface: "Node") {
1059
1067
task(taskId: ID!): Task @resolve(from: "Tasks")
@@ -1202,8 +1210,10 @@ describe("mapDirectives", () => {
1202
1210
typeDefs : gql `
1203
1211
interface Entity
1204
1212
@implements(interface: "Node")
1205
- @discriminates(with: "kind")
1206
- @discriminationAlias(value: "User", type: "Employee") {
1213
+ @discriminates(
1214
+ with: "kind"
1215
+ aliases: [{ value: "User", type: "Employee" }]
1216
+ ) {
1207
1217
name: String! @field(at: "name")
1208
1218
}
1209
1219
0 commit comments