Setting up a Test Environment TypeGraphQL

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

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

  • @kentbull
    @kentbull 3 года назад +1

    Well done. This is valuable content.
    I especially appreciate how you follow good design principles by factoring small units of functionality out into their own files or modules and then importing that module at call sites.

  • @RM-bg5cd
    @RM-bg5cd 4 года назад

    I had a Prisma 2 setup which uses the typical schema query language string and the resolvers passed to the GraphQLServer constructor. Had to use the makeExecutableSchema passing exactly those two values I mentioned earlier to this function to generate the schema, works wonderfully. Thank you!

  • @MatthewLin
    @MatthewLin 2 года назад +1

    For that jest hanging issue, it was redis not being disconnected on my end. You need to call redis.disconnect when you stop the server so the process can exit

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

    Great content. Thank you for sharing your knowledge.

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

    You can grab Maybe directly from 'type-graphql'

  • @MrProthall
    @MrProthall 4 года назад

    I am uaing tape as testrunner, but the whole setup process for the database really slipped the switch for me! Testing is so easy now.

  • @christiangyaban9666
    @christiangyaban9666 5 лет назад +2

    great content...love it

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

    thank you so much for this!

  • @anismuhaimin970
    @anismuhaimin970 3 года назад +2

    anyone got this problem:
    schema: await createSchema();
    }
    return graphql({
    schema,
    source,
    variableValues,
    expected undefined to be a GraphQL schema

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

    Hi Ben, thanks for the videos. For the build schema resolvers glob after googling a bit found that you can exclude directories so I created a __test__ folder inside modules so the glob would be `'/../modules/{,!(__test__)}/*.ts'`.

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

      nice!

    • @kokhenglim8114
      @kokhenglim8114 5 лет назад +2

      Or maybe you can exclude the .test.ts like this '/../modules/**/!(*.test).ts' . Find the solution here: stackoverflow.com/questions/26639236/node-glob-pattern-for-every-js-file-except-spec-js/26648205

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

    Great video, Ben.
    @BenAwad One question: is there a good way to run those tests in isolation _without_ hitting the database? E.g. an in-memory database mock that TypeORM is using instead of a real db? Something like mockgoose does?

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

      Not that I know of, but I would love to do that if it existed.

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

      @@bawad I also tried to jest-mock the User entity, but i ran into problems there as well. For example I tried to create a user mock without any typeorm decorators, but than type-graph complained that the schema is invalid since two "User" classes exists. Did you ever tried/succeeded with this approach?

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

      Apparently there is a project called sqljs: github.com/kripken/sql.js/. It is volatile in-memory SQLLite database. And there is also a driver for typeorm (?): github.com/typeorm/typeorm/blob/master/src/driver/sqljs/SqljsConnectionOptions.ts. Maybe this will do the trick 🤔

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

      cool, I'll give that a try sometime.

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

      import the resolvers in your buildSchema instead of using a glob

  • @unixrebel
    @unixrebel 4 года назад

    any chance you can do an updated version of this? or is there better software to use as of this date. I'm looking online and there seems to be a few options.

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

      the latest one is ruclips.net/video/Pv_0UpaxVHU/видео.html

    • @unixrebel
      @unixrebel 4 года назад

      @@bawad thanks Ben!

  • @mentansh5702
    @mentansh5702 5 лет назад +2

    Getting this error:
    console.log src/modules/user/register/Register.test.ts:29
    { errors:
    [ GraphQLError {
    message: 'Argument Validation Error',
    locations: [ { line: 3, column: 3 } ],
    path: [ 'register' ] } ],
    data: null }
    Any idea on how to debug?

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

      Oh that may be happening when faker creates a random name that's too short. I think you can pass a min lenth to faker

    • @tzorek4440
      @tzorek4440 5 лет назад +3

      Check your PasswordInput.ts and make sure that the decorator for min says @MinLength(5) instead of @Min(5). I had the same issue when I had @Min(5)... I was always getting a validation error.

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

      Same error here:
      console.log src/modules/resolvers/user/register/Register.test.ts:30
      { errors:
      [ GraphQLError {
      message: 'Argument Validation Error',
      locations: [Array],
      path: [Array] } ],
      data: null }
      I already check for the decorator @MinLength(5) and it is fine. Everything works fine at the graphql playground but it fails at the test.
      And I really don't get what Ben means with pass a min length to faker.

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

      @@tzorek4440 Ya, already gave that a shot but still getting the validation error. The graphqlerror output isn't really all that helpful either.

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

      We require a min length of 5 on the password, I'm thinking maybe the password faker is creating may be less than 5 and cause the 'Argument Validation Error'
      You can tell faker to make it longer by doing:
      faker.internet.password(10)

  • @kaousheik9985
    @kaousheik9985 4 года назад

    Great playlist sir.
    But one doubt.
    Is it possible to extend the classes in other files as it is done in Apollo .
    type User {
    name: String
    }
    in one file and extending this type in another file
    extend type User{
    email: String!
    }
    Is this possible using typegraphql??

    • @bawad
      @bawad  4 года назад

      not really, that I'm aware of

    • @kaousheik9985
      @kaousheik9985 4 года назад

      @@bawad any alternatives??

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

    Instead of creating "interface Options" couldn't you "import GraphQLArgs" and use that as type for gCall parameter instead?

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

      You could do that, but we want to add more fields to Options later

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

    Hey guys, does anyone get this error 'user" does not exist'' on running the test? How did you resolve it @benawad

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

      What throws that error?

  • @richarddoust6710
    @richarddoust6710 4 года назад

    Where can I ask questions if my results differ because underlying libraries have changed, for example, formatValidationArgError is no longer available, so removing it might be causing all of my validations to fail when the test is run. If I remove all of them, the code works, but I get a warning in the console: No metadata found. There is more than once (sic) class-validator version installed probably. You need to flatten your dependencies.

    • @richarddoust6710
      @richarddoust6710 4 года назад

      It was formatArgumentValidationError that was removed in 2/19 by the developer (github.com/MichalLytek/type-graphql/issues/258). There are posts on GitHub regarding the class-validator issue: github.com/typestack/class-validator/issues/261

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

    How does the gCall function know that your server is running on localhost:4000?

    • @bawad
      @bawad  5 лет назад +2

      gCall doesn't call the server, it uses the schema and calls that

  • @johnmcneill1998
    @johnmcneill1998 4 года назад

    Register test is failing for me here:
    describe("Register", () => {
    > 29 | it("create user", async () => {
    | ^
    getting this error: "Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout"
    I can make the test pass if I remove the first "await" from "await sendEmail(email, await createConfirmationUrl(user.id));" in the Register.ts file.
    I copied and pasted both of your sendEmail and createConfirmationUrl functions from git, so they should be right.
    Don't spend too much time on this, but maybe there is something obvious I am not seeing? I see sendEmail doesn't returns :Promise. What are we awaiting?

    • @오락가락관
      @오락가락관 4 года назад

      Maybe this link will help you.
      stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti
      I think it's an error that came out because the default timeout for the jest was exceeded.

  • @ДанилШаймурзин-т4р

    nice

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

    I'm getting the following test failure:
    TypeError: Cannot read property 'close' of undefined
    9 |
    10 | afterAll(async () => {
    > 11 | await conn.close()
    | ^
    12 | })
    I've checked my code against your over and over. It's identical

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

      is your testConn returning undefined? github.com/benawad/type-graphql-series/blob/8_setup_testing_env/src/modules/user/register/Register.test.ts#L8

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

      I'm an idiot! testConn came back undefined because it couldn't make a connection because I hadn't started postgres 🤦‍♂️ Sorry!

  • @sinamaleki3908
    @sinamaleki3908 4 года назад

    I've got this error and I could find out what's the problem:
    ```
    {
    errors: [
    QueryFailedError: relation "user" does not exist
    ```

  • @sammmywammmy
    @sammmywammmy 2 года назад

    ReferenceError: await is not defined
    anyone else get this when running the test? can run the application without any issues

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

    Error: Cannot find connection default because its not defined in any orm configuration files
    You have an idea how to solve this error,
    I want to use my configuration ormconfig.json development and test of Airb&b, only accept the name : default

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

      When you create the typeorm connection set the name to default

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

      With typegraphQL we continue working with the environments. NODE_ENV, HOST_ENV, FRONTEND_HOST, process.env, etc... ?

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

      Yeah you can