@theguild/federation-composition 0.11.0 → 0.11.1

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.
@@ -43,6 +43,13 @@ function sortSDL(doc) {
43
43
  fields: sortNodes(node.fields),
44
44
  };
45
45
  },
46
+ InputObjectTypeDefinition(node) {
47
+ return {
48
+ ...node,
49
+ directives: sortNodes(node.directives),
50
+ fields: sortNodes(node.fields),
51
+ };
52
+ },
46
53
  EnumTypeDefinition(node) {
47
54
  return {
48
55
  ...node,
@@ -149,6 +156,9 @@ function sortNodes(nodes) {
149
156
  if (isOfKindList(nodes, graphql_1.Kind.ENUM_VALUE_DEFINITION)) {
150
157
  return (0, lodash_sortby_1.default)(nodes, 'name.value');
151
158
  }
159
+ if (isOfKindList(nodes, graphql_1.Kind.INPUT_VALUE_DEFINITION)) {
160
+ return (0, lodash_sortby_1.default)(nodes, 'name.value');
161
+ }
152
162
  if (isOfKindList(nodes, [graphql_1.Kind.FIELD, graphql_1.Kind.FRAGMENT_SPREAD, graphql_1.Kind.INLINE_FRAGMENT])) {
153
163
  return (0, lodash_sortby_1.default)(nodes, 'kind', 'name.value');
154
164
  }
@@ -325,6 +325,16 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
325
325
  }
326
326
  break;
327
327
  }
328
+ case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
329
+ case graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION: {
330
+ if (fieldDef) {
331
+ inputObjectTypeBuilder.field.setDirective(typeDef.name.value, fieldDef.name.value, node);
332
+ }
333
+ else {
334
+ inputObjectTypeBuilder.setDirective(typeDef.name.value, node);
335
+ }
336
+ break;
337
+ }
328
338
  default:
329
339
  throw new Error(`Directives on "${typeDef.kind}" types are not supported yet`);
330
340
  }
@@ -980,12 +990,15 @@ function inputObjectTypeFactory(state) {
980
990
  getOrCreateInputObjectType(state, typeName).description = description;
981
991
  },
982
992
  setInaccessible(typeName) {
983
- const objectType = getOrCreateInputObjectType(state, typeName);
984
- objectType.inaccessible = true;
985
- for (const field of objectType.fields.values()) {
993
+ const inputObjectType = getOrCreateInputObjectType(state, typeName);
994
+ inputObjectType.inaccessible = true;
995
+ for (const field of inputObjectType.fields.values()) {
986
996
  field.inaccessible = true;
987
997
  }
988
998
  },
999
+ setDirective(typeName, directive) {
1000
+ getOrCreateInputObjectType(state, typeName).ast.directives.push(directive);
1001
+ },
989
1002
  setTag(typeName, tag) {
990
1003
  getOrCreateInputObjectType(state, typeName).tags.add(tag);
991
1004
  },
@@ -1011,6 +1024,9 @@ function inputObjectTypeFactory(state) {
1011
1024
  setTag(typeName, fieldName, tag) {
1012
1025
  getOrCreateInputObjectField(state, typeName, fieldName).tags.add(tag);
1013
1026
  },
1027
+ setDirective(typeName, fieldName, directive) {
1028
+ getOrCreateInputObjectField(state, typeName, fieldName).ast.directives.push(directive);
1029
+ },
1014
1030
  },
1015
1031
  };
1016
1032
  }
@@ -1225,6 +1241,9 @@ function getOrCreateInputObjectType(state, typeName) {
1225
1241
  inaccessible: false,
1226
1242
  tags: new Set(),
1227
1243
  isDefinition: false,
1244
+ ast: {
1245
+ directives: [],
1246
+ },
1228
1247
  };
1229
1248
  state.types.set(typeName, inputObjectType);
1230
1249
  return inputObjectType;
