@graphprotocol/graph-cli 0.26.0 → 0.28.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.
Files changed (38) hide show
  1. package/README.md +6 -6
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +1 -1
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/tendermint.ts +554 -0
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +52 -2
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +11 -0
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +47 -0
  7. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +150 -1
  8. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +2 -0
  9. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +2 -1
  10. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +2 -0
  11. package/examples/basic-event-handlers/package.json +5 -5
  12. package/examples/basic-event-handlers/yarn.lock +12 -12
  13. package/examples/example-subgraph/package.json +1 -1
  14. package/examples/example-subgraph/yarn.lock +4 -4
  15. package/package.json +27 -24
  16. package/src/codegen/schema.js +104 -25
  17. package/src/codegen/schema.test.js +3 -7
  18. package/src/commands/codegen.js +1 -1
  19. package/src/commands/deploy.js +4 -2
  20. package/src/commands/init.js +3 -0
  21. package/src/commands/test.js +82 -59
  22. package/src/protocols/ethereum/codegen/abi.js +72 -2
  23. package/src/protocols/ethereum/manifest.graphql +92 -0
  24. package/src/protocols/index.js +51 -7
  25. package/src/protocols/near/manifest.graphql +57 -0
  26. package/src/protocols/tendermint/manifest.graphql +64 -0
  27. package/src/protocols/tendermint/subgraph.js +20 -0
  28. package/src/scaffold/index.js +1 -1
  29. package/src/subgraph.js +22 -13
  30. package/src/validation/manifest.js +29 -8
  31. package/src/validation/schema.js +120 -119
  32. package/tests/cli/validation/example-values-found.stderr +2 -2
  33. package/tests/cli/validation/invalid-manifest/subgraph.yaml +2 -1
  34. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +12 -0
  35. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +5 -0
  36. package/tests/cli/validation/invalid-manifest.stderr +0 -3
  37. package/tests/cli/validation.test.js +8 -0
  38. package/manifest-schema.graphql +0 -122
@@ -76,12 +76,12 @@ const validateEntityDirective = def =>
76
76
  def.directives.find(directive => directive.name.value === 'entity')
77
77
  ? List()
78
78
  : immutable.fromJS([
79
- {
80
- loc: def.loc,
81
- entity: def.name.value,
82
- message: `Defined without @entity directive`,
83
- },
84
- ])
79
+ {
80
+ loc: def.loc,
81
+ entity: def.name.value,
82
+ message: `Defined without @entity directive`,
83
+ },
84
+ ])
85
85
 
86
86
  const validateEntityID = def => {
87
87
  let idField = def.fields.find(field => field.name.value === 'id')
@@ -99,7 +99,9 @@ const validateEntityID = def => {
99
99
  if (
100
100
  idField.type.kind === 'NonNullType' &&
101
101
  idField.type.type.kind === 'NamedType' &&
102
- idField.type.type.name.value === 'ID'
102
+ (idField.type.type.name.value === 'ID' ||
103
+ idField.type.type.name.value === 'Bytes' ||
104
+ idField.type.type.name.value === 'String')
103
105
  ) {
104
106
  return List()
105
107
  } else {
@@ -107,7 +109,7 @@ const validateEntityID = def => {
107
109
  {
108
110
  loc: idField.loc,
109
111
  entity: def.name.value,
110
- message: `Field 'id': Entity IDs must be of type ID!`,
112
+ message: `Field 'id': Entity ids must be of type Bytes! or String!`,
111
113
  },
112
114
  ])
113
115
  }
@@ -115,22 +117,22 @@ const validateEntityID = def => {
115
117
 
116
118
  const validateListFieldType = (def, field) =>
117
119
  field.type.kind === 'NonNullType' &&
118
- field.type.kind === 'ListType' &&
119
- field.type.type.kind !== 'NonNullType'
120
+ field.type.kind === 'ListType' &&
121
+ field.type.type.kind !== 'NonNullType'
120
122
  ? immutable.fromJS([
121
- {
122
- loc: field.loc,
123
- entity: def.name.value,
124
- message: `\
123
+ {
124
+ loc: field.loc,
125
+ entity: def.name.value,
126
+ message: `\
125
127
  Field '${field.name.value}':
126
128
  Field has type [${field.type.type.name.value}]! but
127
129
  must have type [${field.type.type.name.value}!]!
128
130
 
129
131
  Reason: Lists with null elements are not supported.`,
130
- },
131
- ])
132
+ },
133
+ ])
132
134
  : field.type.kind === 'ListType' && field.type.type.kind !== 'NonNullType'
133
- ? immutable.fromJS([
135
+ ? immutable.fromJS([
134
136
  {
135
137
  loc: field.loc,
136
138
  entity: def.name.value,
@@ -142,7 +144,7 @@ must have type [${field.type.type.name.value}!]
142
144
  Reason: Lists with null elements are not supported.`,
143
145
  },
144
146
  ])
145
- : List()
147
+ : List()
146
148
 
147
149
  const unwrapType = type => {
148
150
  let innerTypeFromList = listType =>
@@ -159,8 +161,8 @@ const unwrapType = type => {
159
161
  return type.kind === 'NonNullType'
160
162
  ? innerTypeFromNonNull(type)
161
163
  : type.kind === 'ListType'
162
- ? innerTypeFromList(type)
163
- : type
164
+ ? innerTypeFromList(type)
165
+ : type
164
166
  }
165
167
 
166
168
  const gatherLocalTypes = defs =>
@@ -206,8 +208,8 @@ const gatherImportedTypes = defs =>
206
208
  type.fields.find(
207
209
  field => field.name.value == 'as' && field.value.kind == 'StringValue',
208
210
  )
209
- ? type.fields.find(field => field.name.value == 'as').value.value
210
- : undefined,
211
+ ? type.fields.find(field => field.name.value == 'as').value.value
212
+ : undefined,
211
213
  ),
212
214
  ),
213
215
  )
