type-graphql
type-graphql copied to clipboard
TypeGraphQL v2.0
WIP
It's happening 😍🥳
It's coming!!! ❤️❤️❤️
nice!
For anyone reading this - plz dont' forget to contribute $$$. Maintaining an opensource project takes time and skills - nothing comes for free.
Thanks so much for the hard work @MichalLytek!
this is great, thank you, I have asked the company that I work for to contribute to this project. ❤️❤️❤️❤️❤️
@MichalLytek thank you! 🙌❤️
I thought @MichalLytek had died or moved out to the woods leaving all traces of nodejs behind, but he has risen with an amazing Draft PR for us to all admire. May the gods of nodejs bless this draft PR with speed, no bugs, and a quick merge.
All kidding aside I really thought this project had died, and was just starting to plan our exit from type-graphql, but this PR gives me a warm fuzzy that we are headed in the right direction.
I thought @MichalLytek had died or moved out to the woods leaving all traces of nodejs behind, but he has risen with an amazing Draft PR for us to all admire. May the gods of nodejs bless this draft PR with speed, no bugs, and a quick merge.
@hkd987 Much like Keith Richards (of the rolling stones), @MichalLytek cannot be killed by conventional weapons. He is nearly indestructible.
This is exciting 🚀
reflect-metadata Can it use something else instead because it doesn't support esm. It's old.
Hi Michal, this is amazing work and thank you for this! I was doing some researches and I found that the current version of tGQL only works with graphql 15.3.0, just want to know if v2.0 will be compatible with any other 15.x version(ideally 15.5) or 16.x version? Thanks in advance!
Hi Michal, this is amazing work and thank you for this! I was doing some researches and I found that the current version of tGQL only works with graphql 15.3.0, just want to know if v2.0 will be compatible with any other 15.x version(ideally 15.5) or 16.x version? Thanks in advance!
Yes it will, 16.6. check the diff.
reflect-metadata Can it use something else instead because it doesn't support esm. It's old.
@productdevbook Please list something else we can use for shimming reflect metadata api
reflect-metadata Can it use something else instead because it doesn't support esm. It's old.
@productdevbook Please list something else we can use for shimming reflect metadata api
https://github.com/abraham/reflection
@productdevbook Have you tried using that? TypeGraphQL doesn't force to use reflect-metadata:
https://github.com/MichalLytek/type-graphql/blob/91ca9b12f84369423372ab480e6685437a59c675/src/metadata/utils.ts#L60-L68
https://github.com/MichalLytek/type-graphql/blob/91ca9b12f84369423372ab480e6685437a59c675/src/errors/ReflectMetadataMissingError.ts#L1-L10
Maybe we can just list abraham/reflection and core-js/es7/reflect in docs as the alternatives?
@vuki656 thanks much! sorry just one more question, do you know when will this be released? very excited about this
@vuki656 thanks much! sorry just one more question, do you know when will this be released? very excited about this
I don't think there is a date.
Maybe we can just list
abraham/reflectionandcore-js/es7/reflectin docs as the alternatives?
@abraham/reflection seems to work in my project 👍
Hey @MichalLytek, I'm happy to contribute to this PR in case you need support! Would just need some guidance w.r.t what's still left to do
Hey @MichalLytek, I'm happy to contribute to this PR in case you need support! Would just need some guidance w.r.t what's still left to do
If we work on #1356, @MaxAst can also get a contribution towards his hacktoberfest stats 💪
Any word @MichalLytek at what is left and how we might be able to help?
I'm currently trying to create an Apollo server v4 Hapijs adapter, but looks like upgrading Apollo server pushes graphql to v16 and thus triggers this issue in the project I'm using to do the dev.
If someone wants to help, please checkout the branch and run every example to see if all the presented features works ok. The one I've updated the codebase (like apollo federation or mikro-orm) should be checked but e.g. subscriptions might not work.
@MichalLytek started going through examples. Ran into an issue with the "extensions" example. Not sure if you just want them in this thread or elsewhere. Posting this one here, but can update elsewhere if more useful (e.g. new issues, etc.)
{
"errors": [
{
"message": "Service with \"MaybeConstructable<ExampleResolver>\" identifier was not found in the container. Register it before usage via explicitly calling the \"Container.set\" function or using the \"@Service()\" decorator.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"recipes"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"name": "ServiceNotFoundError",
"normalizedIdentifier": "MaybeConstructable<ExampleResolver>",
"stacktrace": [
"ServiceNotFoundError: Service with \"MaybeConstructable<ExampleResolver>\" identifier was not found in the container. Register it before usage via explicitly calling the \"Container.set\" function or using the \"@Service()\" decorator.",
" at ContainerInstance.get (/Users/arimus/workspace/type-graphql/node_modules/src/container-instance.class.ts:75:11)",
" at Function.get (/Users/arimus/workspace/type-graphql/node_modules/src/container.class.ts:61:32)",
" at IOCContainer.getInstance (/Users/arimus/workspace/type-graphql/src/utils/container.ts:57:22)",
" at /Users/arimus/workspace/type-graphql/src/resolvers/create.ts:32:67",
" at field.resolve (/Users/arimus/workspace/type-graphql/node_modules/apollo-server-core/src/utils/schemaInstrumentation.ts:106:18)",
" at executeField (/Users/arimus/workspace/type-graphql/node_modules/graphql/execution/execute.js:481:20)",
" at executeFields (/Users/arimus/workspace/type-graphql/node_modules/graphql/execution/execute.js:413:20)",
" at executeOperation (/Users/arimus/workspace/type-graphql/node_modules/graphql/execution/execute.js:344:14)",
" at execute (/Users/arimus/workspace/type-graphql/node_modules/graphql/execution/execute.js:136:20)",
" at execute (/Users/arimus/workspace/type-graphql/node_modules/apollo-server-core/src/requestPipeline.ts:500:34)"
]
}
}
}
],
"data": null
}
I've published the current state of this branch as [email protected].
I've tested it in my project and can confirm that v2.0 works like a charm.
@MichalLytek
Instead of generic Error, the error classes related to GraphQL can extend GraphQLError.
@MichalLytek Instead of generic
Error, the error classes related toGraphQLcan extend GraphQLError.
Not sure if its related but i bumped to apollo server v4 and used this beta release and im not getting the class-validator validation errors in the extensions like this: https://github.com/MichalLytek/type-graphql/issues/258#issuecomment-466637130, im instead getting . not sure if im configuring it wrong @MichalLytek @carlocorradini
{
"data": {},
"errors": [
{
"message": "Argument Validation Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"textPost"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"stacktrace": [
"Error: Argument Validation Error",
" at validateArg (/<local-path>/node_modules/type-graphql/dist/resolvers/validate-arg.js:55:15)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Promise.all (index 0)"
]
}
}
]
}
running on an express server
const server = new ApolloServer({
schema: schema,
});
await server.start();
app.use(
'/graphql',
express.json(),
expressMiddleware(server, {
context: async ({req}) => ({token: req.headers.token}),
}),
);
i added this to intercept and log
formatError: (formattedError,error: any) => {
if (error.originalError instanceof ArgumentValidationError) {
const { extensions, locations, message, path } = error;
// error.extensions.code = 'GRAPHQL_VALIDATION_FAILED';
console.log(error)
// return {
// extensions,
// locations,
// message,
// path,
// };
}
return formattedError;
}
but it doesnt produces have the validation errors
@okaforcj For me it's working without any problems (TypeGraphQL v2 & Apollo Server v4):

Context:
Project
https://github.com/carlocorradini/reCluster/tree/main/server
main.ts (Apollo Server, etc...)
https://github.com/carlocorradini/reCluster/blob/main/server/src/main.ts
Custom errors
https://github.com/carlocorradini/reCluster/tree/main/server/src/errors
formatError.ts
https://github.com/carlocorradini/reCluster/blob/main/server/src/helpers/formatError.ts
Thanks a lot, works like a charm. Sorry for disturbing you guys but thanks for the amazing library @MichalLytek and @carlocorradini I really appreciate the help.
@okaforcj What was the error? :)