@graphprotocol/graph-cli 0.88.0-alpha-20241105081141-b7a8358 → 0.88.0-alpha-20241105083740-b45cf73

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,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.88.0-alpha-20241105081141-b7a8358
3
+ ## 0.88.0-alpha-20241105083740-b45cf73
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -20,12 +20,12 @@ export default class SchemaCodeGenerator {
20
20
  private schema;
21
21
  constructor(schema: Schema);
22
22
  generateModuleImports(): tsCodegen.ModuleImports[];
23
- generateTypes(): Array<tsCodegen.Class>;
23
+ generateTypes(generateStoreMethods?: boolean): Array<tsCodegen.Class>;
24
24
  generateDerivedLoaders(): any[];
25
25
  _isEntityTypeDefinition(def: DefinitionNode): def is ObjectTypeDefinitionNode;
26
26
  _isDerivedField(field: FieldDefinitionNode | undefined): boolean;
27
27
  _isInterfaceDefinition(def: DefinitionNode): def is InterfaceTypeDefinitionNode;
28
- _generateEntityType(def: ObjectTypeDefinitionNode): tsCodegen.Class;
28
+ _generateEntityType(def: ObjectTypeDefinitionNode, generateStoreMethods?: boolean): tsCodegen.Class;
29
29
  _generateDerivedLoader(typeName: string): any;
30
30
  _getTypeNameForField(gqlType: TypeNode): string;
31
31
  _generateConstructor(_entityName: string, fields: readonly FieldDefinitionNode[] | undefined): tsCodegen.Method;
@@ -94,12 +94,12 @@ class SchemaCodeGenerator {
94
94
  ], '@graphprotocol/graph-ts'),
95
95
  ];
96
96
  }
97
- generateTypes() {
97
+ generateTypes(generateStoreMethods = true) {
98
98
  return this.schema.ast.definitions
99
99
  .map(def => {
100
100
  if (this._isEntityTypeDefinition(def)) {
101
101
  schemaCodeGeneratorDebug.extend('generateTypes')(`Generating entity type for ${def.name.value}`);
102
- return this._generateEntityType(def);
102
+ return this._generateEntityType(def, generateStoreMethods);
103
103
  }
104
104
  })
105
105
  .filter(Boolean);
@@ -132,15 +132,17 @@ class SchemaCodeGenerator {
132
132
  _isInterfaceDefinition(def) {
133
133
  return def.kind === 'InterfaceTypeDefinition';
134
134
  }
135
- _generateEntityType(def) {
135
+ _generateEntityType(def, generateStoreMethods = true) {
136
136
  const name = def.name.value;
137
137
  const klass = tsCodegen.klass(name, { export: true, extends: 'Entity' });
138
138
  const fields = def.fields;
139
139
  const idField = IdField.fromFields(fields);
140
140
  // Generate and add a constructor
141
141
  klass.addMethod(this._generateConstructor(name, fields));
142
- // Generate and add save() and getById() methods
143
- this._generateStoreMethods(name, idField).forEach(method => klass.addMethod(method));
142
+ if (generateStoreMethods) {
143
+ // Generate and add save() and getById() methods
144
+ this._generateStoreMethods(name, idField).forEach(method => klass.addMethod(method));
145
+ }
144
146
  // Generate and add entity field getters and setters
145
147
  def.fields
146
148
  ?.reduce((methods, field) => methods.concat(this._generateEntityFieldMethods(def, field)), [])
@@ -25,8 +25,14 @@ export default class TypeGenerator {
25
25
  quiet: boolean;
26
26
  }): Promise<any>;
27
27
  loadSchema(subgraph: immutable.Map<any, any>): Promise<any>;
28
- generateTypesForSchema(schema: any, fileName?: string, // Default file name
29
- outputDir?: string): Promise<any>;
28
+ generateTypesForSchema({ schema, fileName, // Default file name
29
+ outputDir, // Default output directory
30
+ generateStoreMethods, }: {
31
+ schema: any;
32
+ fileName?: string;
33
+ outputDir?: string;
34
+ generateStoreMethods?: boolean;
35
+ }): Promise<any>;
30
36
  generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>): Promise<any>;
31
37
  getFilesToWatch(): Promise<string[]>;
32
38
  watchAndGenerateTypes(): Promise<void>;
@@ -97,7 +97,7 @@ class TypeGenerator {
97
97
  }
98
98
  const schema = await this.loadSchema(subgraph);
99
99
  typeGenDebug.extend('generateTypes')('Generating types for schema');
100
- await this.generateTypesForSchema(schema);
100
+ await this.generateTypesForSchema({ schema });
101
101
  if (this.options.subgraphSources.length > 0) {
102
102
  const ipfsClient = (0, ipfs_http_client_1.create)({
103
103
  url: (0, compiler_1.appendApiVersionForGraph)(this.options.ipfsUrl.toString()),
@@ -109,7 +109,11 @@ class TypeGenerator {
109
109
  const subgraphSchemaFile = await this.loadSubgraphSchemaFromIPFS(ipfsClient, manifest);
110
110
  const subgraphSchema = await schema_1.default.loadFromString(`js${manifest}.graphql`, subgraphSchemaFile);
111
111
  typeGenDebug.extend('generateTypes')(`Generating types for subgraph datasource ${manifest}`);
112
- await this.generateTypesForSchema(subgraphSchema, `subgraph-${manifest}.ts`);
112
+ await this.generateTypesForSchema({
113
+ schema: subgraphSchema,
114
+ fileName: `subgraph-${manifest}.ts`,
115
+ generateStoreMethods: false,
116
+ });
113
117
  }));
114
118
  }
115
119
  toolbox.print.success('\nTypes generated successfully\n');
@@ -180,15 +184,16 @@ class TypeGenerator {
180
184
  return schema_1.default.load(absolutePath);
181
185
  });
182
186
  }
183
- async generateTypesForSchema(schema, fileName = 'schema.ts', // Default file name
184
- outputDir = this.options.outputDir) {
187
+ async generateTypesForSchema({ schema, fileName = 'schema.ts', // Default file name
188
+ outputDir = this.options.outputDir, // Default output directory
189
+ generateStoreMethods = true, }) {
185
190
  return await (0, spinner_1.withSpinner)(`Generate types for GraphQL schema`, `Failed to generate types for GraphQL schema`, `Warnings while generating types for GraphQL schema`, async (spinner) => {
186
191
  // Generate TypeScript module from schema
187
192
  const codeGenerator = schema.codeGenerator();
188
193
  const code = await prettier_1.default.format([
189
194
  typescript_1.GENERATED_FILE_NOTE,
190
195
  ...codeGenerator.generateModuleImports(),
191
- ...codeGenerator.generateTypes(),
196
+ ...codeGenerator.generateTypes(generateStoreMethods),
192
197
  ...codeGenerator.generateDerivedLoaders(),
193
198
  ].join('\n'), {
194
199
  parser: 'typescript',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.88.0-alpha-20241105081141-b7a8358",
2
+ "version": "0.88.0-alpha-20241105083740-b45cf73",
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.88.0-alpha-20241105081141-b7a8358",
3
+ "version": "0.88.0-alpha-20241105083740-b45cf73",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {