Skip to content

Commit 33c04ca

Browse files
icebobclaude
andcommitted
Make makeExecutableSchema and generateGraphQLSchema methods async
- Made makeExecutableSchema method async in service.js - Made generateGraphQLSchema method async since it calls makeExecutableSchema - Added await to all calling places to maintain proper async flow - Updated TypeScript definitions to reflect Promise return types - Updated CHANGELOG.md to document the changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1686ab5 commit 33c04ca

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- **GitHub Actions**: Updated CI workflow to use latest GitHub Actions (v4) and test on Node.js 20.x, 22.x, 24.x
1515
- **Dependencies**: Updated all dependencies to latest compatible versions
1616
- **Configuration**: Replaced `.eslintrc.js` and `.prettierrc.js` with modern `eslint.config.js` and `prettier.config.js`
17+
- **Async Methods**: Made `makeExecutableSchema` and `generateGraphQLSchema` methods async for better async/await support
1718

1819
## Removed Features
1920
- Removed file upload examples and documentation

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ declare module "moleculer-apollo-server" {
108108
buildDataLoader(ctx: any, actionName: string, batchedParamKey: string, staticParams: object, args: object, options?: { hashCacheKey?: boolean }): any;
109109
buildLoaderOptionMap(services: ServiceSchema[]): void;
110110
createAsyncIteratorResolver(actionName: string, tags?: string[], filter?: string): { subscribe: Function; resolve: Function };
111-
generateGraphQLSchema(services: ServiceSchema[]): GraphQLSchema;
112-
makeExecutableSchema(schemaDef: IExecutableSchemaDefinition): GraphQLSchema;
111+
generateGraphQLSchema(services: ServiceSchema[]): Promise<GraphQLSchema>;
112+
makeExecutableSchema(schemaDef: IExecutableSchemaDefinition): Promise<GraphQLSchema>;
113113
createPubSub(): PubSub | Promise<PubSub>;
114114
prepareGraphQLSchema(): Promise<void>;
115115
createGraphqlContext(args: { req: any }): BaseContext;

src/service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ module.exports = function (mixinOptions) {
333333
* @param {Object[]} services
334334
* @returns {Object} Generated schema
335335
*/
336-
generateGraphQLSchema(services) {
336+
async generateGraphQLSchema(services) {
337337
let str;
338338
try {
339339
let typeDefs = [];
@@ -570,7 +570,7 @@ module.exports = function (mixinOptions) {
570570
typeDefs.push(str);
571571
}
572572

573-
return this.makeExecutableSchema({ typeDefs, resolvers });
573+
return await this.makeExecutableSchema({ typeDefs, resolvers });
574574
} catch (err) {
575575
throw new MoleculerServerError(
576576
"Unable to compile GraphQL schema",
@@ -587,7 +587,7 @@ module.exports = function (mixinOptions) {
587587
* just overwrite it in your service file.
588588
* @param {Object} schemaDef
589589
*/
590-
makeExecutableSchema(schemaDef) {
590+
async makeExecutableSchema(schemaDef) {
591591
return makeExecutableSchema(schemaDef);
592592
},
593593

@@ -626,7 +626,7 @@ module.exports = function (mixinOptions) {
626626
}
627627

628628
const services = this.broker.registry.getServiceList({ withActions: true });
629-
const schema = this.generateGraphQLSchema(services);
629+
const schema = await this.generateGraphQLSchema(services);
630630

631631
this.logger.debug(
632632
"Generated GraphQL schema:\n\n" + GraphQL.printSchema(schema)

0 commit comments

Comments
 (0)