Skip to content

Commit

Permalink
Merge pull request #133 from HPInc/chore/bump-mongoose-v5-to-v6
Browse files Browse the repository at this point in the history
feat: bump mongoose
  • Loading branch information
Adrià authored Oct 3, 2022
2 parents 82a78ba + f740846 commit f8a7adf
Show file tree
Hide file tree
Showing 30 changed files with 1,581 additions and 1,069 deletions.
558 changes: 392 additions & 166 deletions examples/graphql/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"debug": "^4.1.1",
"express": "4.16.4",
"lodash": "4.17.21",
"mongoose": "^5.13.14"
"mongoose": "^6.6.2"
},
"devDependencies": {
"@types/express": "4.16.1",
Expand Down
8 changes: 4 additions & 4 deletions examples/graphql/src/api/author/author.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export default class AuthorController {
@arg() where: AuthorFilter,
@arg() paginate: AuthorPagination,
@selectionSet() selection,
@context() context: any
@context() davinciContext: any
) {
const q = queryHelpers.toMongodbQuery(where);
const { $limit, $skip } = queryHelpers.toMongodbQuery(paginate || {});
const projection = queryHelpers.toMongdbProjection(selection || []);

return this.model
.find(q, projection, { context })
.find(q, projection, { davinciContext })
.limit($limit)
.skip($skip);
}
Expand All @@ -54,7 +54,7 @@ export default class AuthorController {
}

@fieldResolver(BookSchema, 'authors', [AuthorSchema])
getBookAuthors(@parent() book: BookSchema, @arg() query: AuthorFilter, @context() context: any) {
return this.findAuthors({ ...query, _id: { IN: book.authorIds } }, null, null, context);
getBookAuthors(@parent() book: BookSchema, @arg() query: AuthorFilter, @context() davinciContext: any) {
return this.findAuthors({ ...query, _id: { IN: book.authorIds } }, null, null, davinciContext);
}
}
12 changes: 6 additions & 6 deletions examples/graphql/src/api/author/author.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ const { generateSchema, beforeRead, beforeWrite, beforeDelete } = mgoose;

const schema = generateSchema(AuthorSchema);

beforeRead<Context>(schema, ({ query, context }) => {
if (context) {
beforeRead<Context>(schema, ({ query, davinciContext }) => {
if (davinciContext) {
const currentQuery = query.getQuery();
query.setQuery({ ...currentQuery, accountId: context.accountId });
query.setQuery({ ...currentQuery, accountId: davinciContext.accountId });
}
});

beforeWrite<Context, AuthorSchema>(schema, ({ doc, context }) => {
beforeWrite<Context, AuthorSchema>(schema, ({ doc, davinciContext }) => {
// inject accountId before persisting into DB
if (context) {
doc.accountId = context.accountId;
if (davinciContext) {
doc.accountId = davinciContext.accountId;
}
});

Expand Down
8 changes: 4 additions & 4 deletions examples/graphql/src/api/book/book.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default class BookController {
}

@query([BookSchema], 'books')
findBooks(@arg() query: BookFilter, @ctx() context: any, @info() gqlInfo, @selectionSet() gqlSelectionSet) {
findBooks(@arg() query: BookFilter, @ctx() davinciContext: any, @info() gqlInfo, @selectionSet() gqlSelectionSet) {
console.log(gqlInfo, gqlSelectionSet);
return this.model.find(query, {}, { context });
return this.model.find(query, {}, { davinciContext });
}

@mutation(BookSchema, 'createBook')
Expand All @@ -31,7 +31,7 @@ export default class BookController {
}

@fieldResolver<AuthorSchema>(AuthorSchema, 'books', [BookSchema])
getAuthorBooks(@parent() author: AuthorSchema, @arg() query: BookFilter, @ctx() context: any) {
return this.model.find({ ...query, authorIds: author.id }).setOptions({ context });
getAuthorBooks(@parent() author: AuthorSchema, @arg() query: BookFilter, @ctx() davinciContext: any) {
return this.model.find({ ...query, authorIds: author.id }).setOptions({ davinciContext });
}
}
12 changes: 6 additions & 6 deletions examples/graphql/src/api/book/book.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ const { generateSchema, beforeRead, beforeWrite, beforeDelete } = mgoose;

const schema = generateSchema(BookSchema);

beforeRead<Context>(schema, ({ query, context }) => {
if (context) {
beforeRead<Context>(schema, ({ query, davinciContext }) => {
if (davinciContext) {
const currentQuery = query.getQuery();
query.setQuery({ ...currentQuery, accountId: context.accountId });
query.setQuery({ ...currentQuery, accountId: davinciContext.accountId });
}
});

beforeWrite<Context, BookSchema>(schema, ({ doc, context }) => {
beforeWrite<Context, BookSchema>(schema, ({ doc, davinciContext }) => {
// inject accountId before persisting into DB
if (context) {
doc.accountId = context.accountId;
if (davinciContext) {
doc.accountId = davinciContext.accountId;
}
});

Expand Down
5 changes: 1 addition & 4 deletions examples/graphql/src/boot/dbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import mongoose from 'mongoose';

module.exports = async app => {
const mongodbUrl = process.env.MONGODB_URL || 'mongodb://localhost:27017/author-api';
await mongoose.connect(
mongodbUrl,
{ useNewUrlParser: true }
);
await mongoose.connect(mongodbUrl);

/*
ready states being:
Expand Down
Loading

0 comments on commit f8a7adf

Please sign in to comment.