v0.23.x release notes #911
doug-martin
started this conversation in
Releases
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Offset Paging Strategy [BREAKING CHANGE]
In previous versions of
nestjs-querytheOFFSETpaging strategy returned an array of nodes, this proved to not beextensible, especially when wanting to expose other attributes such as
totalCount, or paging meta such hashasNextPageorhasPreviousPage.In
v0.23.0the graphql response now returns anOffsetConnectionthat looks like the followingTotal Count with OFFSET Strategy
In previous versions of the nestjs-query the
enableTotalCountoption only worked with theCURSORpaging strategy.In
v0.23.0theenableTotalCountoption now also works with theOFFSETpaging strategy.When
enableTotalCountis set to true the following graphql schema will be generatedRelation Decorator Changes [BREAKING CHANGE]
In previous versions of
nestjs-querythere were four relation decorators@Relation,@FilterableRelation,@Connection, and@FilterableConnectionall four of the decorators have been changed to be more explicit in namingto be clear in what they are doing.
In
v0.23.0the decorators have been renamed to be more explicit.@Relation- A relation that is a single value (one-to-one, many-to-one)@FilterableRelation- A@Relationthat enables filtering the parent by fields of the relationDTO.@UnPagedRelation- An array of relations (e.g, many-to-many, one-to-many) that returns all the related records.@FilterableUnPagedRelation- An@UnPagedRelationthat enables filtering the parent by fields of the relationDTO.@OffsetConnection- A connection that represents a collection (e.g, many-to-many, one-to-many) that usesoffsetbased pagination.
@FilterableOffsetConnection- An@OffsetConnectionthat enables filtering the parent by fields of the connectionDTO.@CursorConnection- A connection that represents a collection (e.g, many-to-many, one-to-many) that usescursorbased pagination.
@FilterableCursorConnection- A@CursorConnectionthat enables filtering the parent by fields of theconnection
DTO.Below is a mapping of the old definition to the new one
WARNING In previous versions the
OFFSETpaging strategy returned an array of relations, the new version returns anOffsetConnectionAuthorizers
In previous versions of
nestjs-querythe resolvers relied on an AuthorizerService to be injected and the filterswere created manually within the resolver.
In the latest version, we have transitioned to a interceptor/param decorator pattern. This provides:
without having to worry about internal implementation details.
CRUDResolverby not having to worry about injecting the authorizerService, it willautomatically add the interceptor and param decorators to auto generated methods, you just need to decorate your DTO.
Old way
New
Hook Updates
In previous versions of nestjs-query hooks were not very flexible, and could not be used by custom resolver endpoints.
In the latest version the hooks pipeline has been re-worked to enable the following:
As a demonstration of the flexibility of the new hooks implementation, lets use a hook in a custom endpoint (this
would not have been possible previously)
The two important things are:
HookInterceptorin this example we reuse theBEFORE_UPDATE_MANYhook on theTodoItemDTO, the interceptoradds a DI hook instance to the context that can be used downstream by any guards or param decorators.
@MutationHookArgswill apply the correct hook to the args and provide it to the resolver endpoint.In this next example we can demonstrate the DI capability, we'll keep the example simple, but with
nestjs's DIfunctionality you can inject other services to look up information and transform the incoming request as much as you
need.
In this example we create a simple hook that will work for both
createOneandcreateManyendpoints to set thecreatedByattribute. In this example we look up the userEmail from theuserServiceand setcreatedByattributeon the input.
Now we can use this generic hook on any DTO that has a
createdByfieldRegistering DTOs When Using Custom Resolvers
In previous versions of
nestjs-queryyou could extendCRUDResolverbut there was not a way to set up theappropriate providers for many of the newer features (hooks, authorizers etc.).
In the latest version you now have the option to register your DTOs with
@nestjs-query/query-graphqlwithout itgenerating a resolver automatically.
In this example we create a custom resolver that extends
CRUDResolver.Because the
TodoItemResolverextendsCRUDResolverthere is no need to havenestjs-queryalso create a resolver,instead you can specify the
dtosoption which just takes inDTOClass,CreateDTOClass, andUpdateDTOClasstoset up all of additional providers to hooks, authorizers and other features.
Beta Was this translation helpful? Give feedback.
All reactions