Skip to content

Commit

Permalink
Merge pull request #15 from RoboVault/fix/schema-composer
Browse files Browse the repository at this point in the history
fixing schema composer
  • Loading branch information
hazelnutcloud authored Jul 11, 2023
2 parents 97a6d98 + 68ae93c commit 5341866
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './cli/mod.ts'
import 'https://deno.land/[email protected]/dotenv/load.ts'

export const version = 'v0.4.16'
export const version = 'v0.4.17'

const command = new Command()
.name('arkiver')
Expand Down
5 changes: 4 additions & 1 deletion src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/log/mod.ts'
export * as colors from 'https://deno.land/[email protected]/fmt/colors.ts'
Expand Down
20 changes: 15 additions & 5 deletions src/graphql/builder.ts
Original file line number Diff line number Diff line change
@@ -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<any>; list: boolean }[],
) => {
for (const { model, list } of entities) {
const getTC = (schemaComposer: any, model: any) => {
const getTC = (
schemaComposer: SchemaComposer,
model: mongoose.Model<any>,
) => {
try {
return schemaComposer.getAnyTC(model.modelName)
return schemaComposer.getOTC(
model.modelName,
) as ObjectTypeComposerWithMongooseResolvers<any>
} catch (_e) {
return composeMongoose<any>(model)
return composeMongoose<any>(model, { schemaComposer })
}
}

Expand All @@ -28,7 +38,7 @@ export const buildSchemaFromEntities = (
[_id]: (source: any) => source[path],
},
projection: { [path]: 1 },
})
} as any)
}
}

Expand Down

0 comments on commit 5341866

Please sign in to comment.