slicknode/graphql-query-complexity

Using within typescript project

mydnicq opened this issue · 3 comments

Thank you for this awesome package, which I'm sure it'll become an important part in every graphql server written in Javascript.

I have a graphql server based on Apollo Server and the whole project is written in TypeScript. For running the server I use ts-node.

The problem I have is when I make a query, I always get 'Query Complexity of 0'. Then I made a custom Typescript module to where I copied the graph-query-complexity code with small modifications regarding only the type definitions. With this module, the Query Complexity is calculated as it should.

I'm not sure if this is a problem of the package or the fact that I'm using Typescript with ts-node.

Any help would be more than welcome.

After doing some more investigation, I found that the problem isn't in using Apollo Server nor in ts-node, but how graphql module is included in the project.

In your module package.json, the graphql module is defined as dependency. My project also has graphql module as dependency and creators of graphql stated that there should be only one graphql module per project. After removing graphql module from your package's node_modules, everything works.

So I recommend that you change graphql moduledependency to peerDependency.

ivome commented

Thanks for reporting and investigating the issue. I just released a new version with that change. Could you check if that solved the problem?

Yes it is solved. Thank you!