@@ -256,16 +258,15 @@ const validateInnerFieldType = (defs, def, field) => {
256
258
  return availableTypes.includes(typeName)
257
259
  ? List()
258
260
  : immutable.fromJS([
259
- {
260
- loc: field.loc,
261
- entity: def.name.value,
262
- message: `\
261
+ {
262
+ loc: field.loc,
263
+ entity: def.name.value,
264
+ message: `\
263
265
  Field '${field.name.value}': \
264
- Unknown type '${typeName}'.${
265
- suggestion !== undefined ? ` Did you mean '${suggestion}'?` : ''
266
+ Unknown type '${typeName}'.${suggestion !== undefined ? ` Did you mean '${suggestion}'?` : ''
266
267
  }`,
267
- },
268
- ])
268
+ },
269
+ ])
269
270
  }
270
271
 
271
272
  const validateEntityFieldType = (defs, def, field) =>
@@ -277,14 +278,14 @@ const validateEntityFieldType = (defs, def, field) =>
277
278
  const validateEntityFieldArguments = (defs, def, field) =>
278
279
  field.arguments.length > 0
279
280
  ? immutable.fromJS([
280
- {
281
- loc: field.loc,
282
- entity: def.name.value,
283
- message: `\
281
+ {
282
+ loc: field.loc,
283
+ entity: def.name.value,
284
+ message: `\
284
285
  Field '${field.name.value}': \
285
286
  Field arguments are not supported.`,
286
- },
287
- ])
287
+ },
288
+ ])
288
289
  : List()
289
290
 
290
291
  const entityFieldExists = (entityDef, name) =>
@@ -390,23 +391,23 @@ const validateEntityFields = (defs, def) =>
390
391
  const validateNoImportDirective = def =>
391
392
  def.directives.find(directive => directive.name.value == 'import')
392
393
  ? List([
393
- immutable.fromJS({
394
- loc: def.name.loc,
395
- entity: def.name.value,
396
- message: `@import directive only allowed on '${RESERVED_TYPE}' type`,
397
- }),
398
- ])
394
+ immutable.fromJS({
395
+ loc: def.name.loc,
396
+ entity: def.name.value,
397
+ message: `@import directive only allowed on '${RESERVED_TYPE}' type`,
398
+ }),
399
+ ])
399
400
  : List()
400
401
 
401
402
  const validateNoFulltext = def =>
402
403
  def.directives.find(directive => directive.name.value == 'fulltext')
403
404
  ? List([
404
- immutable.fromJS({
405
- loc: def.name.loc,
406
- entity: def.name.value,
407
- message: `@fulltext directive only allowed on '${RESERVED_TYPE}' type`,
408
- }),
409
- ])
405
+ immutable.fromJS({
406
+ loc: def.name.loc,
407
+ entity: def.name.value,
408
+ message: `@fulltext directive only allowed on '${RESERVED_TYPE}' type`,
409
+ }),
410
+ ])
410
411
  : List()
411
412
 
