Skip to content

Commit

Permalink
Load schema file path from subgraph config (#458)
Browse files Browse the repository at this point in the history
* Get subgraph schema from config file

* Use default value if schema not given

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
  • Loading branch information
prathamesh0 and neerajvijay1997 authored Nov 9, 2023
1 parent 5aa9832 commit 483a73f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/codegen/src/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/src/utils/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/codegen/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 483a73f

Please sign in to comment.