Higher Order Resolvers TypeGraphQL

preview_player
Показать описание
Learn how to create higher order resolvers in TypeGraphQL.

Links from video:

----

----

----

----
Follow Me Online Here:

#benawad

----
#benawad
Рекомендации по теме
Комментарии
Автор

Great series Ben! So using this base resolver, how would you extend it to handle extra logic such as needing to hash the input password first?

jamesduong
Автор

love your videos.
I have read somewhere that you can authorize specific fields in a query based on a user's role
does it mean the self documentation will change based on a role?
if no, is it possible to achieve such a thing ?
*cough* video idea *cough*

tabziz
Автор

Thanks for the video! I'm trying to setup CRUD controllers in NestJS like this, but what about when you have to chain multiple of those functions? I think it's not possible for typescript to maintain type info at the moment due to its lack of ability to handle types with generic type parameters.. do you know of any workarounds to this? Have a minimal repo ready for this issue if an example is needed.

patrickgeyer
Автор

Help I have an error adding the middleware is Auth.
(alias) const isAuth: MiddlewareFn<MyContext>
import isAuth
Argument of type 'MiddlewareFn<MyContext>' is not assignable to parameter of type 'Middleware<any>[]'.
Type 'MiddlewareFn<MyContext>' is missing the following properties from type 'Middleware<any>[]': pop, push, concat, join, and 27 more.

maxmeza
Автор

It looks like the following import in CreateUser.ts is no longer valid (Cannot find module...).

import { Middleware } from

I have created a temporary workaround, but all I did was essentially drudged up the old code (example to follow). Wondering if anyone has any better methods to achieve this?


*temp solution*
Add 2 files to the modules/middleware folder


*file - ResolverData.ts*
import { GraphQLResolveInfo } from "graphql";


export interface ArgsDictionary {
[argName: string]: any;
}


export interface ResolverData<ContextType = {}> {
root: any;
args: ArgsDictionary;
context: ContextType;
info: GraphQLResolveInfo;
}



*file Middleware.ts*
import { ResolverData } from "./ResolverData";


export type NextFn = () => Promise<any>;


export type MiddlewareFn<TContext = {}> = (
action: ResolverData<TContext>,
next: NextFn
) => Promise<any>;


export interface MiddlewareInterface<TContext = {}> {
use: MiddlewareFn<TContext>;
}
export interface MiddlewareClass<TContext = {}> {
new (...args: any[]):
}


export type Middleware<TContext = {}> =
| MiddlewareFn<TContext>
| MiddlewareClass<TContext>;



*Change the import in CreateUser.ts *
import { Middleware } from "../middleware/Middleware";

willcalltickets
Автор

HI, very interesting for CRUD. However, I'm facing in issue for Update part, has tslint throw an error while using the spread operator. Example:
@Mutation(() => GoogleGroups!, { nullable: true })
async updateGoogleGroup(
@Arg("data") data: GoogleGroupType
): Promise<GoogleGroups | null> {
let ggroup: GoogleGroups | null = new GoogleGroups();

ggroup = (await GoogleGroups.findOne({ id: data.id })) || null;

if (!ggroup) {
return null;
}
ggroup = { ...ggroup, ...data } ;
<--- error is here : is missing the following properties from type 'GoogleGroups': hasId, save, remove, reloadts

// ggroup.description = data.description as string;
<--- this is working but not flexible as not all Entites could have description field...
await ggroup!.save();
<--- this failed if I convert { ...ggroup, ...data } as any
return ggroup;
}

In the spread operator ggroup is a BaseEntity extension whereas data is a inputType. I tried to convert the spreadoperator to any, but of course, then, the .save() call failed because ggroups has been converted to any, so no longer BaseEntity. It makes very hard then to create a HOResolver, has the data to update could be different from one entity to another

Any idea ?

yoyo-