412
413
  const validateFulltextFields = (def, directive) => {
@@ -415,13 +416,13 @@ const validateFulltextFields = (def, directive) => {
415
416
  ['name', 'language', 'algorithm', 'include'].includes(argument.name.value)
416
417
  ? List([])
417
418
  : List([
418
- immutable.fromJS({
419
- loc: directive.name.loc,
420
- entity: def.name.value,
421
- directive: fulltextDirectiveName(directive),
422
- message: `found invalid argument: '${argument.name.value}', @fulltext directives only allow 'name', 'language', 'algorithm', and 'includes' arguments`,
423
- }),
424
- ]),
419
+ immutable.fromJS({
420
+ loc: directive.name.loc,
421
+ entity: def.name.value,
422
+ directive: fulltextDirectiveName(directive),
423
+ message: `found invalid argument: '${argument.name.value}', @fulltext directives only allow 'name', 'language', 'algorithm', and 'includes' arguments`,
424
+ }),
425
+ ]),
425
426
  )
426
427
  }, List([]))
427
428
  }
@@ -431,25 +432,25 @@ const validateFulltextName = (def, directive) => {
431
432
  return name
432
433
  ? validateFulltextArgumentName(def, directive, name)
433
434
  : List([
434
- immutable.fromJS({
435
- loc: directive.name.loc,
436
- entity: def.name.value,
437
- directive: fulltextDirectiveName(directive),
438
- message: `@fulltext argument 'name' must be specified`,
439
- }),
440
- ])
435
+ immutable.fromJS({
436
+ loc: directive.name.loc,
437
+ entity: def.name.value,
438
+ directive: fulltextDirectiveName(directive),
439
+ message: `@fulltext argument 'name' must be specified`,
440
+ }),
441
+ ])
441
442
  }
442
443
 
443
444
  const validateFulltextArgumentName = (def, directive, argument) => {
444
445
  return argument.value.kind != 'StringValue'
445
446
  ? List([
446
- immutable.fromJS({
447
- loc: directive.name.loc,
448
- entity: def.name.value,
449
- directive: fulltextDirectiveName(directive),
450
- message: `@fulltext argument 'name' must be a string`,
451
- }),
452
- ])
447
+ immutable.fromJS({
448
+ loc: directive.name.loc,
449
+ entity: def.name.value,
450
+ directive: fulltextDirectiveName(directive),
451
+ message: `@fulltext argument 'name' must be a string`,
452
+ }),
453
+ ])
453
454
  : List([])
454
455
  }
455
456
 
@@ -463,13 +464,13 @@ const validateFulltextLanguage = (def, directive) => {
463
464
  return language
464
465
  ? validateFulltextArgumentLanguage(def, directive, language)
465
466
  : List([
466
- immutable.fromJS({
467
- loc: directive.name.loc,
468
- entity: def.name.value,
469
- directive: fulltextDirectiveName(directive),
470
- message: `@fulltext argument 'language' must be specified`,
471
- }),
472
- ])
467
+ immutable.fromJS({
468
+ loc: directive.name.loc,
469
+ entity: def.name.value,
470
+ directive: fulltextDirectiveName(directive),
471
+ message: `@fulltext argument 'language' must be specified`,
472
+ }),
473
+ ])
473
474
  }
474
475
 
475
476
  const validateFulltextArgumentLanguage = (def, directive, argument) => {
@@ -521,13 +522,13 @@ const validateFulltextAlgorithm = (def, directive) => {
521
522
  return algorithm
522
523
  ? validateFulltextArgumentAlgorithm(def, directive, algorithm)
523
524
  : List([
524
- immutable.fromJS({
525
- loc: directive.name.loc,
526
- entity: def.name.value,
527
- directive: fulltextDirectiveName(directive),
528
- message: `@fulltext argument 'algorithm' must be specified`,
529
- }),
530
- ])
525
+ immutable.fromJS({
526
+ loc: directive.name.loc,
527
+ entity: def.name.value,
528
+ directive: fulltextDirectiveName(directive),
529
+ message: `@fulltext argument 'algorithm' must be specified`,
530
+ }),
531
+ ])
531
532
  }
532
533
 
533
534
  const validateFulltextArgumentAlgorithm = (def, directive, argument) => {
@@ -740,12 +741,12 @@ const validateImportDirectiveType = (def, directive, type) => {
740
741
  return importDirectiveTypeValidators[type.kind]
741
742
  ? importDirectiveTypeValidators[type.kind](def, directive, type)
742
743
  : List([
743
- immutable.fromJS({
744
- loc: directive.name.loc,
745
- entity: def.name.value,
746
- message: `Import must be one of "Name" or { name: "Name", as: "Alias" }`,
747
- }),
748
- ])
744
+ immutable.fromJS({
745
+ loc: directive.name.loc,
746
+ entity: def.name.value,
747
+ message: `Import must be one of "Name" or { name: "Name", as: "Alias" }`,
748
+ }),
749
+ ])
749
750
  }
