mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-04-11 10:01:16 +00:00
Load schema file path from subgraph config (#458)
* Get subgraph schema from config file * Use default value if schema not given --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
5aa98326cb
commit
483a73fc3e
@ -212,7 +212,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any, overW
|
|||||||
// Register the handlebar helpers to be used in the templates.
|
// Register the handlebar helpers to be used in the templates.
|
||||||
registerHandlebarHelpers(config);
|
registerHandlebarHelpers(config);
|
||||||
|
|
||||||
visitor.visitSubgraph(config.subgraphPath);
|
visitor.visitSubgraph(config.subgraphPath, config.subgraphConfig);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/schema.gql'))
|
? fs.createWriteStream(path.join(outputDir, 'src/schema.gql'))
|
||||||
|
@ -5,8 +5,8 @@ import yaml from 'js-yaml';
|
|||||||
|
|
||||||
import { loadFilesSync } from '@graphql-tools/load-files';
|
import { loadFilesSync } from '@graphql-tools/load-files';
|
||||||
|
|
||||||
export function parseSubgraphSchema (subgraphPath: string): any {
|
export function parseSubgraphSchema (subgraphPath: string, subgraphConfig: any): any {
|
||||||
const subgraphSchemaPath = path.join(path.resolve(subgraphPath), '/schema.graphql');
|
const subgraphSchemaPath = path.join(path.resolve(subgraphPath), subgraphConfig.schema?.file ?? './schema.graphql');
|
||||||
|
|
||||||
assert(fs.existsSync(subgraphSchemaPath), `Schema file not found at ${subgraphSchemaPath}`);
|
assert(fs.existsSync(subgraphSchemaPath), `Schema file not found at ${subgraphSchemaPath}`);
|
||||||
const typesArray = loadFilesSync(subgraphSchemaPath);
|
const typesArray = loadFilesSync(subgraphSchemaPath);
|
||||||
|
@ -180,13 +180,13 @@ export class Visitor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
visitSubgraph (subgraphPath?: string): void {
|
visitSubgraph (subgraphPath?: string, subgraphConfig?: any): void {
|
||||||
if (!subgraphPath) {
|
if (!subgraphPath || !subgraphConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse subgraph schema to get subgraphSchemaDocument.
|
// Parse subgraph schema to get subgraphSchemaDocument.
|
||||||
const subgraphSchemaDocument = parseSubgraphSchema(subgraphPath);
|
const subgraphSchemaDocument = parseSubgraphSchema(subgraphPath, subgraphConfig);
|
||||||
|
|
||||||
this._schema.addSubgraphSchema(subgraphSchemaDocument);
|
this._schema.addSubgraphSchema(subgraphSchemaDocument);
|
||||||
this._types.addSubgraphTypes(subgraphSchemaDocument);
|
this._types.addSubgraphTypes(subgraphSchemaDocument);
|
||||||
|
Loading…
Reference in New Issue
Block a user