@@ -1351,6 +1370,9 @@ function getOrCreateInputObjectField(state, typeName, fieldName) {
1351
1370
  type: MISSING,
1352
1371
  inaccessible: false,
1353
1372
  tags: new Set(),
1373
+ ast: {
1374
+ directives: [],
1375
+ },
1354
1376
  };
1355
1377
  inputObjectType.fields.set(fieldName, field);
1356
1378
  return field;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inputObjectTypeBuilder = void 0;
4
4
  const ast_js_1 = require("./ast.js");
5
+ const common_js_1 = require("./common.js");
5
6
  function inputObjectTypeBuilder() {
6
7
  return {
7
8
  visitSubgraphState(graph, state, typeName, type) {
@@ -10,13 +11,17 @@ function inputObjectTypeBuilder() {
10
11
  if (type.inaccessible) {
11
12
  inputObjectTypeState.inaccessible = true;
12
13
  }
13
- const isDefinition = type.isDefinition && !type.extension;
14
14
  if (type.description && !inputObjectTypeState.description) {
15
15
  inputObjectTypeState.description = type.description;
16
16
  }
17
17
  if (type.isDefinition) {
18
18
  inputObjectTypeState.hasDefinition = true;
19
19
  }
20
+ if (type.ast.directives) {
21
+ type.ast.directives.forEach(directive => {
22
+ inputObjectTypeState.ast.directives.push(directive);
23
+ });
24
+ }
20
25
  inputObjectTypeState.byGraph.set(graph.id, {
21
26
  inaccessible: type.inaccessible,
22
27
  version: graph.version,
@@ -39,6 +44,9 @@ function inputObjectTypeBuilder() {
39
44
  if (typeof field.defaultValue !== 'undefined') {
40
45
  fieldState.defaultValue = field.defaultValue;
41
46
  }
47
+ field.ast.directives.forEach(directive => {
48
+ fieldState.ast.directives.push(directive);
49
+ });
42
50
  fieldState.byGraph.set(graph.id, {
43
51
  type: field.type,
44
52
  inaccessible: field.inaccessible,
@@ -53,6 +61,9 @@ function inputObjectTypeBuilder() {
53
61
  tags: Array.from(inputObjectType.tags),
54
62
  inaccessible: inputObjectType.inaccessible,
55
63
  description: inputObjectType.description,
64
+ ast: {
65
+ directives: (0, common_js_1.convertToConst)(inputObjectType.ast.directives),
66
+ },
56
67
  fields: Array.from(inputObjectType.fields.values())
57
68
  .filter(field => {
58
69
  if (field.byGraph.size !== inputObjectType.byGraph.size) {
@@ -73,6 +84,9 @@ function inputObjectTypeBuilder() {
73
84
  : undefined,
74
85
  description: field.description,
75
86
  deprecated: field.deprecated,
87
+ ast: {
88
+ directives: (0, common_js_1.convertToConst)(field.ast.directives),
89
+ },
76
90
  join: {
77
91
  field: hasDifferentType
78
92
  ? Array.from(field.byGraph).map(([graph, fieldByGraph]) => ({
@@ -104,6 +118,9 @@ function getOrCreateInputObjectType(state, typeName) {
104
118
  inaccessible: false,
105
119
  byGraph: new Map(),
106
120
  fields: new Map(),
121
+ ast: {
122
+ directives: [],
123
+ },
107
124
  };
108
125
  state.set(typeName, def);
109
126
  return def;
@@ -119,6 +136,9 @@ function getOrCreateField(objectTypeState, fieldName, fieldType) {
119
136
  tags: new Set(),
120
137
  inaccessible: false,
121
138
  byGraph: new Map(),
139
+ ast: {
140
+ directives: [],
141
+ },
122
142
  };
123
143
  objectTypeState.fields.set(fieldName, def);
124
144
  return def;
@@ -37,6 +37,13 @@ export function sortSDL(doc) {
37
37
  fields: sortNodes(node.fields),
38
38
  };
39
39
  },
40
+ InputObjectTypeDefinition(node) {
41
+ return {
42
+ ...node,
43
+ directives: sortNodes(node.directives),
44
+ fields: sortNodes(node.fields),
45
+ };
46
+ },
40
47
  EnumTypeDefinition(node) {
41
48
  return {
42
49
  ...node,
@@ -142,6 +149,9 @@ function sortNodes(nodes) {
142
149
  if (isOfKindList(nodes, Kind.ENUM_VALUE_DEFINITION)) {
143
150
  return sortBy(nodes, 'name.value');
144
151
  }
152
+ if (isOfKindList(nodes, Kind.INPUT_VALUE_DEFINITION)) {
153
+ return sortBy(nodes, 'name.value');
154
+ }
145
155
  if (isOfKindList(nodes, [Kind.FIELD, Kind.FRAGMENT_SPREAD, Kind.INLINE_FRAGMENT])) {
146
156
  return sortBy(nodes, 'kind', 'name.value');
147
157
  }
@@ -322,6 +322,16 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
322
322
  }
323
323
  break;
324
324
  }
325
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
326
+ case Kind.INPUT_OBJECT_TYPE_EXTENSION: {
327
+ if (fieldDef) {
328
+ inputObjectTypeBuilder.field.setDirective(typeDef.name.value, fieldDef.name.value, node);
329
+ }
330
+ else {
331
+ inputObjectTypeBuilder.setDirective(typeDef.name.value, node);
332
+ }
333
+ break;
334
+ }
325
335
  default:
326
336
  throw new Error(`Directives on "${typeDef.kind}" types are not supported yet`);
327
337
  }
@@ -974,12 +984,15 @@ function inputObjectTypeFactory(state) {
974
984
  getOrCreateInputObjectType(state, typeName).description = description;
975
985
  },
976
986
  setInaccessible(typeName) {
977
- const objectType = getOrCreateInputObjectType(state, typeName);
978
- objectType.inaccessible = true;
979
- for (const field of objectType.fields.values()) {
987
+ const inputObjectType = getOrCreateInputObjectType(state, typeName);
988
+ inputObjectType.inaccessible = true;
989
+ for (const field of inputObjectType.fields.values()) {
980
990
  field.inaccessible = true;
981
991
  }
982
992
  },
993
+ setDirective(typeName, directive) {
994
+ getOrCreateInputObjectType(state, typeName).ast.directives.push(directive);
995
+ },
983
996
  setTag(typeName, tag) {
984
997
  getOrCreateInputObjectType(state, typeName).tags.add(tag);
985
998
  },
@@ -1005,6 +1018,9 @@ function inputObjectTypeFactory(state) {
1005
1018
  setTag(typeName, fieldName, tag) {
1006
1019
  getOrCreateInputObjectField(state, typeName, fieldName).tags.add(tag);
1007
1020
  },
1021
+ setDirective(typeName, fieldName, directive) {
1022
+ getOrCreateInputObjectField(state, typeName, fieldName).ast.directives.push(directive);
1023
+ },
1008
1024
  },
1009
1025
  };
1010
1026
  }
@@ -1219,6 +1235,9 @@ function getOrCreateInputObjectType(state, typeName) {
1219
1235
  inaccessible: false,
1220
1236
  tags: new Set(),
1221
1237
  isDefinition: false,
1238
+ ast: {
1239
+ directives: [],
1240
+ },
1222
1241
  };
1223
1242
  state.types.set(typeName, inputObjectType);
1224
1243
  return inputObjectType;
@@ -1345,6 +1364,9 @@ function getOrCreateInputObjectField(state, typeName, fieldName) {
1345
1364
  type: MISSING,
1346
1365
  inaccessible: false,
1347
1366
  tags: new Set(),
1367
+ ast: {
1368
+ directives: [],
1369
+ },
1348
1370
  };
1349
1371
  inputObjectType.fields.set(fieldName, field);
1350
1372
  return field;
@@ -1,4 +1,5 @@
1
1
  import { createInputObjectTypeNode } from './ast.js';
2
+ import { convertToConst } from './common.js';
2
3
  export function inputObjectTypeBuilder() {
3
4
  return {
4
5
  visitSubgraphState(graph, state, typeName, type) {
@@ -7,13 +8,17 @@ export function inputObjectTypeBuilder() {
7
8
  if (type.inaccessible) {
8
9
  inputObjectTypeState.inaccessible = true;
9
10
  }
10
- const isDefinition = type.isDefinition && !type.extension;
11
11
  if (type.description && !inputObjectTypeState.description) {
12
12
  inputObjectTypeState.description = type.description;
13
13
  }
14
14
  if (type.isDefinition) {
15
15
  inputObjectTypeState.hasDefinition = true;
16
16
  }
17
+ if (type.ast.directives) {
18
+ type.ast.directives.forEach(directive => {
19
+ inputObjectTypeState.ast.directives.push(directive);
20
+ });
21
+ }
17
22
  inputObjectTypeState.byGraph.set(graph.id, {
18
23
  inaccessible: type.inaccessible,
19
24
  version: graph.version,
@@ -36,6 +41,9 @@ export function inputObjectTypeBuilder() {
36
41
  if (typeof field.defaultValue !== 'undefined') {
37
42
  fieldState.defaultValue = field.defaultValue;
38
43
  }
44
+ field.ast.directives.forEach(directive => {
45
+ fieldState.ast.directives.push(directive);
46
+ });
39
47
  fieldState.byGraph.set(graph.id, {
40
48
  type: field.type,
41
49
  inaccessible: field.inaccessible,
@@ -50,6 +58,9 @@ export function inputObjectTypeBuilder() {
50
58
  tags: Array.from(inputObjectType.tags),
51
59
  inaccessible: inputObjectType.inaccessible,
52
60
  description: inputObjectType.description,
61
+ ast: {
62
+ directives: convertToConst(inputObjectType.ast.directives),
63
+ },
53
64
  fields: Array.from(inputObjectType.fields.values())
54
65
  .filter(field => {
55
66
  if (field.byGraph.size !== inputObjectType.byGraph.size) {
@@ -70,6 +81,9 @@ export function inputObjectTypeBuilder() {
70
81
  : undefined,
71
82
  description: field.description,
72
83
  deprecated: field.deprecated,
84
+ ast: {
85
+ directives: convertToConst(field.ast.directives),
86
+ },
73
87
  join: {
74
88
  field: hasDifferentType
75
89
  ? Array.from(field.byGraph).map(([graph, fieldByGraph]) => ({
@@ -100,6 +114,9 @@ function getOrCreateInputObjectType(state, typeName) {
100
114
  inaccessible: false,
101
115
  byGraph: new Map(),
102
116
  fields: new Map(),
117
+ ast: {
118
+ directives: [],
119
+ },
103
120
  };
104
121
  state.set(typeName, def);
105
122
  return def;
@@ -115,6 +132,9 @@ function getOrCreateField(objectTypeState, fieldName, fieldType) {
115
132
  tags: new Set(),
116
133
  inaccessible: false,
117
134
  byGraph: new Map(),
135
+ ast: {
136
+ directives: [],
137
+ },
118
138
  };
119
139
  objectTypeState.fields.set(fieldName, def);
120
140
  return def;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theguild/federation-composition",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Open Source Composition library for Apollo Federation",
5
5
  "peerDependencies": {
6
6
  "graphql": "^16.0.0"
@@ -87,6 +87,9 @@ export interface InputObjectType {
87
87
  tags: Set<string>;
88
88
  isDefinition: boolean;
89
89
  description?: Description;
90
+ ast: {
91
+ directives: DirectiveNode[];
92
+ };
90
93
  }
91
94
  export interface UnionType {
92
95
  kind: TypeKind.UNION;
@@ -147,6 +150,9 @@ export interface InputField {
147
150
  defaultValue?: string;
148
151
  description?: Description;
149
152
  deprecated?: Deprecated;
153
+ ast: {
154
+ directives: DirectiveNode[];
155
+ };
150
156
  }
151
157
  export interface EnumValue {
152
158
  name: string;
@@ -323,6 +329,7 @@ export declare function createSubgraphStateBuilder(graph: {
323
329
  setExtension(typeName: string): void;
324
330
  setDescription(typeName: string, description: Description): void;
325
331
  setInaccessible(typeName: string): void;
332
+ setDirective(typeName: string, directive: DirectiveNode): void;
326
333
  setTag(typeName: string, tag: string): void;
327
334
  field: {
328
335
  setType(typeName: string, fieldName: string, fieldType: string): void;
@@ -331,6 +338,7 @@ export declare function createSubgraphStateBuilder(graph: {
331
338
  setDefaultValue(typeName: string, fieldName: string, defaultValue: string): void;
332
339
  setInaccessible(typeName: string, fieldName: string): void;
333
340
  setTag(typeName: string, fieldName: string, tag: string): void;
341
+ setDirective(typeName: string, fieldName: string, directive: DirectiveNode): void;
334
342
  };
335
343
  };
336
344
  unionType: {
@@ -87,6 +87,9 @@ export interface InputObjectType {
87
87
  tags: Set<string>;
88
88
  isDefinition: boolean;
89
89
  description?: Description;
90
+ ast: {
91
+ directives: DirectiveNode[];
92
+ };
90
93
  }
91
94
  export interface UnionType {
92
95
  kind: TypeKind.UNION;
@@ -147,6 +150,9 @@ export interface InputField {
147
150
  defaultValue?: string;
148
151
  description?: Description;
149
152
  deprecated?: Deprecated;
153
+ ast: {
154
+ directives: DirectiveNode[];
155
+ };
150
156
  }
151
157
  export interface EnumValue {
152
158
  name: string;
@@ -323,6 +329,7 @@ export declare function createSubgraphStateBuilder(graph: {
323
329
  setExtension(typeName: string): void;
324
330
  setDescription(typeName: string, description: Description): void;
325
331
  setInaccessible(typeName: string): void;
332
+ setDirective(typeName: string, directive: DirectiveNode): void;
326
333
  setTag(typeName: string, tag: string): void;
327
334
  field: {
328
335
  setType(typeName: string, fieldName: string, fieldType: string): void;
@@ -331,6 +338,7 @@ export declare function createSubgraphStateBuilder(graph: {
331
338
  setDefaultValue(typeName: string, fieldName: string, defaultValue: string): void;
332
339
  setInaccessible(typeName: string, fieldName: string): void;
333
340
  setTag(typeName: string, fieldName: string, tag: string): void;
341
+ setDirective(typeName: string, fieldName: string, directive: DirectiveNode): void;
334
342
  };
335
343
  };
336
344
  unionType: {
@@ -136,6 +136,7 @@ export declare function createSubgraphValidationContext(subgraph: {
136
136
  setExtension(typeName: string): void;
137
137
  setDescription(typeName: string, description: import("../state.js").Description): void;
138
138
  setInaccessible(typeName: string): void;
139
+ setDirective(typeName: string, directive: import("graphql").DirectiveNode): void;
139
140
  setTag(typeName: string, tag: string): void;
140
141
  field: {
141
142
  setType(typeName: string, fieldName: string, fieldType: string): void;
@@ -144,6 +145,7 @@ export declare function createSubgraphValidationContext(subgraph: {
144
145
  setDefaultValue(typeName: string, fieldName: string, defaultValue: string): void;
145
146
  setInaccessible(typeName: string, fieldName: string): void;
146
147
  setTag(typeName: string, fieldName: string, tag: string): void;
148
+ setDirective(typeName: string, fieldName: string, directive: import("graphql").DirectiveNode): void;
147
149
  };
148
150
  };
149
151
  unionType: {
@@ -136,6 +136,7 @@ export declare function createSubgraphValidationContext(subgraph: {
136
136
  setExtension(typeName: string): void;
137
137
  setDescription(typeName: string, description: import("../state.js").Description): void;
138
138
  setInaccessible(typeName: string): void;
139
+ setDirective(typeName: string, directive: import("graphql").DirectiveNode): void;
139
140
  setTag(typeName: string, tag: string): void;
140
141
  field: {
141
142
  setType(typeName: string, fieldName: string, fieldType: string): void;
@@ -144,6 +145,7 @@ export declare function createSubgraphValidationContext(subgraph: {
144
145
  setDefaultValue(typeName: string, fieldName: string, defaultValue: string): void;
145
146
  setInaccessible(typeName: string, fieldName: string): void;
146
147
  setTag(typeName: string, fieldName: string, tag: string): void;
148
+ setDirective(typeName: string, fieldName: string, directive: import("graphql").DirectiveNode): void;
147
149
  };
148
150
  };
149
151
  unionType: {
@@ -1,6 +1,7 @@
1
+ import { DirectiveNode } from 'graphql';
1
2
  import { FederationVersion } from '../../specifications/federation.cjs';
2
3
  import { Deprecated, Description, InputObjectType } 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 inputObjectTypeBuilder(): TypeBuilder<InputObjectType, InputObjectTypeState>;
5
6
  export interface InputObjectTypeState {
6
7
  kind: 'input';
@@ -11,6 +12,9 @@ export interface InputObjectTypeState {
11
12
  description?: Description;
12
13
  byGraph: MapByGraph<InputObjectTypeStateInGraph>;
13
14
  fields: Map<string, InputObjectTypeFieldState>;
15
+ ast: {
16
+ directives: DirectiveNode[];
17
+ };
14
18
  }
15
19
  export type InputObjectTypeFieldState = {
16
20
  name: string;
@@ -21,6 +25,9 @@ export type InputObjectTypeFieldState = {
21
25
  description?: Description;
22
26
  deprecated?: Deprecated;
23
27
  byGraph: MapByGraph<InputObjectFieldStateInGraph>;
28
+ ast: {
29
+ directives: DirectiveNode[];
30
+ };
24
31
  };
25
32
  type InputObjectTypeStateInGraph = {
26
33
  inaccessible: boolean;
@@ -1,6 +1,7 @@
1
+ import { DirectiveNode } from 'graphql';
1
2
  import { FederationVersion } from '../../specifications/federation.js';
2
3
  import { Deprecated, Description, InputObjectType } 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 inputObjectTypeBuilder(): TypeBuilder<InputObjectType, InputObjectTypeState>;
5
6
  export interface InputObjectTypeState {
6
7
  kind: 'input';
@@ -11,6 +12,9 @@ export interface InputObjectTypeState {
11
12
  description?: Description;
12
13
  byGraph: MapByGraph<InputObjectTypeStateInGraph>;
13
14
  fields: Map<string, InputObjectTypeFieldState>;
15
+ ast: {
16
+ directives: DirectiveNode[];
17
+ };
14
18
  }
15
19
  export type InputObjectTypeFieldState = {
16
20
  name: string;
@@ -21,6 +25,9 @@ export type InputObjectTypeFieldState = {
21
25
  description?: Description;
22
26
  deprecated?: Deprecated;
23
27
  byGraph: MapByGraph<InputObjectFieldStateInGraph>;
28
+ ast: {
29
+ directives: DirectiveNode[];
30
+ };
24
31
  };
25
32
  type InputObjectTypeStateInGraph = {
26
33
  inaccessible: boolean;