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.
@@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 });
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\""
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.
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 ?)
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 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...
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.
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
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.
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.
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
@InputType() creates a graphql input type graphql.org/graphql-js/mutations-and-input-types/ @ArgsType() creates an argument graphql.org/graphql-js/passing-arguments/
my god,
how awesome is that
time I wasted on graphl apollo without typescript, no more!
thank a lot
Do not forget the '--no-notify' flag of ts-node-dev. Otherwise it'll drive you crazy.
you've saved my life
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.
yeah that function did get removed
@@bawad And? How would you do it now?
@@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 });
In the meantime they have left it as it was in the docs!
:)
@@willcalltickets thank you
I LOVE TypeGraphQL!!!
FYI - Error validation has been deprecated in the newest versions of TypeGraphQL
Go Ben, go!
Basically, looks like in new ApolloServer the formatArgumentValidationError is not needed anymore
Thank you very much Ben. This is really very helpful.
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?
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
this series is sick!
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\""
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?
just for example purposes
custom decorator, super cool.
@Ben Awad is the class-validator a replacement for joi validator when it comes down to this kind of typescript, typeorm architecture?
Yes, but I actually like Joi/yup better
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.
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 ?)
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.
you could remove the validation from the db and just do application validation
@@bawad Yeah, but then my objects won't be validated if I create them outside of graphql context.
@@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...
there is a problem with the new flag in tsconfig : "esModuleInterop": true and the import Express from 'express' line...
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.
Hi, Ben. Could you publish a gist with your vs code extensions using Settings Sync vs code extension?
I'll set that up, in the mean time I have my extensions in the description: ruclips.net/video/yuV2OxGJAEk/видео.html
@@bawad Thank you
It feels a bit like writing Java in Spring lol Jk, good job
with all the decorators it does have that feel
You mentioned using a new way to organize your files and folders, can you share the link?
hackernoon.com/fractal-a-react-app-structure-for-infinite-scale-4dab943092af
Ben... thanks for sharing...pls could you show how type-graphql handle file upload
I think uploading a file would work the same with or without type-graphql
@@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
Christian Gyaban you could possible just use a simple rest api for your file upload and continue to use Type-GraphQL for everything else
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
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.
const schema = await buildSchema({
resolvers: [RegisterResolver],
validate: { validationError: { target: false } }
});
This removes target from returning
@@celeneg Its does :D
@@19majkel94 Yeah, newcomers, like me :D Thanks Michal for your work with TypeGraphQL
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.
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
@@bawad Submitted an issue into type-graphql as well
That's a good idea, type-graphql will want to match up it's type definitions
What is the difference between @ArgsType() and @InputType() ?
@InputType() creates a graphql input type graphql.org/graphql-js/mutations-and-input-types/
@ArgsType() creates an argument graphql.org/graphql-js/passing-arguments/
@@bawad Thanks Ben! Can't wait for next episode :D
Typescript + typeorm/typegoose + type-graphql + class-validator === "match in even"
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.
that's the plan
@@bawad oh great!
Could have used this.firstName and this.lastName instead of parent @ 3:12