@graphprotocol/graph-cli 0.56.1-alpha-20230831035057-3d319d2 → 0.57.0-alpha-20230831103613-4c8bdf8

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.
package/CHANGELOG.md CHANGED
@@ -1,17 +1,13 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.56.1-alpha-20230831035057-3d319d2
3
+ ## 0.57.0-alpha-20230831103613-4c8bdf8
4
4
 
5
- ### Patch Changes
6
-
7
- - [#1433](https://github.com/graphprotocol/graph-tooling/pull/1433)
8
- [`3d319d2`](https://github.com/graphprotocol/graph-tooling/commit/3d319d2bf39856b1e8e106b16302bbe40d3028b5)
9
- Thanks [@saihaj](https://github.com/saihaj)! - when generating nested tuples make sure they are
10
- non-nullable
5
+ ### Minor Changes
11
6
 
12
- - [#1433](https://github.com/graphprotocol/graph-tooling/pull/1433)
13
- [`8287a05`](https://github.com/graphprotocol/graph-tooling/commit/8287a058f9991bb7fa5591142af6dd17cf2fb77d)
14
- Thanks [@saihaj](https://github.com/saihaj)! - 2D arrays are valid entities
7
+ - [#1434](https://github.com/graphprotocol/graph-tooling/pull/1434)
8
+ [`4c8bdf8`](https://github.com/graphprotocol/graph-tooling/commit/4c8bdf8acb655cd397f24f2e1639baf6cff4ac3e)
9
+ Thanks [@incrypto32](https://github.com/incrypto32)! - Add data source context support in ethereum
10
+ manifest
15
11
 
16
12
  ## 0.56.0
17
13
 
package/dist/debug.js CHANGED
@@ -11,12 +11,6 @@ debug_1.default.formatters.M = immutableMap => {
11
11
  if (immutableMap.toMap != null) {
12
12
  return JSON.stringify(immutableMap.toMap());
13
13
  }
14
- if (typeof immutableMap.toJS === 'function') {
15
- return JSON.stringify(immutableMap.toJS());
16
- }
17
- if (typeof immutableMap === 'object') {
18
- return JSON.stringify(immutableMap);
19
- }
20
14
  return immutableMap;
21
15
  };
22
16
  exports.default = debug_1.default;
@@ -8,6 +8,7 @@ scalar String
8
8
  scalar File
9
9
  scalar BigInt
10
10
  scalar Boolean
11
+ scalar JSON
11
12
 
12
13
  type SubgraphManifest {
13
14
  specVersion: String!
@@ -28,6 +29,7 @@ type DataSource {
28
29
  kind: String!
29
30
  name: String!
30
31
  network: String
32
+ context: JSON
31
33
  source: ContractSource!
32
34
  mapping: ContractMapping!
33
35
  }
@@ -46,18 +46,14 @@ const protocolTypeToGraphQL = (protocol, name) => {
46
46
  // TODO: this is a hack to make array type non-nullable
47
47
  // We should refactor the way we convert the Values from ASC to GraphQL
48
48
  // For arrays we always want non-nullable children
49
- return convertedType.endsWith(']') ? convertedType.replace(/\]/g, '!]') : convertedType;
49
+ return convertedType.endsWith(']') ? convertedType.replace(']', '!]') : convertedType;
50
50
  };
51
51
  exports.protocolTypeToGraphQL = protocolTypeToGraphQL;
52
52
  const generateField = ({ name, type, protocolName, }) => `${name}: ${(0, exports.protocolTypeToGraphQL)(protocolName, type)}! # ${type}`;
53
53
  exports.generateField = generateField;
54
54
  const generateEventFields = ({ index, input, protocolName, }) => input.type == 'tuple'
55
55
  ? util
56
- .unrollTuple({
57
- value: input,
58
- path: [input.name || `param${index}`],
59
- index,
60
- })
56
+ .unrollTuple({ value: input, path: [input.name || `param${index}`], index })
61
57
  .map(({ path, type }) => (0, exports.generateField)({ name: path.join('_'), type, protocolName }))
62
58
  : [
63
59
  (0, exports.generateField)({
package/dist/subgraph.js CHANGED
@@ -49,9 +49,8 @@ const buildCombinedWarning = (filename, warnings) => warnings.size > 0
49
49
  : null;
50
50
  class Subgraph {
51
51
  static async validate(data, protocol, { resolveFile }) {
52
- subgraphDebug.extend('validate')('Validating Subgraph with protocol %M', protocol);
52
+ subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol);
53
53
  if (protocol.name == null) {
54
- subgraphDebug.extend('validate')('Protocol has no name, skipping validation');
55
54
  return immutable_1.default.fromJS([
56
55
  {
57
56
  path: [],
@@ -67,18 +66,13 @@ class Subgraph {
67
66
  return definition.name.value === 'SubgraphManifest';
68
67
  });
69
68
  // Validate the subgraph manifest using this schema
70
- return validation.validateManifest(data, rootType, schema, protocol, {
71
- resolveFile,
72
- });
69
+ return validation.validateManifest(data, rootType, schema, protocol, { resolveFile });
73
70
  }
74
71
  static validateSchema(manifest, { resolveFile }) {
75
- subgraphDebug.extend('validate')('Validating schema in manifest');
76
72
  const filename = resolveFile(manifest.getIn(['schema', 'file']));
77
- subgraphDebug.extend('validate')('Loaded schema from %s', filename);
78
73
  const validationErrors = validation.validateSchema(filename);
79
74
  let errors;
80
75
  if (validationErrors.size > 0) {
81
- subgraphDebug.extend('validate')('Schema validation failed for %s', filename);
82
76
  errors = validationErrors.groupBy(error => error.get('entity')).sort();
83
77
  const msg = errors.reduce((msg, errors, entity) => {
84
78
  errors = errors.groupBy((error) => error.get('directive'));
@@ -100,7 +94,6 @@ class Subgraph {
100
94
  }
101
95
  }
102
96
  static validateRepository(manifest) {
103
- subgraphDebug.extend('validate')('Validating repository in manifest');
104
97
  const repository = manifest.get('repository');
105
98
  return /^https:\/\/github\.com\/graphprotocol\/graph-tooling?$/.test(repository) ||
106
99
  // For legacy reasons, we should error on example subgraphs
@@ -114,7 +107,6 @@ Please replace it with a link to your subgraph source code.`,
114
107
  : immutable_1.default.List();
115
108
  }
116
109
  static validateDescription(manifest) {
117
- subgraphDebug.extend('validate')('Validating description in manifest');
118
110
  // TODO: Maybe implement this in the future for each protocol example description
119
111
  return manifest.get('description', '').startsWith('Gravatar for ')
120
112
  ? immutable_1.default.List().push(immutable_1.default.fromJS({
@@ -126,7 +118,6 @@ Please update it to tell users more about your subgraph.`,
126
118
  : immutable_1.default.List();
127
119
  }
128
120
  static validateHandlers(manifest, protocol, protocolSubgraph) {
129
- subgraphDebug.extend('validate')('Validating handlers for protocol %s', protocol?.name);
130
121
  return manifest
131
122
  .get('dataSources')
132
123
  .filter((dataSource) => protocol.isValidKindName(dataSource.get('kind')))
@@ -134,7 +125,7 @@ Please update it to tell users more about your subgraph.`,
134
125
  const path = ['dataSources', dataSourceIndex, 'mapping'];
135
126
  const mapping = dataSource.get('mapping');
136
127
  const handlerTypes = protocolSubgraph.handlerTypes();
137
- subgraphDebug.extend('validate')('Validating dataSource "%s" handlers with %d handlers types defined for protocol', dataSource.get('name'), handlerTypes.size);
128
+ subgraphDebug('Validating dataSource "%s" handlers with %d handlers types defined for protocol', dataSource.get('name'), handlerTypes.size);
138
129
  if (handlerTypes.size == 0) {
139
130
  return errors;
140
131
  }
@@ -153,16 +144,13 @@ At least one such handler must be defined.`,
153
144
  }, immutable_1.default.List());
154
145
  }
155
146
  static validateContractValues(manifest, protocol) {
156
- subgraphDebug.extend('validate')('Validating contract values for protocol %s', protocol?.name);
157
147
  if (!protocol.hasContract()) {
158
- subgraphDebug.extend('validate')('Protocol has no contract, skipping validation');
159
148
  return immutable_1.default.List();
160
149
  }
161
150
  return validation.validateContractValues(manifest, protocol);
162
151
  }
163
152
  // Validate that data source names are unique, so they don't overwrite each other.
164
153
  static validateUniqueDataSourceNames(manifest) {
165
- subgraphDebug.extend('validate')('Validating that data source names are unique');
166
154
  const names = [];
167
155
  return manifest
168
156
  .get('dataSources')
@@ -170,7 +158,6 @@ At least one such handler must be defined.`,
170
158
  const path = ['dataSources', dataSourceIndex, 'name'];
171
159
  const name = dataSource.get('name');
172
160
  if (names.includes(name)) {
173
- subgraphDebug.extend('validate')("Found duplicate data source name '%s', adding error");
174
161
  errors = errors.push(immutable_1.default.fromJS({
175
162
  path,
176
163
  message: `\
@@ -182,7 +169,6 @@ More than one data source named '${name}', data source names must be unique.`,
182
169
  }, immutable_1.default.List());
183
170
  }
184
171
  static validateUniqueTemplateNames(manifest) {
185
- subgraphDebug.extend('validate')('Validating that template names are unique');
186
172
  const names = [];
187
173
  return manifest
188
174
  .get('templates', immutable_1.default.List())
@@ -190,7 +176,6 @@ More than one data source named '${name}', data source names must be unique.`,
190
176
  const path = ['templates', templateIndex, 'name'];
191
177
  const name = template.get('name');
192
178
  if (names.includes(name)) {
193
- subgraphDebug.extend('validate')("Found duplicate template name '%s', adding error");
194
179
  errors = errors.push(immutable_1.default.fromJS({
195
180
  path,
196
181
  message: `\
@@ -217,30 +202,21 @@ More than one template named '${name}', template names must be unique.`,
217
202
  data = require(path_1.default.resolve(filename));
218
203
  }
219
204
  else {
220
- subgraphDebug('Loading manifest from %s', filename);
221
205
  const raw_data = await fs_extra_1.default.readFile(filename, 'utf-8');
222
- subgraphDebug('Checking for file data sources in %s', filename);
223
206
  has_file_data_sources = raw_data.includes('kind: file');
224
- subgraphDebug('Parsing manifest from %s', filename);
225
207
  data = yaml_1.default.parse(raw_data);
226
208
  }
227
209
  // Helper to resolve files relative to the subgraph manifest
228
210
  const resolveFile = maybeRelativeFile => path_1.default.resolve(path_1.default.dirname(filename), maybeRelativeFile);
229
211
  // TODO: Validation for file data sources
230
212
  if (!has_file_data_sources) {
231
- subgraphDebug('Validating manifest from %s', filename);
232
- const manifestErrors = await Subgraph.validate(data, protocol, {
233
- resolveFile,
234
- });
213
+ const manifestErrors = await Subgraph.validate(data, protocol, { resolveFile });
235
214
  if (manifestErrors.size > 0) {
236
- subgraphDebug('Manifest validation failed for %s', filename);
237
215
  throwCombinedError(filename, manifestErrors);
238
216
  }
239
217
  }
240
218
  const manifest = immutable_1.default.fromJS(data);
241
- subgraphDebug.extend('manifest')('Loaded: %M', manifest);
242
219
  // Validate the schema
243
- subgraphDebug.extend('manifest')('Validating schema');
244
220
  Subgraph.validateSchema(manifest, { resolveFile });
245
221
  // Perform other validations
246
222
  const protocolSubgraph = protocol.getSubgraph({
@@ -154,6 +154,20 @@ const validators = immutable_1.default.fromJS({
154
154
  message: `Expected filename, found ${typeName(value)}:\n${value}`,
155
155
  },
156
156
  ]),
157
+ JSON: (value, ctx) => {
158
+ try {
159
+ JSON.parse(JSON.stringify(value));
160
+ return List();
161
+ }
162
+ catch (e) {
163
+ return immutable_1.default.fromJS([
164
+ {
165
+ path: ctx.get('path'),
166
+ message: `Invalid JSON value: ${e.message}`,
167
+ },
168
+ ]);
169
+ }
170
+ },
157
171
  Boolean: (value, ctx) => typeof value === 'boolean'
158
172
  ? List()
159
173
  : immutable_1.default.fromJS([
@@ -30,8 +30,6 @@ exports.validateSchema = exports.typeSuggestion = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const graphql = __importStar(require("graphql/language"));
32
32
  const immutable_1 = __importDefault(require("immutable"));
33
- const debug_1 = __importDefault(require("../debug"));
34
- const validateDebugger = (0, debug_1.default)('graph-cli:validation');
35
33
  const List = immutable_1.default.List;
36
34
  const Set = immutable_1.default.Set;
37
35
  // Builtin scalar types
@@ -103,23 +101,18 @@ const parseSchema = (doc) => {
103
101
  throw new Error(`Invalid GraphQL schema: ${e}`);
104
102
  }
105
103
  };
106
- const validateEntityDirective = (def) => {
107
- validateDebugger('Validating entity directive for %s', def?.name?.value);
108
- return def.directives.find((directive) => directive.name.value === 'entity')
109
- ? List()
110
- : immutable_1.default.fromJS([
111
- {
112
- loc: def.loc,
113
- entity: def.name.value,
114
- message: `Defined without @entity directive`,
115
- },
116
- ]);
117
- };
104
+ const validateEntityDirective = (def) => def.directives.find((directive) => directive.name.value === 'entity')
105
+ ? List()
106
+ : immutable_1.default.fromJS([
107
+ {
108
+ loc: def.loc,
109
+ entity: def.name.value,
110
+ message: `Defined without @entity directive`,
111
+ },
112
+ ]);
118
113
  const validateEntityID = (def) => {
119
- validateDebugger('Validating entity ID for %s', def?.name?.value);
120
114
  const idField = def.fields.find((field) => field.name.value === 'id');
121
115
  if (idField === undefined) {
122
- validateDebugger('Entity %s has no id field', def?.name?.value);
123
116
  return immutable_1.default.fromJS([
124
117
  {
125
118
  loc: def.loc,
@@ -133,10 +126,8 @@ const validateEntityID = (def) => {
133
126
  (idField.type.type.name.value === 'ID' ||
134
127
  idField.type.type.name.value === 'Bytes' ||
135
128
  idField.type.type.name.value === 'String')) {
136
- validateDebugger('Entity %s has valid id field', def?.name?.value);
137
129
  return List();
138
130
  }
139
- validateDebugger('Entity %s has invalid id field', def?.name?.value);
140
131
  return immutable_1.default.fromJS([
141
132
  {
142
133
  loc: idField.loc,
@@ -145,80 +136,52 @@ const validateEntityID = (def) => {
145
136
  },
146
137
  ]);
147
138
  };
148
- const validateListFieldType = (def, field) => {
149
- validateDebugger('Validating list field type for %s', def?.name?.value);
150
- return field.type.kind === 'NonNullType' &&
151
- field.type.kind === 'ListType' &&
152
- field.type.type.kind !== 'NonNullType'
153
- ? immutable_1.default.fromJS([
154
- {
155
- loc: field.loc,
156
- entity: def.name.value,
157
- message: `\
139
+ const validateListFieldType = (def, field) => field.type.kind === 'NonNullType' &&
140
+ field.type.kind === 'ListType' &&
141
+ field.type.type.kind !== 'NonNullType'
142
+ ? immutable_1.default.fromJS([
143
+ {
144
+ loc: field.loc,
145
+ entity: def.name.value,
146
+ message: `\
158
147
  Field '${field.name.value}':
159
148
  Field has type [${field.type.type.name.value}]! but
160
149
  must have type [${field.type.type.name.value}!]!
161
150
 
162
151
  Reason: Lists with null elements are not supported.`,
163
- },
164
- ])
165
- : field.type.kind === 'ListType' && field.type.type.kind !== 'NonNullType'
166
- ? immutable_1.default.fromJS([
167
- {
168
- loc: field.loc,
169
- entity: def.name.value,
170
- message: `\
152
+ },
153
+ ])
154
+ : field.type.kind === 'ListType' && field.type.type.kind !== 'NonNullType'
155
+ ? immutable_1.default.fromJS([
156
+ {
157
+ loc: field.loc,
158
+ entity: def.name.value,
159
+ message: `\
171
160
  Field '${field.name.value}':
172
161
  Field has type [${field.type.type.name.value}] but
173
162
  must have type [${field.type.type.name.value}!]
174
163
 
175
164
  Reason: Lists with null elements are not supported.`,
176
- },
177
- ])
178
- : List();
179
- };
165
+ },
166
+ ])
167
+ : List();
180
168
  const unwrapType = (type) => {
181
- validateDebugger.extend('definition')('Unwrapping type %M', type);
182
- const innerTypeFromList = (listType) => {
183
- validateDebugger.extend('unwrapType').extend('definition')('Unwrapping list type %M', listType);
184
- if (listType.type.kind === 'NonNullType') {
185
- validateDebugger.extend('unwrapType').extend('innerTypeFromList')('Returning non-null list type');
186
- return innerTypeFromNonNull(listType.type);
187
- }
188
- validateDebugger.extend('unwrapType').extend('innerTypeFromList')('Returning list type');
189
- return unwrapType(listType.type);
190
- };
191
- const innerTypeFromNonNull = (nonNullType) => {
192
- validateDebugger.extend('unwrapType').extend('definition')('Unwrapping non-null type %M', nonNullType);
193
- if (nonNullType.type.kind === 'ListType') {
194
- validateDebugger.extend('unwrapType').extend('innerTypeFromNonNull')('Returning non-null list type');
195
- return innerTypeFromList(nonNullType.type);
196
- }
197
- validateDebugger.extend('unwrapType').extend('innerTypeFromNonNull')('Returning non-null type');
198
- return unwrapType(nonNullType.type);
199
- };
169
+ const innerTypeFromList = (listType) => listType.type.kind === 'NonNullType' ? innerTypeFromNonNull(listType.type) : listType.type;
170
+ const innerTypeFromNonNull = (nonNullType) => nonNullType.type.kind === 'ListType' ? innerTypeFromList(nonNullType.type) : nonNullType.type;
200
171
  // Obtain the inner-most type from the field
201
- if (type.kind === 'NonNullType') {
202
- validateDebugger('Returning inner type from non-null type');
203
- return innerTypeFromNonNull(type);
204
- }
205
- if (type.kind === 'ListType') {
206
- validateDebugger('Returning inner type from list type');
207
- return innerTypeFromList(type);
208
- }
209
- validateDebugger('Returning inner type');
210
- return type;
211
- };
212
- const gatherLocalTypes = (defs) => {
213
- validateDebugger('Gathering local types');
214
- return defs
215
- .filter(def => def.kind === 'ObjectTypeDefinition' ||
216
- def.kind === 'EnumTypeDefinition' ||
217
- def.kind === 'InterfaceTypeDefinition')
218
- .map(def =>
219
- // @ts-expect-error TODO: name field does not exist on definition, really?
220
- def.name.value);
221
- };
172
+ return type.kind === 'NonNullType'
173
+ ? innerTypeFromNonNull(type)
174
+ : type.kind === 'ListType'
175
+ ? innerTypeFromList(type)
176
+ : type;
177
+ };
178
+ const gatherLocalTypes = (defs) => defs
179
+ .filter(def => def.kind === 'ObjectTypeDefinition' ||
180
+ def.kind === 'EnumTypeDefinition' ||
181
+ def.kind === 'InterfaceTypeDefinition')
182
+ .map(def =>
183
+ // @ts-expect-error TODO: name field does not exist on definition, really?
184
+ def.name.value);
222
185
  const gatherImportedTypes = (defs) => defs
223
186
  .filter(def => def.kind === 'ObjectTypeDefinition' &&
224
187
  def.name.value == RESERVED_TYPE &&
@@ -243,28 +206,19 @@ def.directives
243
206
  }
244
207
  return flattened;
245
208
  }, [])), []);
246
- const entityTypeByName = (defs, name) => {
247
- validateDebugger('Looking up entity type %s', name);
248
- return defs
249
- .filter(def => def.kind === 'InterfaceTypeDefinition' ||
250
- (def.kind === 'ObjectTypeDefinition' &&
251
- def.directives.find((directive) => directive.name.value === 'entity')))
252
- .find(def => def.name.value === name);
253
- };
254
- const fieldTargetEntityName = (field) => {
255
- validateDebugger('Looking up field target entity name for %s', field?.name?.value);
256
- return unwrapType(field.type).name.value;
257
- };
209
+ const entityTypeByName = (defs, name) => defs
210
+ .filter(def => def.kind === 'InterfaceTypeDefinition' ||
211
+ (def.kind === 'ObjectTypeDefinition' &&
212
+ def.directives.find((directive) => directive.name.value === 'entity')))
213
+ .find(def => def.name.value === name);
214
+ const fieldTargetEntityName = (field) => unwrapType(field.type).name.value;
258
215
  const fieldTargetEntity = (defs, field) => entityTypeByName(defs, fieldTargetEntityName(field));
259
216
  const validateInnerFieldType = (defs, def, field) => {
260
- validateDebugger('Validating inner field type for %s', def?.name?.value);
261
217
  const innerType = unwrapType(field.type);
262
218
  // Get the name of the type
263
219
  const typeName = innerType.name.value;
264
- validateDebugger('Inner field type name: %s', typeName);
265
220
  // Look up a possible suggestion for the type to catch common mistakes
266
221
  const suggestion = (0, exports.typeSuggestion)(typeName);
267
- validateDebugger('Inner field type suggestion: %s', suggestion);
268
222
  // Collect all types that we can use here: built-ins + entities + enums + interfaces
269
223
  const availableTypes = List.of(...BUILTIN_SCALAR_TYPES, ...gatherLocalTypes(defs), ...gatherImportedTypes(defs));
270
224
  // Check whether the type name is available, otherwise return an error
@@ -338,7 +292,6 @@ does not exist on type '${targetEntity.name.value}'`,
338
292
  ]);
339
293
  }
340
294
  const backrefTypeName = unwrapType(derivedFromField.type);
341
- validateDebugger.extend('definition')('Backref type name: %M', backrefTypeName);
342
295
  const backRefEntity = entityTypeByName(defs, backrefTypeName.name.value);
343
296
  // The field we are deriving from must either have type 'def' or one of the
344
297
  // interface types that 'def' is implementing
@@ -729,7 +682,6 @@ const validateImportDirectiveArgumentFrom = (def, directive, argument) => {
729
682
  }, List());
730
683
  };
731
684
  const validateImportDirectiveFields = (def, directive) => {
732
- validateDebugger('Validating import directive fields: %s', def?.name?.value);
733
685
  return directive.arguments.reduce((errors, argument) => {
734
686
  return errors.concat(['types', 'from'].includes(argument.name.value)
735
687
  ? List([])
@@ -743,7 +695,6 @@ const validateImportDirectiveFields = (def, directive) => {
743
695
  }, List([]));
744
696
  };
745
697
  const validateImportDirectiveTypes = (def, directive) => {
746
- validateDebugger('Validating import directive types: %s', def?.name?.value);
747
698
  const types = directive.arguments.find((argument) => argument.name.value == 'types');
748
699
  return types
749
700
  ? validateImportDirectiveArgumentTypes(def, directive, types)
@@ -756,7 +707,6 @@ const validateImportDirectiveTypes = (def, directive) => {
756
707
  ]);
757
708
  };
758
709
  const validateImportDirectiveFrom = (def, directive) => {
759
- validateDebugger('Validating import directive from: %s', def?.name?.value);
760
710
  const from = directive.arguments.find((argument) => argument.name.value == 'from');
761
711
  return from
762
712
  ? validateImportDirectiveArgumentFrom(def, directive, from)
@@ -768,19 +718,13 @@ const validateImportDirectiveFrom = (def, directive) => {
768
718
  }),
769
719
  ]);
770
720
  };
771
- const validateImportDirective = (def, directive) => {
772
- validateDebugger('Validating import directive: %s', def?.name?.value);
773
- return List.of(...validateImportDirectiveFields(def, directive), ...validateImportDirectiveTypes(def, directive), ...validateImportDirectiveFrom(def, directive));
774
- };
721
+ const validateImportDirective = (def, directive) => List.of(...validateImportDirectiveFields(def, directive), ...validateImportDirectiveTypes(def, directive), ...validateImportDirectiveFrom(def, directive));
775
722
  const validateFulltext = (def, directive) => List.of(...validateFulltextFields(def, directive), ...validateFulltextName(def, directive), ...validateFulltextLanguage(def, directive), ...validateFulltextAlgorithm(def, directive), ...validateFulltextInclude(def, directive));
776
723
  const validateSubgraphSchemaDirective = (def, directive) => {
777
- validateDebugger('Validating subgraph schema directive: %s', def?.name?.value);
778
724
  if (directive.name.value == 'import') {
779
- validateDebugger('Validating import directive: %s', def?.name?.value);
780
725
  return validateImportDirective(def, directive);
781
726
  }
782
727
  if (directive.name.value == 'fulltext') {
783
- validateDebugger('Validating fulltext directive: %s', def?.name?.value);
784
728
  return validateFulltext(def, directive);
785
729
  }
786
730
  return List([
@@ -791,52 +735,32 @@ const validateSubgraphSchemaDirective = (def, directive) => {
791
735
  }),
792
736
  ]);
793
737
  };
794
- const validateSubgraphSchemaDirectives = (def) => {
795
- validateDebugger('Validating subgraph schema directives: %s', def?.name?.value);
796
- return def.directives.reduce((errors, directive) => errors.concat(validateSubgraphSchemaDirective(def, directive)), List());
797
- };
798
- const validateTypeHasNoFields = (def) => {
799
- validateDebugger('Validating type has no fields: %s', def?.name?.value);
800
- return def.fields.length
801
- ? List([
802
- immutable_1.default.fromJS({
803
- loc: def.name.loc,
804
- entity: def.name.value,
805
- message: `${def.name.value} type is not allowed any fields by convention`,
806
- }),
807
- ])
808
- : List();
809
- };
738
+ const validateSubgraphSchemaDirectives = (def) => def.directives.reduce((errors, directive) => errors.concat(validateSubgraphSchemaDirective(def, directive)), List());
739
+ const validateTypeHasNoFields = (def) => def.fields.length
740
+ ? List([
741
+ immutable_1.default.fromJS({
742
+ loc: def.name.loc,
743
+ entity: def.name.value,
744
+ message: `${def.name.value} type is not allowed any fields by convention`,
745
+ }),
746
+ ])
747
+ : List();
810
748
  const validateAtLeastOneExtensionField = (_def) => List();
811
749
  const typeDefinitionValidators = {
812
- ObjectTypeDefinition: (defs, def) => {
813
- validateDebugger('Validating object type definition: %s', def?.name?.value);
814
- return def.name && def.name.value == RESERVED_TYPE
815
- ? List.of(...validateSubgraphSchemaDirectives(def), ...validateTypeHasNoFields(def))
816
- : List.of(...validateEntityDirective(def), ...validateEntityID(def), ...validateEntityFields(defs, def), ...validateNoImportDirective(def), ...validateNoFulltext(def));
817
- },
818
- ObjectTypeExtension: (_defs, def) => {
819
- validateDebugger('Validating object type extension: %s', def?.name?.value);
820
- return validateAtLeastOneExtensionField(def);
821
- },
822
- };
823
- const validateTypeDefinition = (defs, def) => {
824
- validateDebugger.extend('definition')('Validating type definition: %M', def);
825
- return typeDefinitionValidators[def.kind] === undefined
826
- ? List()
827
- : typeDefinitionValidators[def.kind](defs, def);
828
- };
829
- const validateTypeDefinitions = (defs) => {
830
- validateDebugger('Validating type definitions');
831
- return defs.reduce((errors, def) => errors.concat(validateTypeDefinition(defs, def)), List());
832
- };
750
+ ObjectTypeDefinition: (defs, def) => def.name && def.name.value == RESERVED_TYPE
751
+ ? List.of(...validateSubgraphSchemaDirectives(def), ...validateTypeHasNoFields(def))
752
+ : List.of(...validateEntityDirective(def), ...validateEntityID(def), ...validateEntityFields(defs, def), ...validateNoImportDirective(def), ...validateNoFulltext(def)),
753
+ ObjectTypeExtension: (_defs, def) => validateAtLeastOneExtensionField(def),
754
+ };
755
+ const validateTypeDefinition = (defs, def) => typeDefinitionValidators[def.kind] === undefined
756
+ ? List()
757
+ : typeDefinitionValidators[def.kind](defs, def);
758
+ const validateTypeDefinitions = (defs) => defs.reduce((errors, def) => errors.concat(validateTypeDefinition(defs, def)), List());
833
759
  const validateNamingCollisionsInTypes = (types) => {
834
- validateDebugger('Validating naming collisions in types');
835
760
  let seen = Set();
836
761
  let conflicting = Set();
837
762
  return types.reduce((errors, type) => {
838
763
  if (seen.has(type) && !conflicting.has(type)) {
839
- validateDebugger('Found naming collision');
840
764
  errors = errors.push(immutable_1.default.fromJS({
841
765
  loc: { start: 1, end: 1 },
842
766
  entity: type,
@@ -850,16 +774,10 @@ const validateNamingCollisionsInTypes = (types) => {
850
774
  return errors;
851
775
  }, List());
852
776
  };
853
- const validateNamingCollisions = (local, imported) => {
854
- validateDebugger('Validating naming collisions');
855
- return validateNamingCollisionsInTypes(local.concat(imported));
856
- };
777
+ const validateNamingCollisions = (local, imported) => validateNamingCollisionsInTypes(local.concat(imported));
857
778
  const validateSchema = (filename) => {
858
- validateDebugger('Validating schema: %s', filename);
859
779
  const doc = loadSchema(filename);
860
- validateDebugger('Loaded schema: %s', filename);
861
780
  const schema = parseSchema(doc);
862
- validateDebugger.extend('schema')('Parsed schema: %M', schema);
863
781
  return List.of(...validateTypeDefinitions(schema.definitions), ...validateNamingCollisions(gatherLocalTypes(schema.definitions), gatherImportedTypes(schema.definitions)));
864
782
  };
865
783
  exports.validateSchema = validateSchema;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.56.1-alpha-20230831035057-3d319d2",
2
+ "version": "0.57.0-alpha-20230831103613-4c8bdf8",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.56.1-alpha-20230831035057-3d319d2",
3
+ "version": "0.57.0-alpha-20230831103613-4c8bdf8",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {