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
-
Offset Paging Strategy [BREAKING CHANGE]
In previous versions of
nestjs-query
theOFFSET
paging 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 hashasNextPage
orhasPreviousPage
.In
v0.23.0
the graphql response now returns anOffsetConnection
that looks like the followingTotal Count with OFFSET Strategy
In previous versions of the nestjs-query the
enableTotalCount
option only worked with theCURSOR
paging strategy.In
v0.23.0
theenableTotalCount
option now also works with theOFFSET
paging strategy.When
enableTotalCount
is set to true the following graphql schema will be generatedRelation Decorator Changes [BREAKING CHANGE]
In previous versions of
nestjs-query
there were four relation decorators@Relation
,@FilterableRelation
,@Connection
, and@FilterableConnection
all four of the decorators have been changed to be more explicit in namingto be clear in what they are doing.
In
v0.23.0
the decorators have been renamed to be more explicit.@Relation
- A relation that is a single value (one-to-one, many-to-one)@FilterableRelation
- A@Relation
that 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@UnPagedRelation
that 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 usesoffset
based pagination.
@FilterableOffsetConnection
- An@OffsetConnection
that 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 usescursor
based pagination.
@FilterableCursorConnection
- A@CursorConnection
that 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
OFFSET
paging strategy returned an array of relations, the new version returns anOffsetConnection
Authorizers
In previous versions of
nestjs-query
the 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.
CRUDResolver
by 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:
HookInterceptor
in this example we reuse theBEFORE_UPDATE_MANY
hook on theTodoItemDTO
, the interceptoradds a DI hook instance to the context that can be used downstream by any guards or param decorators.
@MutationHookArgs
will 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
createOne
andcreateMany
endpoints to set thecreatedBy
attribute. In this example we look up the userEmail from theuserService
and setcreatedBy
attributeon the input.
Now we can use this generic hook on any DTO that has a
createdBy
fieldRegistering DTOs When Using Custom Resolvers
In previous versions of
nestjs-query
you could extendCRUDResolver
but 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-graphql
without itgenerating a resolver automatically.
In this example we create a custom resolver that extends
CRUDResolver
.Because the
TodoItemResolver
extendsCRUDResolver
there is no need to havenestjs-query
also create a resolver,instead you can specify the
dtos
option which just takes inDTOClass
,CreateDTOClass
, andUpdateDTOClass
toset up all of additional providers to hooks, authorizers and other features.
Beta Was this translation helpful? Give feedback.
All reactions