Skip to content

Releases: Adrinalin4ik/Nestjs-Graphql-Tools

Version 0.7.8

14 Feb 02:47
Compare
Choose a tag to compare
  • Bump deps

Version 0.7.7

14 Feb 02:46
Compare
Choose a tag to compare

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

24 Jan 07:15
Compare
Choose a tag to compare
  • 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

16 Jan 06:29
Compare
Choose a tag to compare

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

09 Jan 18:45
Compare
Choose a tag to compare
  • 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

04 Jan 10:56
Compare
Choose a tag to compare
  • Fix "not in" operator type. Now it's an array as it should be.

Version 0.7.2

03 Jan 08:08
Compare
Choose a tag to compare
  • Upgrade packages, fix vulnurabilities

Version 0.7.1

01 Jan 09:58
Compare
Choose a tag to compare
  • Now like operator always casts value and field to string. Graphql definition is string as well.

Version 0.7.0

19 Dec 06:16
Compare
Choose a tag to compare
  • Changed type names generated by the library for filters and sorting
  • Added initial unit tests

Version 0.6.1

16 Dec 06:22
Compare
Choose a tag to compare
  • Updated types of pagination. Now, types page and per_page are Int
  • Clean up