750
751
 
751
752
  const validateImportDirectiveArgumentTypes = (def, directive, argument) => {
@@ -815,12 +816,12 @@ const validateImportDirectiveFields = (def, directive) => {
815
816
  ['types', 'from'].includes(argument.name.value)
816
817
  ? List([])
817
818
  : List([
818
- immutable.fromJS({
819
- loc: directive.name.loc,
820
- entity: def.name.value,
821
- message: `found invalid argument: '${argument.name.value}', @import directives only allow 'types' and 'from' arguments`,
822
- }),
823
- ]),
819
+ immutable.fromJS({
820
+ loc: directive.name.loc,
821
+ entity: def.name.value,
822
+ message: `found invalid argument: '${argument.name.value}', @import directives only allow 'types' and 'from' arguments`,
823
+ }),
824
+ ]),
824
825
  )
825
826
  }, List([]))
826
827
  }
@@ -830,12 +831,12 @@ const validateImportDirectiveTypes = (def, directive) => {
830
831
  return types
831
832
  ? validateImportDirectiveArgumentTypes(def, directive, types)
832
833
  : List([
833
- immutable.fromJS({
834
- loc: directive.name.loc,
835
- entity: def.name.value,
836
- message: `@import argument 'types' must be specified`,
837
- }),
838
- ])
834
+ immutable.fromJS({
835
+ loc: directive.name.loc,
836
+ entity: def.name.value,
837
+ message: `@import argument 'types' must be specified`,
838
+ }),
839
+ ])
839
840
  }
840
841
 
841
842
  const validateImportDirectiveFrom = (def, directive) => {
@@ -843,12 +844,12 @@ const validateImportDirectiveFrom = (def, directive) => {
843
844
  return from
844
845
  ? validateImportDirectiveArgumentFrom(def, directive, from)
845
846
  : List([
846
- immutable.fromJS({
847
- loc: directive.name.loc,
848
- entity: def.name.value,
849
- message: `@import argument 'from' must be specified`,
850
- }),
851
- ])
847
+ immutable.fromJS({
848
+ loc: directive.name.loc,
849
+ entity: def.name.value,
850
+ message: `@import argument 'from' must be specified`,
851
+ }),
852
+ ])
852
853
  }
853
854
 
854
855
  const validateImportDirective = (def, directive) =>
@@ -892,12 +893,12 @@ const validateSubgraphSchemaDirectives = def =>
892
893
  const validateTypeHasNoFields = def =>
893
894
  def.fields.length
894
895
  ? List([
895
- immutable.fromJS({
896
- loc: def.name.loc,
897
- entity: def.name.value,
898
- message: `${def.name.value} type is not allowed any fields by convention`,
899
- }),
900
- ])
896
+ immutable.fromJS({
897
+ loc: def.name.loc,
898
+ entity: def.name.value,
899
+ message: `${def.name.value} type is not allowed any fields by convention`,
900
+ }),
901
+ ])
901
902
  : List()
902
903
 
903
904
  const validateAtLeastOneExtensionField = def => List()
@@ -907,12 +908,12 @@ const typeDefinitionValidators = {
907
908
  def.name && def.name.value == RESERVED_TYPE
908
909
  ? List.of(...validateSubgraphSchemaDirectives(def), ...validateTypeHasNoFields(def))
909
910
  : List.of(
910
- ...validateEntityDirective(def),
911
- ...validateEntityID(def),
912
- ...validateEntityFields(defs, def),
913
- ...validateNoImportDirective(def),
914
- ...validateNoFulltext(def),
915
- ),
911
+ ...validateEntityDirective(def),
912
+ ...validateEntityID(def),
913
+ ...validateEntityFields(defs, def),
914
+ ...validateNoImportDirective(def),
915
+ ...validateNoFulltext(def),
916
+ ),
916
917
  ObjectTypeExtension: (_defs, def) => validateAtLeastOneExtensionField(def),
917
918
  }
918
919
 
@@ -1,10 +1,10 @@
1
1
  - Load subgraph from subgraph.yaml
2
2
  ⚠ Warnings while loading subgraph from subgraph.yaml: Warnings in subgraph.yaml:
3
-
3
+
4
4
  Path: repository
5
5
  The repository is still set to https://github.com/graphprotocol/example-subgraph.
6
6
  Please replace it with a link to your subgraph source code.
7
-
7
+
8
8
  Path: description
9
9
  The description is still the one from the example subgraph.
10
10
  Please update it to tell users more about your subgraph.
@@ -1,7 +1,8 @@
1
1
  schema:
2
2
  file: ./non-existent.grapqhl
3
3
  dataSources:
