type-graphql icon indicating copy to clipboard operation
type-graphql copied to clipboard

TypeGraphQL v2.0

Open MichalLytek opened this issue 3 years ago • 18 comments

WIP

MichalLytek avatar Aug 16 '22 14:08 MichalLytek

It's happening 😍🥳

carlocorradini avatar Aug 17 '22 08:08 carlocorradini

It's coming!!! ❤️❤️❤️

alvis avatar Aug 17 '22 09:08 alvis

nice!

For anyone reading this - plz dont' forget to contribute $$$. Maintaining an opensource project takes time and skills - nothing comes for free.

orefalo avatar Aug 17 '22 10:08 orefalo

Thanks so much for the hard work @MichalLytek!

LeoBorai avatar Aug 17 '22 11:08 LeoBorai

this is great, thank you, I have asked the company that I work for to contribute to this project. ❤️❤️❤️❤️❤️

angelo-moreira avatar Aug 18 '22 11:08 angelo-moreira

@MichalLytek thank you! 🙌❤️

noxend avatar Aug 19 '22 07:08 noxend

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.

hkd987 avatar Sep 01 '22 11:09 hkd987

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.

jessekrubin avatar Sep 05 '22 19:09 jessekrubin

This is exciting 🚀

bnussman avatar Sep 05 '22 21:09 bnussman

reflect-metadata Can it use something else instead because it doesn't support esm. It's old.

productdevbook avatar Sep 07 '22 18:09 productdevbook

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!

kt390256 avatar Sep 11 '22 06:09 kt390256

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.

vuki656 avatar Sep 11 '22 06:09 vuki656

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

MichalLytek avatar Sep 11 '22 08:09 MichalLytek

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 avatar Sep 11 '22 09:09 productdevbook

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

MichalLytek avatar Sep 11 '22 09:09 MichalLytek

@vuki656 thanks much! sorry just one more question, do you know when will this be released? very excited about this

kt390256 avatar Sep 11 '22 22:09 kt390256

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

vuki656 avatar Sep 12 '22 07:09 vuki656

Maybe we can just list abraham/reflection and core-js/es7/reflect in docs as the alternatives?

@abraham/reflection seems to work in my project 👍

beeequeue avatar Sep 12 '22 08:09 beeequeue

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

MaxAst avatar Oct 01 '22 09:10 MaxAst

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 💪

itpropro avatar Oct 02 '22 15:10 itpropro

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.

arimus avatar Oct 07 '22 21:10 arimus

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 avatar Oct 11 '22 09:10 MichalLytek

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

arimus avatar Oct 13 '22 22:10 arimus

I've published the current state of this branch as [email protected].

MichalLytek avatar Oct 19 '22 10:10 MichalLytek

I've tested it in my project and can confirm that v2.0 works like a charm.

carlocorradini avatar Oct 20 '22 12:10 carlocorradini

@MichalLytek  Instead of generic Error, the error classes related to GraphQL can extend GraphQLError.

carlocorradini avatar Oct 20 '22 13:10 carlocorradini

@MichalLytek  Instead of generic Error, the error classes related to GraphQL can 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 avatar Oct 23 '22 08:10 okaforcj

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 avatar Oct 23 '22 09:10 okaforcj

@okaforcj What was the error? :)

carlocorradini avatar Oct 23 '22 10:10 carlocorradini