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:
prathamesh0 2023-11-09 12:17:09 +05:30 committed by GitHub
parent 5aa98326cb
commit 483a73fc3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -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'))

View File

@ -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);

View File

@ -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);