4
- - name: 5
4
+ - kind: ethereum/contract
5
+ name: 5
5
6
  abis:
6
7
  name: Foo
7
8
  mapping:
@@ -0,0 +1,12 @@
1
+ schema:
2
+ file: ./non-existent.grapqhl
3
+ dataSources:
4
+ - name: 5
5
+ abis:
6
+ name: Foo
7
+ mapping:
8
+ - 12
9
+ - 13
10
+ - 14
11
+ templates:
12
+ field: foo
@@ -0,0 +1,5 @@
1
+ - Load subgraph from subgraph.yaml
2
+ ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml:
3
+
4
+ Path: /
5
+ Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph.
@@ -7,9 +7,6 @@
7
7
  Path: schema > file
8
8
  File does not exist: non-existent.grapqhl
9
9
 
10
- Path: dataSources > 0 > kind
11
- No value provided
12
-
13
10
  Path: dataSources > 0 > name
14
11
  Expected string, found number:
15
12
  5
@@ -9,6 +9,14 @@ describe('Validation', () => {
9
9
  exitCode: 1,
10
10
  },
11
11
  )
12
+ cliTest(
13
+ 'Invalid subgraph manifest (cannot infer protocol)',
14
+ ['codegen', '--skip-migrations'],
15
+ 'validation/invalid-manifest-cannot-infer-protocol',
16
+ {
17
+ exitCode: 1,
18
+ },
19
+ )
12
20
  cliTest(
13
21
  'ABI not found in data source',
14
22
  ['codegen', '--skip-migrations'],
@@ -1,122 +0,0 @@
1
- scalar String
2
- scalar File
3
- scalar BigInt
4
-
5
- type Schema {
6
- file: File!
7
- }
8
-
9
- union DataSource =
10
- EthereumContractDataSource |
11
- NearContractDataSource
12
-
13
- union DataSourceTemplate = EthereumContractDataSourceTemplate
14
-
15
- type EthereumContractDataSource {
16
- kind: String!
17
- name: String!
18
- network: String
19
- source: EthereumContractSource!
20
- mapping: EthereumContractMapping!
21
- }
22
-
23
- type NearContractDataSource {
24
- kind: String!
25
- name: String!
26
- network: String
27
- source: NearContractSource!
28
- mapping: NearContractMapping!
29
- }
30
-
31
- type EthereumContractSource {
32
- address: String
33
- abi: String!
34
- startBlock: BigInt
35
- }
36
-
37
- type NearContractSource {
38
- account: String
39
- startBlock: BigInt
40
- }
41
-
42
- type EthereumContractMapping {
43
- kind: String
44
- apiVersion: String!
45
- language: String!
46
- file: File!
47
- entities: [String!]!
48
- abis: [EthereumContractAbi!]!
49
- blockHandlers: [EthereumBlockHandler!]
50
- callHandlers: [EthereumCallHandler!]
51
- eventHandlers: [EthereumContractEventHandler!]
52
- }
53
-
54
- type NearContractMapping {
55
- apiVersion: String!
56
- language: String!
57
- file: File!
58
- entities: [String!]!
59
- blockHandlers: [NearBlockHandler!]
60
- receiptHandlers: [NearReceiptHandler!]
61
- }
62
-
63
- type EthereumContractAbi {
64
- name: String!
65
- file: File!
66
- }
67
-
68
- type EthereumBlockHandler {
69
- handler: String!
70
- filter: EthereumBlockFilter
71
- }
72
-
73
- type EthereumBlockFilter {
74
- kind: String!
75
- }
76
-
77
- type NearBlockHandler {
78
- handler: String!
79
- }
80
-
81
- type EthereumCallHandler {
82
- function: String!
83
- handler: String!
84
- }
85
-
86
- type NearReceiptHandler {
87
- handler: String!
88
- }
89
-
90
- type EthereumContractEventHandler {
91
- event: String!
92
- topic0: String
93
- handler: String!
94
- }
95
-
96
- type Graft {
97
- base: String!
98
- block: BigInt!
99
- }
100
-
101
- type SubgraphManifest {
102
- specVersion: String!
103
- features: [String!]
104
- schema: Schema!
105
- description: String
106
- repository: String
107
- graft: Graft
108
- dataSources: [DataSource!]!
109
- templates: [DataSourceTemplate!]
110
- }
111
-
112
- type EthereumContractDataSourceTemplate {
113
- kind: String!
114
- name: String!
115
- network: String
116
- source: EthereumContractSourceTemplate!
117
- mapping: EthereumContractMapping!
118
- }
119
-
120
- type EthereumContractSourceTemplate {
121
- abi: String!
122
- }