Releases: Adrinalin4ik/Nestjs-Graphql-Tools
Releases · Adrinalin4ik/Nestjs-Graphql-Tools
Version 0.7.8
- Bump deps
Version 0.7.7
Added exclusions
Sometimes you don't want to provide filters/sorting by all the fields in the dto. There's a couple decorators that can help with it @FilterField({exclude: true})
and @SortingField({exclude: true})
Example
@ObjectType()
export class User {
@Field(() => String)
fname: string;
@Field(() => String)
@FilterField({exclude: true})
@SortingField({exclude: true})
mname: string;
@Field(() => String)
lname: string;
}
export class UserResolver {
@Query(() => [UserObjectType])
@GraphqlFilter()
@GraphqlSorting()
users(
@Filter(() => [UserObjectType], {sqlAlias: 'u'}) filter: Brackets,
@Sorting(() => [UserObjectType], { sqlAlias: 'u' }) sorting: SortArgs<UserObjectType>
) {
const qb = this.userRepository.createQueryBuilder('u')
.where(filter);
if (sorting) {
qb.orderBy(sorting)
}
return qb.getMany()
}
}
Now, if you try to build a query with the sorting an filtering by mname you'll get an error, because there's not such field in the graphql schema definition for sorting and filtering.
Version 0.7.6
- Fixed nullable resolvers. Now they not thow an error in case of parent object includes null in the foreignKey.
- Updated errors wording
Version 0.7.5
Bug fix
- Clean up context after the loader executed the actual handler. This bug is only applicable to subscriptions, because they don't have context at all, and using synthetic context we should clean it up on every socket message.
Version 0.7.4
- Added ability to use custom accessors for the loaders
Now @GraphqlLoader can have foreignKey argument as a function. This function has 1 argument which is parent model.
@GraphqlLoader({
foreignKey: (parent: User) => parent.id
})
async tasks (
@Loader() loader: LoaderData<TaskObjectType, number>
) {
const tasks = await this.taskRepository.createQueryBuilder('t')
.where({
assignee_id: In(loader.ids)
}).getMany()
return loader.helpers.mapOneToManyRelation(tasks, loader.ids, 'assignee_id');
}
It also toches polymorphic relations. For the polymorphic relations, polymorphic option can be a function which is providing access to the parent object and allow to select id and descriminator from it.
@ResolveField(() => [DescriptionableUnion], { nullable: true })
@GraphqlLoader({
polymorphic: (parent: DescriptionObjectType) => ({
id: parent.description_id,
descriminator: parent.description_type
})
})
async descriptionable(
@Loader() loader: PolymorphicLoaderData<[DescriptionText | DescriptionChecklist], number, DescriptionType>,
@SelectedUnionTypes() types: SelectedUnionTypesResult
) {
const results = [];
for (const item of loader.polimorphicTypes) {
switch(item.descriminator) {
case DescriptionType.Text:
const textDescriptions = await this.descriptionTextRepository.createQueryBuilder()
.select(types.getFields(DescriptionTextObjectType))
.where({
id: In(item.ids)
})
.getRawMany();
results.push({ descriminator: DescriptionType.Text, entities: textDescriptions })
break;
case DescriptionType.Checklist:
const checklistDescriptions = await this.descriptionChecklistRepository.createQueryBuilder()
.select(types.getFields(DescriptionChecklistObjectType))
.where({
id: In(item.ids)
})
.getRawMany();
results.push({ descriminator: DescriptionType.Checklist, entities: checklistDescriptions })
break;
default: break;
}
}
return loader.helpers.mapOneToManyPolymorphicRelation(results, loader.ids);
}
All examples inside the code.
- Code clean up
Version 0.7.3
- Fix "not in" operator type. Now it's an array as it should be.
Version 0.7.2
- Upgrade packages, fix vulnurabilities
Version 0.7.1
- Now
like
operator always casts value and field to string. Graphql definition is string as well.
Version 0.7.0
- Changed type names generated by the library for filters and sorting
- Added initial unit tests
Version 0.6.1
- Updated types of pagination. Now, types page and per_page are Int
- Clean up