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.
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!
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
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'`.
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
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 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?
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 🤔
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.
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.
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.
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)
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??
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.
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
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?
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.
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
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
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.
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!
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
Great content. Thank you for sharing your knowledge.
You can grab Maybe directly from 'type-graphql'
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.
great content...love it
thank you so much for this!
anyone got this problem:
schema: await createSchema();
}
return graphql({
schema,
source,
variableValues,
expected undefined to be a GraphQL schema
did you solve it?
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'`.
nice!
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
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?
Not that I know of, but I would love to do that if it existed.
@@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?
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 🤔
cool, I'll give that a try sometime.
import the resolvers in your buildSchema instead of using a glob
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.
the latest one is ruclips.net/video/Pv_0UpaxVHU/видео.html
@@bawad thanks Ben!
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?
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
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.
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.
@@tzorek4440 Ya, already gave that a shot but still getting the validation error. The graphqlerror output isn't really all that helpful either.
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)
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??
not really, that I'm aware of
@@bawad any alternatives??
Instead of creating "interface Options" couldn't you "import GraphQLArgs" and use that as type for gCall parameter instead?
You could do that, but we want to add more fields to Options later
Hey guys, does anyone get this error 'user" does not exist'' on running the test? How did you resolve it @benawad
What throws that error?
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.
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
How does the gCall function know that your server is running on localhost:4000?
gCall doesn't call the server, it uses the schema and calls that
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?
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.
nice
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
is your testConn returning undefined? github.com/benawad/type-graphql-series/blob/8_setup_testing_env/src/modules/user/register/Register.test.ts#L8
I'm an idiot! testConn came back undefined because it couldn't make a connection because I hadn't started postgres 🤦♂️ Sorry!
I've got this error and I could find out what's the problem:
```
{
errors: [
QueryFailedError: relation "user" does not exist
```
Same
ReferenceError: await is not defined
anyone else get this when running the test? can run the application without any issues
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
When you create the typeorm connection set the name to default
With typegraphQL we continue working with the environments. NODE_ENV, HOST_ENV, FRONTEND_HOST, process.env, etc... ?
Yeah you can