@theguild/federation-composition 0.13.0 → 0.14.0-rc-20241002121511-2c854a0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -311,6 +311,7 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
311
311
  if (composedDirectives.has(node.name.value)) {
312
312
  const typeDef = typeNodeInfo.getTypeDef();
313
313
  const fieldDef = typeNodeInfo.getFieldDef();
314
+ const enumValueDef = typeNodeInfo.getValueDef();
314
315
  const argDef = typeNodeInfo.getArgumentDef();
315
316
  if (!typeDef) {
316
317
  return;
@@ -363,11 +364,21 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
363
364
  }
364
365
  case graphql_1.Kind.ENUM_TYPE_DEFINITION:
365
366
  case graphql_1.Kind.ENUM_TYPE_EXTENSION: {
366
- enumTypeBuilder.setDirective(typeDef.name.value, node);
367
+ if (enumValueDef) {
368
+ enumTypeBuilder.value.setDirective(typeDef.name.value, enumValueDef.name.value, node);
369
+ }
370
+ else {
371
+ enumTypeBuilder.setDirective(typeDef.name.value, node);
372
+ }
373
+ break;
374
+ }
375
+ case graphql_1.Kind.UNION_TYPE_DEFINITION:
376
+ case graphql_1.Kind.UNION_TYPE_EXTENSION: {
377
+ unionTypeBuilder.setDirective(typeDef.name.value, node);
367
378
  break;
368
379
  }
369
380
  default:
370
- throw new Error(`Directives on "${typeDef.kind}" types are not supported yet`);
381
+ throw new Error(`Directives on "${typeof typeDef === 'object' && typeDef !== null && 'kind' in typeDef ? typeDef.kind : typeDef}" types are not supported yet`);
371
382
  }
372
383
  }
373
384
  else if (node.name.value === 'specifiedBy') {
@@ -1098,6 +1109,9 @@ function unionTypeFactory(state) {
1098
1109
  setMember(typeName, member) {
1099
1110
  getOrCreateUnionType(state, typeName).members.add(member);
1100
1111
  },
1112
+ setDirective(typeName, directive) {
1113
+ getOrCreateUnionType(state, typeName).ast.directives.push(directive);
1114
+ },
1101
1115
  };
1102
1116
  }
