From 68ae93c3eba99da9ad8bc5b77d21012cd1ca4dee Mon Sep 17 00:00:00 2001 From: hazelnutcloud Date: Tue, 11 Jul 2023 22:33:31 +0800 Subject: [PATCH] fixing schema composer --- CHANGELOG.md | 3 +++ cli.ts | 2 +- src/deps.ts | 5 ++++- src/graphql/builder.ts | 20 +++++++++++++++----- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2751b27..e70cd4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v0.4.17 +- fix: bug in schema composer where it was not properly handling entities + # v0.4.16 - feat: enhance `arkiver list` command, see `arkiver list --help` - feat: added 3 new commands to the CLI: diff --git a/cli.ts b/cli.ts index 085f605..c2da6fa 100644 --- a/cli.ts +++ b/cli.ts @@ -17,7 +17,7 @@ import { } from './cli/mod.ts' import 'https://deno.land/std@0.179.0/dotenv/load.ts' -export const version = 'v0.4.16' +export const version = 'v0.4.17' const command = new Command() .name('arkiver') diff --git a/src/deps.ts b/src/deps.ts index 32dcdd6..2e71984 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -24,7 +24,10 @@ export { } from 'npm:abitype' export { default as mongoose, Schema, Types } from 'npm:mongoose' export { SchemaComposer, schemaComposer } from 'npm:graphql-compose' -export { composeMongoose } from 'npm:graphql-compose-mongoose' +export { + composeMongoose, + type ObjectTypeComposerWithMongooseResolvers, +} from 'npm:graphql-compose-mongoose' export { LRUCache as Cache } from 'npm:lru-cache' export * as log from 'https://deno.land/std@0.181.0/log/mod.ts' export * as colors from 'https://deno.land/std@0.181.0/fmt/colors.ts' diff --git a/src/graphql/builder.ts b/src/graphql/builder.ts index 4d0998b..50e3d84 100644 --- a/src/graphql/builder.ts +++ b/src/graphql/builder.ts @@ -1,16 +1,26 @@ // deno-lint-ignore-file no-explicit-any -import { composeMongoose, mongoose, SchemaComposer } from '../deps.ts' +import { + composeMongoose, + mongoose, + ObjectTypeComposerWithMongooseResolvers, + SchemaComposer, +} from '../deps.ts' export const buildSchemaFromEntities = ( schemaComposer: SchemaComposer, entities: { model: mongoose.Model; list: boolean }[], ) => { for (const { model, list } of entities) { - const getTC = (schemaComposer: any, model: any) => { + const getTC = ( + schemaComposer: SchemaComposer, + model: mongoose.Model, + ) => { try { - return schemaComposer.getAnyTC(model.modelName) + return schemaComposer.getOTC( + model.modelName, + ) as ObjectTypeComposerWithMongooseResolvers } catch (_e) { - return composeMongoose(model) + return composeMongoose(model, { schemaComposer }) } } @@ -28,7 +38,7 @@ export const buildSchemaFromEntities = ( [_id]: (source: any) => source[path], }, projection: { [path]: 1 }, - }) + } as any) } }