mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-08 11:02:52 +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.
|
||||
registerHandlebarHelpers(config);
|
||||
|
||||
visitor.visitSubgraph(config.subgraphPath);
|
||||
visitor.visitSubgraph(config.subgraphPath, config.subgraphConfig);
|
||||
|
||||
outStream = outputDir
|
||||
? fs.createWriteStream(path.join(outputDir, 'src/schema.gql'))
|
||||
|
@ -5,8 +5,8 @@ import yaml from 'js-yaml';
|
||||
|
||||
import { loadFilesSync } from '@graphql-tools/load-files';
|
||||
|
||||
export function parseSubgraphSchema (subgraphPath: string): any {
|
||||
const subgraphSchemaPath = path.join(path.resolve(subgraphPath), '/schema.graphql');
|
||||
export function parseSubgraphSchema (subgraphPath: string, subgraphConfig: any): any {
|
||||
const subgraphSchemaPath = path.join(path.resolve(subgraphPath), subgraphConfig.schema?.file ?? './schema.graphql');
|
||||
|
||||
assert(fs.existsSync(subgraphSchemaPath), `Schema file not found at ${subgraphSchemaPath}`);
|
||||
const typesArray = loadFilesSync(subgraphSchemaPath);
|
||||
|
@ -180,13 +180,13 @@ export class Visitor {
|
||||
});
|
||||
}
|
||||
|
||||
visitSubgraph (subgraphPath?: string): void {
|
||||
if (!subgraphPath) {
|
||||
visitSubgraph (subgraphPath?: string, subgraphConfig?: any): void {
|
||||
if (!subgraphPath || !subgraphConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse subgraph schema to get subgraphSchemaDocument.
|
||||
const subgraphSchemaDocument = parseSubgraphSchema(subgraphPath);
|
||||
const subgraphSchemaDocument = parseSubgraphSchema(subgraphPath, subgraphConfig);
|
||||
|
||||
this._schema.addSubgraphSchema(subgraphSchemaDocument);
|
||||
this._types.addSubgraphTypes(subgraphSchemaDocument);
|
||||
|
Loading…
Reference in New Issue
Block a user