Validation TypeGraphQL

  Рет қаралды 23,904

Ben Awad

Ben Awad

Күн бұрын

Пікірлер: 72
@jacob5403
@jacob5403 4 жыл бұрын
my god, how awesome is that time I wasted on graphl apollo without typescript, no more! thank a lot
@Gualcm
@Gualcm 5 жыл бұрын
I believe formatArgumentValidationError was removed from type-graphql. I get an error that there is no such export, and I can't find formatArgumentValidationError on type-graphql's documentation.
@bawad
@bawad 5 жыл бұрын
yeah that function did get removed
@4ware
@4ware 5 жыл бұрын
@@bawad And? How would you do it now?
@willcalltickets
@willcalltickets 5 жыл бұрын
@@4ware - this is done automatically now. Just remove that line from the ApolloServer call in index.ts - and remove the import formatArgumentValidationError from type-graphql. in index.ts should be const apolloServer = new ApolloServer({ schema });
@fullstackgreekdeveloper8033
@fullstackgreekdeveloper8033 4 жыл бұрын
In the meantime they have left it as it was in the docs! :)
@lenhu7089
@lenhu7089 4 жыл бұрын
@@willcalltickets thank you
@djchrisi
@djchrisi 4 жыл бұрын
Do not forget the '--no-notify' flag of ts-node-dev. Otherwise it'll drive you crazy.
@pavle649
@pavle649 4 жыл бұрын
you've saved my life
@TruthVideosOnline
@TruthVideosOnline 5 жыл бұрын
I LOVE TypeGraphQL!!!
@netstereo
@netstereo 5 жыл бұрын
Go Ben, go!
@ChaseOhlson19
@ChaseOhlson19 4 жыл бұрын
FYI - Error validation has been deprecated in the newest versions of TypeGraphQL
@aigod_
@aigod_ 5 жыл бұрын
this series is sick!
@raphaelgarcia4975
@raphaelgarcia4975 5 жыл бұрын
Ben very good your videos, it helps me a lot in the day to day! How do I make a many to many insertion with typegraphql?
@bawad
@bawad 5 жыл бұрын
Do you know how to do it with regular graphql? It's the same way and in typeorm you can do this: typeorm.io/#/many-to-many-relations
@swashataghosh7462
@swashataghosh7462 5 жыл бұрын
Thank you very much Ben. This is really very helpful.
@EJIROEDWIN
@EJIROEDWIN 4 жыл бұрын
Basically, looks like in new ApolloServer the formatArgumentValidationError is not needed anymore
@peterm.souzajr.2112
@peterm.souzajr.2112 5 жыл бұрын
custom decorator, super cool.
@vigneshs2886
@vigneshs2886 4 жыл бұрын
@Ben Awad is the class-validator a replacement for joi validator when it comes down to this kind of typescript, typeorm architecture?
@bawad
@bawad 4 жыл бұрын
Yes, but I actually like Joi/yup better
@mikebrecht970
@mikebrecht970 3 жыл бұрын
Pro tips: - formatArumentValidation doesn't exist anymore. The functionality that it provided should be included in the current version of type-graphql with no additional work. - You don't need to build a custom decorator to check if the email is already in use. If you set the field to be unique ( @Column("text", { unique: true }) ), then you should get an error message when trying to register a second user with the same email. Mine looks like this: message: "duplicate key value violates unique constraint \"UQ_e12875dfb3b1d92d7d7c5377e22\""
@CardinalHijack
@CardinalHijack 4 жыл бұрын
Why do we bother doing the custom decorator at 10:20, when we check the email is unique in the Users.ts file in the entity folder?
@bawad
@bawad 4 жыл бұрын
just for example purposes
@Lee-qj4hk
@Lee-qj4hk 4 жыл бұрын
8:02 "Now, I'm not actually sure what exactly a good first-name, last-name length would be...": en.wikipedia.org/wiki/Hubert_Blaine_Wolfeschlegelsteinhausenbergerdorff_Sr. (1024 ?)
@siafudev7172
@siafudev7172 5 жыл бұрын
You mentioned using a new way to organize your files and folders, can you share the link?
@bawad
@bawad 5 жыл бұрын
hackernoon.com/fractal-a-react-app-structure-for-infinite-scale-4dab943092af
@alexnezhynsky9707
@alexnezhynsky9707 5 жыл бұрын
It feels a bit like writing Java in Spring lol Jk, good job
@bawad
@bawad 5 жыл бұрын
with all the decorators it does have that feel
@MrEnsiferum77
@MrEnsiferum77 4 жыл бұрын
i've tried this days to run ts-node-dev inside docker container, but I had issues with running it in watch mode. But after running "nodemon -L src/index.ts", actually nodemon, now is smart enough to run "ts-node-dev --respawn src/index.ts" under the hood.
@PaulPushkarov
@PaulPushkarov 5 жыл бұрын
It seems like developer needs to define validation rules twice - first time in User model and second time in RegisterInput. It does not pickup validation rules from model, just throws "server error", is there a way to avoid duplication? Thanks.
@bawad
@bawad 5 жыл бұрын
you could remove the validation from the db and just do application validation
@PaulPushkarov
@PaulPushkarov 5 жыл бұрын
@@bawad Yeah, but then my objects won't be validated if I create them outside of graphql context.
@PaulPushkarov
@PaulPushkarov 5 жыл бұрын
@@bawad For now went with a custom save() method saveInResolver (extended BaseEntity) that validates the model and throws new UserInputError('...', {validationErrors}) in cases of validation errors...
@сергейказаков-н8щ
@сергейказаков-н8щ 5 жыл бұрын
Hi, Ben. Could you publish a gist with your vs code extensions using Settings Sync vs code extension?
@bawad
@bawad 5 жыл бұрын
I'll set that up, in the mean time I have my extensions in the description: kzbin.info/www/bejne/r6a5Y4KufK90e80
@сергейказаков-н8щ
@сергейказаков-н8щ 5 жыл бұрын
@@bawad Thank you
@christiangyaban9666
@christiangyaban9666 5 жыл бұрын
Ben... thanks for sharing...pls could you show how type-graphql handle file upload
@bawad
@bawad 5 жыл бұрын
I think uploading a file would work the same with or without type-graphql
@christiangyaban9666
@christiangyaban9666 5 жыл бұрын
@@bawad I tried but it didn't work as it was complaining so I have to drop type-graphql for something else but I hope you can try it out
@benjidaniel5595
@benjidaniel5595 5 жыл бұрын
Christian Gyaban you could possible just use a simple rest api for your file upload and continue to use Type-GraphQL for everything else
@CardinalHijack
@CardinalHijack 4 жыл бұрын
Man I missed the auto import at 12:15 - my vscode didnt auto import. Spent an hour working out why I was getting no error message in the graphQL playground (everything ran fine). Would be cool to just clarify any imports I think.
@netstereo
@netstereo 5 жыл бұрын
Hi Ben. Do you know how we can further customize the error returned by formatArgumentValidationError? Maybe return an array of objects with the "faulty" property name and the error message as the value? Right now even the password is returned
@19majkel94
@19majkel94 5 жыл бұрын
It returns the payload that user sent, so it's not a data leak I think :P But in `formatError` you can do anything you need for safety, the built-in helper is just a few lines, for newcomers mostly.
@celeneg
@celeneg 5 жыл бұрын
const schema = await buildSchema({ resolvers: [RegisterResolver], validate: { validationError: { target: false } } }); This removes target from returning
@netstereo
@netstereo 5 жыл бұрын
@@celeneg Its does :D
@netstereo
@netstereo 5 жыл бұрын
@@19majkel94 Yeah, newcomers, like me :D Thanks Michal for your work with TypeGraphQL
@jeremyh9841
@jeremyh9841 3 жыл бұрын
there is a problem with the new flag in tsconfig : "esModuleInterop": true and the import Express from 'express' line...
@Iwillownyouandbehappy
@Iwillownyouandbehappy 5 жыл бұрын
What is the difference between @ArgsType() and @InputType() ?
@bawad
@bawad 5 жыл бұрын
@InputType() creates a graphql input type graphql.org/graphql-js/mutations-and-input-types/ @ArgsType() creates an argument graphql.org/graphql-js/passing-arguments/
@Iwillownyouandbehappy
@Iwillownyouandbehappy 5 жыл бұрын
@@bawad Thanks Ben! Can't wait for next episode :D
@GizmoDuck5
@GizmoDuck5 5 жыл бұрын
Not exactly sure why I'm getting this but haven't seen anyone else with this issue. When I use the formatError: formatArgumentValidationError option I get a typescript error. [ERROR] 09:27:28 ⨯ Unable to compile TypeScript: src/index.ts(16,51): error TS2322: Type '(err: GraphQLError) => { [key: string]: any; }' is not assignable to type '(error: GraphQLError) => GraphQLFormattedError'. Type '{ [key: string]: any; }' is missing the following properties from type 'GraphQLFormattedError': message, locations, path I have followed the tutorial pretty much to a T. Only thing I can come up with is a version difference potentially in one of the dependencies.
@bawad
@bawad 5 жыл бұрын
yeah I think your right, apollo-server probably changed it's typescript definitions with a new version I would just cast it to any: formatError: formatArgumentValidationError as any
@GizmoDuck5
@GizmoDuck5 5 жыл бұрын
@@bawad Submitted an issue into type-graphql as well
@bawad
@bawad 5 жыл бұрын
That's a good idea, type-graphql will want to match up it's type definitions
@besjansejrani1880
@besjansejrani1880 3 жыл бұрын
Typescript + typeorm/typegoose + type-graphql + class-validator === "match in even"
@임창수-c7c
@임창수-c7c 5 жыл бұрын
Could you make next.js series later with this? I tried to follow along your codeponder but it was hard. Just a suggestion. Thank you always.
@bawad
@bawad 5 жыл бұрын
that's the plan
@임창수-c7c
@임창수-c7c 5 жыл бұрын
@@bawad oh great!
@gitanshutalwar1604
@gitanshutalwar1604 Жыл бұрын
Could have used this.firstName and this.lastName instead of parent @ 3:12
Higher Order Resolvers TypeGraphQL
15:06
Ben Awad
Рет қаралды 10 М.
Authorization TypeGraphQL
10:31
Ben Awad
Рет қаралды 17 М.
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 1,3 МЛН
Try Not To Laugh 😅 the Best of BoxtoxTv 👌
00:18
boxtoxtv
Рет қаралды 7 МЛН
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 22 МЛН
Setting up a Test Environment TypeGraphQL
18:11
Ben Awad
Рет қаралды 12 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
DRM explained - How Netflix prevents you from downloading videos?
18:17
Mehul - Codedamn
Рет қаралды 198 М.
Confirmation Email TypeGraphQL
18:44
Ben Awad
Рет қаралды 12 М.
Login TypeGraphQL
16:33
Ben Awad
Рет қаралды 21 М.
10  laravel graphql - validation rules
5:01
Bitfumes
Рет қаралды 3,3 М.
File Uploads TypeGraphQL
6:01
Ben Awad
Рет қаралды 25 М.
The Best GraphQL Library You've Never Tried
8:01
Ben Awad
Рет қаралды 7 М.
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 1,3 МЛН