Validation TypeGraphQL

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 72

  • @jacob5403
    @jacob5403 4 года назад +1

    my god,
    how awesome is that
    time I wasted on graphl apollo without typescript, no more!
    thank a lot

  • @djchrisi
    @djchrisi 5 лет назад +9

    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

  • @Gualcm
    @Gualcm 5 лет назад +15

    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 лет назад +1

      yeah that function did get removed

    • @4ware
      @4ware 5 лет назад

      @@bawad And? How would you do it now?

    • @willcalltickets
      @willcalltickets 5 лет назад +9

      @@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

  • @TruthVideosOnline
    @TruthVideosOnline 5 лет назад +5

    I LOVE TypeGraphQL!!!

  • @ChaseOhlson19
    @ChaseOhlson19 4 года назад +2

    FYI - Error validation has been deprecated in the newest versions of TypeGraphQL

  • @netstereo
    @netstereo 5 лет назад +9

    Go Ben, go!

  • @EJIROEDWIN
    @EJIROEDWIN 4 года назад +1

    Basically, looks like in new ApolloServer the formatArgumentValidationError is not needed anymore

  • @swashataghosh7462
    @swashataghosh7462 5 лет назад

    Thank you very much Ben. This is really very helpful.

  • @raphaelgarcia4975
    @raphaelgarcia4975 5 лет назад +4

    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 лет назад +2

      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

  • @aigod_
    @aigod_ 5 лет назад

    this series is sick!

  • @mikebrecht970
    @mikebrecht970 3 года назад +4

    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 года назад +1

    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

  • @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 года назад +1

      Yes, but I actually like Joi/yup better

  • @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.

  • @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 ?)

  • @PaulPushkarov
    @PaulPushkarov 5 лет назад +1

    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...

  • @jeremyh9841
    @jeremyh9841 3 года назад

    there is a problem with the new flag in tsconfig : "esModuleInterop": true and the import Express from 'express' line...

  • @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.

  • @сергейказаков-н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: ruclips.net/video/yuV2OxGJAEk/видео.html

    • @сергейказаков-н8щ
      @сергейказаков-н8щ 5 лет назад

      @@bawad Thank you

  • @alexnezhynsky9707
    @alexnezhynsky9707 5 лет назад +1

    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

  • @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

  • @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

  • @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 лет назад +1

      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 лет назад +2

      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 лет назад +1

      @@19majkel94 Yeah, newcomers, like me :D Thanks Michal for your work with TypeGraphQL

  • @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

  • @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

  • @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.

  • @gitanshutalwar1604
    @gitanshutalwar1604 Год назад

    Could have used this.firstName and this.lastName instead of parent @ 3:12