Releases: Adrinalin4ik/Nestjs-Graphql-Tools
Version 0.10.1
- Fix queries without filters
- Vulnerability fixes
Version 0.10.0
- Added support of nested filters (proposal: #42)
- Dependencies upgrade
Now is allowed to use nested filters like this
{
users(where: {
and: {
id: {eq: 1}
or: {
and: {
id: {eq: 2}
email: {like: "123"}
}
is_active: { eq: true }
id: { eq: 3 }
}
}
}) {
id
email
}
}
Version 0.9.1
- Updated dependencies
- Added feature presented in the issue #34
- Added raw filters and sorting
Raw filters
Raw filters allow to get access to the user provided raw value right from the code. This feature allows to build your own filters interpreters.
How to use raw filters:
- Add
@Filter({ raw: true })
parameter with type ofRawFilterArgs<T>
whereT
is your filter type @Filter()
will return raw filter data.
@Query(() => [UserObjectType])
async usersRaw(
@Filter(() => [UserObjectType, UserFilterInputType], {sqlAlias: 'u', raw: true}) filter: RawFilterArgs<UserObjectType & UserFilterInputType>,
@Paginator() paginator: PaginatorArgs
) {
// Your customer filter logic..
return [];
}
Raw sorting
Raw sorting allows to get access to the user provided raw value right from the code. This feature allows to build your own sorting interpreters.
How to use raw filters:
- Add
@Sorting({ raw: true })
parameter with type ofRawSortingArgs<T>
whereT
is your filter type @Sorting()
will return raw sorting data.
@Query(() => [UserObjectType])
async usersRaw(
@Sorting(() => [UserObjectType], { sqlAlias: 'u', raw: true}) sorting: RawSortingArgs<UserObjectType>,
@Paginator() paginator: PaginatorArgs
) {
// Your customer filter logic..
return [];
}
Version 0.9.0
- Fixed enums for custom filters
- Added simple automated tests
- Fixed errors related to sqlite3
Migration guide
- All custom filters should be decorated with
@InputType()
Version 0.8.3
- Fix vulnurabilities
Version 0.8.2
- Upgrade deps
- Vulns fixes
Version 0.8.1
Federation support
Basic support of federation already in place. Just add to your method with @ResolveReference()
one more decorator @GraphqlLoader()
Example
This examples is the reference to official example https://github.com/nestjs/nest/tree/master/sample/31-graphql-federation-code-first. Clone https://github.com/nestjs/nest/tree/master/sample/31-graphql-federation-code-first (download specific directory with https://download-directory.github.io/ or with chrome extention https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn)
- Annotate method resolveReference of
users-application/src/users/users.resolver.ts
// users-application/src/users/users.resolver.ts
@ResolveReference()
@GraphqlLoader()
async resolveReference(
@Loader() loader: LoaderData<User, number>,
) {
const ids = loader.ids;
const users = this.usersService.findByIds(ids);
return loader.helpers.mapManyToOneRelation(users, loader.ids, 'id')
}
- Add method findByIds to
users-application/src/users/users.service.ts
// users-application/src/users/users.service.ts
@Injectable()
export class UsersService {
private users: User[] = [
{ id: 1, name: 'John Doe' },
{ id: 2, name: 'Richard Roe' },
];
findByIds(idsList: number[]): User[] {
return this.users.filter((user) => idsList.some(id => Number(id) === user.id));
}
}
-
Install dependencies of 3 projects : npm ci in gateway, posts-application, users-application.
-
Run all projects in order :
cd users-application && npm run start
cd posts-application && npm run start
cd gateway && npm run start
-
Go to localhost:3001/graphql and send graphql request to gateway
{
posts {
id
title
authorId
user {
id
name
}
}
}
Version 0.8.0
- Updated deps
- @GraphqlFilter and @GraphqlSorting method decorators are no longer required and marked as deprecated. These decorators will be removed soon.
- @filter decorator now has it's own type FilterArgs. It should be used insted of Brackets in all the cases.
- Fixed problem related to global pipes like ValidationPipe. This problem happened because pipe created dummy model based on types provided for the @filter decorator (it was typeorm Brakets). Please use FilterArgs type insted of Brackets to avoid this bug.
Version 0.7.21
- Vulnurabilities fixes
- Upgraded all the dev deps to be the latest
- Npm replaced with yarn
Version 0.7.20
- Bump deps