1103
1117
  function enumTypeFactory(state) {
@@ -1141,6 +1155,9 @@ function enumTypeFactory(state) {
1141
1155
  setDescription(typeName, valueName, description) {
1142
1156
  getOrCreateEnumValue(state, typeName, valueName).description = description;
1143
1157
  },
1158
+ setDirective(typeName, valueName, directive) {
1159
+ getOrCreateEnumValue(state, typeName, valueName).ast.directives.push(directive);
1160
+ },
1144
1161
  setInaccessible(typeName, valueName) {
1145
1162
  getOrCreateEnumValue(state, typeName, valueName).inaccessible = true;
1146
1163
  },
@@ -1347,6 +1364,9 @@ function getOrCreateUnionType(state, typeName) {
1347
1364
  inaccessible: false,
1348
1365
  tags: new Set(),
1349
1366
  isDefinition: false,
1367
+ ast: {
1368
+ directives: [],
1369
+ },
1350
1370
  };
1351
1371
  state.types.set(typeName, unionType);
1352
1372
  return unionType;
@@ -1446,6 +1466,9 @@ function getOrCreateEnumValue(state, typeName, enumValueName) {
1446
1466
  name: enumValueName,
1447
1467
  inaccessible: false,
1448
1468
  tags: new Set(),
1469
+ ast: {
1470
+ directives: [],
1471
+ },
1449
1472
  };
1450
1473
  enumType.values.set(enumValueName, enumValue);
1451
1474
  return enumValue;
@@ -57,6 +57,9 @@ function enumTypeBuilder() {
57
57
  if (value.description && !valueState.description) {
58
58
  valueState.description = value.description;
59
59
  }
60
+ value.ast.directives.forEach(directive => {
61
+ valueState.ast.directives.push(directive);
62
+ });
60
63
  valueState.byGraph.set(graph.id, {
61
64
  inaccessible: value.inaccessible,
62
65
  version: graph.version,
@@ -81,6 +84,9 @@ function enumTypeBuilder() {
81
84
  inaccessible: value.inaccessible,
82
85
  description: value.description,
83
86
  deprecated: value.deprecated,
87
+ ast: {
88
+ directives: (0, common_js_1.convertToConst)(value.ast.directives),
89
+ },
84
90
  })),
85
91
  tags: Array.from(enumType.tags),
86
92
  inaccessible: enumType.inaccessible,
@@ -154,6 +160,9 @@ function getOrCreateEnumValue(enumTypeState, enumValueName) {
154
160
  tags: new Set(),
155
161
  inaccessible: false,
156
162
  byGraph: new Map(),
163
+ ast: {
164
+ directives: [],
165
+ },
157
166
  };
158
167
  enumTypeState.values.set(enumValueName, def);
159
168
  return def;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unionTypeBuilder = void 0;
4
4
  const ast_js_1 = require("./ast.js");
5
+ const common_js_1 = require("./common.js");
5
6
  function unionTypeBuilder() {
6
7
  return {
7
8
  visitSubgraphState(graph, state, typeName, type) {
@@ -16,6 +17,9 @@ function unionTypeBuilder() {
16
17
  if (type.description && !unionTypeState.description) {
17
18
  unionTypeState.description = type.description;
18
19
  }
20
+ type.ast.directives.forEach(directive => {
21
+ unionTypeState.ast.directives.push(directive);
22
+ });
19
23
  unionTypeState.byGraph.set(graph.id, {
20
24
  members: type.members,
21
25
  version: graph.version,
@@ -42,6 +46,9 @@ function unionTypeBuilder() {
42
46
  })
43
47
  .flat(1),
44
48
  },
49
+ ast: {
50
+ directives: (0, common_js_1.convertToConst)(unionType.ast.directives),
51
+ },
45
52
  });
46
53
  },
47
54
  };
@@ -60,6 +67,9 @@ function getOrCreateUnionType(state, typeName) {
60
67
  inaccessible: false,
61
68
  hasDefinition: false,
62
69
  byGraph: new Map(),
70
+ ast: {
71
+ directives: [],
72
+ },
63
73
  };
64
74
  state.set(typeName, def);
65
75
  return def;
@@ -308,6 +308,7 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
308
308
  if (composedDirectives.has(node.name.value)) {
309
309
  const typeDef = typeNodeInfo.getTypeDef();
310
310
  const fieldDef = typeNodeInfo.getFieldDef();
311
+ const enumValueDef = typeNodeInfo.getValueDef();
311
312
  const argDef = typeNodeInfo.getArgumentDef();
312
313
  if (!typeDef) {
313
314
  return;
@@ -360,11 +361,21 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
360
361
  }
361
362
  case Kind.ENUM_TYPE_DEFINITION:
362
363
  case Kind.ENUM_TYPE_EXTENSION: {
363
- enumTypeBuilder.setDirective(typeDef.name.value, node);
364
+ if (enumValueDef) {
365
+ enumTypeBuilder.value.setDirective(typeDef.name.value, enumValueDef.name.value, node);
366
+ }
367
+ else {
368
+ enumTypeBuilder.setDirective(typeDef.name.value, node);
369
+ }
370
+ break;
371
+ }
372
+ case Kind.UNION_TYPE_DEFINITION:
373
+ case Kind.UNION_TYPE_EXTENSION: {
374
+ unionTypeBuilder.setDirective(typeDef.name.value, node);
364
375
  break;
365
376
  }
366
377
  default:
367
- throw new Error(`Directives on "${typeDef.kind}" types are not supported yet`);
378
+ throw new Error(`Directives on "${typeof typeDef === 'object' && typeDef !== null && 'kind' in typeDef ? typeDef.kind : typeDef}" types are not supported yet`);
368
379
  }
369
380
  }
370
381
  else if (node.name.value === 'specifiedBy') {
@@ -1092,6 +1103,9 @@ function unionTypeFactory(state) {
1092
1103
  setMember(typeName, member) {
1093
1104
  getOrCreateUnionType(state, typeName).members.add(member);
1094
1105
  },
1106
+ setDirective(typeName, directive) {
1107
+ getOrCreateUnionType(state, typeName).ast.directives.push(directive);
1108
+ },
1095
1109
  };
1096
1110
  }
1097
1111
  function enumTypeFactory(state) {
@@ -1135,6 +1149,9 @@ function enumTypeFactory(state) {
1135
1149
  setDescription(typeName, valueName, description) {
1136
1150
  getOrCreateEnumValue(state, typeName, valueName).description = description;
1137
1151
  },
1152
+ setDirective(typeName, valueName, directive) {
1153
+ getOrCreateEnumValue(state, typeName, valueName).ast.directives.push(directive);
1154
+ },
1138
1155
  setInaccessible(typeName, valueName) {
1139
1156
  getOrCreateEnumValue(state, typeName, valueName).inaccessible = true;
1140
1157
  },
@@ -1341,6 +1358,9 @@ function getOrCreateUnionType(state, typeName) {
1341
1358
  inaccessible: false,
1342
1359
  tags: new Set(),
1343
1360
  isDefinition: false,
1361
+ ast: {
1362
+ directives: [],
1363
+ },
1344
1364
  };
1345
1365
  state.types.set(typeName, unionType);
1346
1366
  return unionType;
@@ -1440,6 +1460,9 @@ function getOrCreateEnumValue(state, typeName, enumValueName) {
1440
1460
  name: enumValueName,
1441
1461
  inaccessible: false,
1442
1462
  tags: new Set(),
1463
+ ast: {
1464
+ directives: [],
1465
+ },
1443
1466
  };
1444
1467
  enumType.values.set(enumValueName, enumValue);
1445
1468
  return enumValue;
@@ -54,6 +54,9 @@ export function enumTypeBuilder() {
54
54
  if (value.description && !valueState.description) {
55
55
  valueState.description = value.description;
56
56
  }
57
+ value.ast.directives.forEach(directive => {
58
+ valueState.ast.directives.push(directive);
59
+ });
57
60
  valueState.byGraph.set(graph.id, {
58
61
  inaccessible: value.inaccessible,
59
62
  version: graph.version,
@@ -78,6 +81,9 @@ export function enumTypeBuilder() {
78
81
  inaccessible: value.inaccessible,
79
82
  description: value.description,
80
83
  deprecated: value.deprecated,
84
+ ast: {
85
+ directives: convertToConst(value.ast.directives),
86
+ },
81
87
  })),
82
88
  tags: Array.from(enumType.tags),
83
89
  inaccessible: enumType.inaccessible,
@@ -150,6 +156,9 @@ function getOrCreateEnumValue(enumTypeState, enumValueName) {
150
156
  tags: new Set(),
151
157
  inaccessible: false,
152
158
  byGraph: new Map(),
159
+ ast: {
160
+ directives: [],
161
+ },
153
162
  };
154
163
  enumTypeState.values.set(enumValueName, def);
155
164
  return def;
@@ -1,4 +1,5 @@
1
1
  import { createUnionTypeNode } from './ast.js';
2
+ import { convertToConst } from './common.js';
2
3
  export function unionTypeBuilder() {
3
4
  return {
4
5
  visitSubgraphState(graph, state, typeName, type) {
@@ -13,6 +14,9 @@ export function unionTypeBuilder() {
13
14
  if (type.description && !unionTypeState.description) {
14
15
  unionTypeState.description = type.description;
15
16
  }
17
+ type.ast.directives.forEach(directive => {
18
+ unionTypeState.ast.directives.push(directive);
19
+ });
16
20
  unionTypeState.byGraph.set(graph.id, {
17
21
  members: type.members,
18
22
  version: graph.version,
@@ -39,6 +43,9 @@ export function unionTypeBuilder() {
39
43
  })
40
44
  .flat(1),
41
45
  },
46
+ ast: {
47
+ directives: convertToConst(unionType.ast.directives),
48
+ },
42
49
  });
43
50
  },
44
51
  };
@@ -56,6 +63,9 @@ function getOrCreateUnionType(state, typeName) {
56
63
  inaccessible: false,
57
64
  hasDefinition: false,
58
65
  byGraph: new Map(),
66
+ ast: {
67
+ directives: [],
68
+ },
59
69
  };
60
70
  state.set(typeName, def);
61
71
  return def;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theguild/federation-composition",
3
- "version": "0.13.0",
3
+ "version": "0.14.0-rc-20241002121511-2c854a0",
4
4
  "description": "Open Source Composition library for Apollo Federation",
5
5
  "peerDependencies": {
6
6
  "graphql": "^16.0.0"
@@ -104,6 +104,9 @@ export interface UnionType {
104
104
  inaccessible: boolean;
105
105
  isDefinition: boolean;
106
106
  description?: Description;
107
+ ast: {
108
+ directives: DirectiveNode[];
109
+ };
107
110
  }
108
111
  export interface EnumType {
109
112
  kind: TypeKind.ENUM;
@@ -169,6 +172,9 @@ export interface EnumValue {
169
172
  tags: Set<string>;
170
173
  description?: Description;
171
174
  deprecated?: Deprecated;
175
+ ast: {
176
+ directives: DirectiveNode[];
177
+ };
172
178
  }
173
179
  export interface Argument {
174
180
  name: string;
@@ -361,6 +367,7 @@ export declare function createSubgraphStateBuilder(graph: {
361
367
  setTag(typeName: string, tag: string): void;
362
368
  setDescription(typeName: string, description: Description): void;
363
369
  setMember(typeName: string, member: string): void;
370
+ setDirective(typeName: string, directive: DirectiveNode): void;
364
371
  };
365
372
  enumType: {
366
373
  setDefinition(typeName: string): void;
@@ -376,6 +383,7 @@ export declare function createSubgraphStateBuilder(graph: {
376
383
  value: {
377
384
  setValue(typeName: string, valueName: string): void;
378
385
  setDescription(typeName: string, valueName: string, description: Description): void;
386
+ setDirective(typeName: string, valueName: string, directive: DirectiveNode): void;
379
387
  setInaccessible(typeName: string, valueName: string): void;
380
388
  setTag(typeName: string, valueName: string, tag: string): void;
381
389
  setDeprecated(typeName: string, valueName: string, reason?: string | undefined): void;
@@ -104,6 +104,9 @@ export interface UnionType {
104
104
  inaccessible: boolean;
105
105
  isDefinition: boolean;
106
106
  description?: Description;
107
+ ast: {
108
+ directives: DirectiveNode[];
109
+ };
107
110
  }
108
111
  export interface EnumType {
109
112
  kind: TypeKind.ENUM;
@@ -169,6 +172,9 @@ export interface EnumValue {
169
172
  tags: Set<string>;
170
173
  description?: Description;
171
174
  deprecated?: Deprecated;
175
+ ast: {
176
+ directives: DirectiveNode[];
177
+ };
172
178
  }
173
179
  export interface Argument {
174
180
  name: string;
@@ -361,6 +367,7 @@ export declare function createSubgraphStateBuilder(graph: {
361
367
  setTag(typeName: string, tag: string): void;
362
368
  setDescription(typeName: string, description: Description): void;
363
369
  setMember(typeName: string, member: string): void;
370
+ setDirective(typeName: string, directive: DirectiveNode): void;
364
371
  };
365
372
  enumType: {
366
373
  setDefinition(typeName: string): void;
@@ -376,6 +383,7 @@ export declare function createSubgraphStateBuilder(graph: {
376
383
  value: {
377
384
  setValue(typeName: string, valueName: string): void;
378
385
  setDescription(typeName: string, valueName: string, description: Description): void;
386
+ setDirective(typeName: string, valueName: string, directive: DirectiveNode): void;
379
387
  setInaccessible(typeName: string, valueName: string): void;
380
388
  setTag(typeName: string, valueName: string, tag: string): void;
381
389
  setDeprecated(typeName: string, valueName: string, reason?: string | undefined): void;
@@ -158,6 +158,7 @@ export declare function createSubgraphValidationContext(subgraph: {
158
158
  setTag(typeName: string, tag: string): void;
159
159
  setDescription(typeName: string, description: import("../state.js").Description): void;
160
160
  setMember(typeName: string, member: string): void;
161
+ setDirective(typeName: string, directive: import("graphql").DirectiveNode): void;
161
162
  };
162
163
  enumType: {
163
164
  setDefinition(typeName: string): void;
@@ -173,6 +174,7 @@ export declare function createSubgraphValidationContext(subgraph: {
173
174
  value: {
174
175
  setValue(typeName: string, valueName: string): void;
175
176
  setDescription(typeName: string, valueName: string, description: import("../state.js").Description): void;
177
+ setDirective(typeName: string, valueName: string, directive: import("graphql").DirectiveNode): void;
176
178
  setInaccessible(typeName: string, valueName: string): void;
177
179
  setTag(typeName: string, valueName: string, tag: string): void;
178
180
  setDeprecated(typeName: string, valueName: string, reason?: string | undefined): void;
@@ -158,6 +158,7 @@ export declare function createSubgraphValidationContext(subgraph: {
158
158
  setTag(typeName: string, tag: string): void;
159
159
  setDescription(typeName: string, description: import("../state.js").Description): void;
160
160
  setMember(typeName: string, member: string): void;
161
+ setDirective(typeName: string, directive: import("graphql").DirectiveNode): void;
161
162
  };
162
163
  enumType: {
163
164
  setDefinition(typeName: string): void;
@@ -173,6 +174,7 @@ export declare function createSubgraphValidationContext(subgraph: {
173
174
  value: {
174
175
  setValue(typeName: string, valueName: string): void;
175
176
  setDescription(typeName: string, valueName: string, description: import("../state.js").Description): void;
177
+ setDirective(typeName: string, valueName: string, directive: import("graphql").DirectiveNode): void;
176
178
  setInaccessible(typeName: string, valueName: string): void;
177
179
  setTag(typeName: string, valueName: string, tag: string): void;
178
180
  setDeprecated(typeName: string, valueName: string, reason?: string | undefined): void;
@@ -29,6 +29,9 @@ type EnumValueState = {
29
29
  inaccessible: boolean;
30
30
  deprecated?: Deprecated;
31
31
  description?: Description;
32
+ ast: {
33
+ directives: DirectiveNode[];
34
+ };
32
35
  byGraph: MapByGraph<EnumValueStateInGraph>;
33
36
  };
34
37
  type EnumTypeStateInGraph = {
@@ -29,6 +29,9 @@ type EnumValueState = {
29
29
  inaccessible: boolean;
30
30
  deprecated?: Deprecated;
31
31
  description?: Description;
32
+ ast: {
33
+ directives: DirectiveNode[];
34
+ };
32
35
  byGraph: MapByGraph<EnumValueStateInGraph>;
33
36
  };
34
37
  type EnumTypeStateInGraph = {
@@ -1,6 +1,7 @@
1
+ import type { DirectiveNode } from 'graphql';
1
2
  import { FederationVersion } from '../../specifications/federation.cjs';
2
3
  import { Description, UnionType } from '../../subgraph/state.cjs';
3
- import type { MapByGraph, TypeBuilder } from './common.cjs';
4
+ import { type MapByGraph, type TypeBuilder } from './common.cjs';
4
5
  export declare function unionTypeBuilder(): TypeBuilder<UnionType, UnionTypeState>;
5
6
  export type UnionTypeState = {
6
7
  kind: 'union';
@@ -11,6 +12,9 @@ export type UnionTypeState = {
11
12
  inaccessible: boolean;
12
13
  byGraph: MapByGraph<UnionTypeInGraph>;
13
14
  members: Set<string>;
15
+ ast: {
16
+ directives: DirectiveNode[];
17
+ };
14
18
  };
15
19
  type UnionTypeInGraph = {
16
20
  members: Set<string>;
@@ -1,6 +1,7 @@
1
+ import type { DirectiveNode } from 'graphql';
1
2
  import { FederationVersion } from '../../specifications/federation.js';
2
3
  import { Description, UnionType } from '../../subgraph/state.js';
3
- import type { MapByGraph, TypeBuilder } from './common.js';
4
+ import { type MapByGraph, type TypeBuilder } from './common.js';
4
5
  export declare function unionTypeBuilder(): TypeBuilder<UnionType, UnionTypeState>;
5
6
  export type UnionTypeState = {
6
7
  kind: 'union';
@@ -11,6 +12,9 @@ export type UnionTypeState = {
11
12
  inaccessible: boolean;
12
13
  byGraph: MapByGraph<UnionTypeInGraph>;
13
14
  members: Set<string>;
15
+ ast: {
16
+ directives: DirectiveNode[];
17
+ };
14
18
  };
15
19
  type UnionTypeInGraph = {
16
20
  members: Set<string>;