graphql-code-generator: typescript-resolvers v4.2.1 causes error when typechecking: `Maximum call stack size exceeded`

Which packages are impacted by your issue?

@graphql-codegen/typescript-resolvers

Describe the bug

With the v4.2.1 release of @graphql-codegen/typescript-resolvers, I started seeing an error Maximum call stack size exceeded when running the typescript compiler. This did not happen on v4.2.0.

Your Example Website or App

https://github.com/dylanwulf/graphql-code-generator-issue-sandbox-template/tree/typescript-resolvers-max-call-stack-exceeded

Steps to Reproduce the Bug or Issue

  1. in the linked github repo, check out branch typescript-resolvers-max-call-stack-exceeded
  2. npm install
  3. npm run codegen (optional – the types have already been generated and committed)
  4. npm run typecheck
  5. see error

Expected behavior

I expected no error

Screenshots or Videos

No response

Platform

  • OS: Windows 11
  • NodeJS: 20.13.1
  • graphql version: see package.json in linked github repo
  • @graphql-codegen/* version(s): see package.json in linked github repo

Codegen Config File

See linked github repo

Additional context

The full error output I see in the console:

> graphql-codegen-issue-template@1.0.0 typecheck
> tsc

C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:98439
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at Object.createBaseTokenNode (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:22176:39)
    at createBaseToken (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:18429:32)
    at createBaseLiteral (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:18308:24)
    at createBaseStringLiteral (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:18326:24)
    at Object.createStringLiteral (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:18331:24)
    at typeToTypeNodeWorker (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:43717:88)
    at typeToTypeNodeHelper (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:43641:32)
    at mapToTypeNodes (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:44401:40)
    at typeToTypeNodeWorker (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:43831:37)
    at typeToTypeNodeHelper (C:\Users\redacted\projects\graphql-code-generator-issue-sandbox-template\node_modules\typescript\lib\tsc.js:43641:32)

Node.js v20.13.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17

Most upvoted comments

This is fixed in @graphql-codegen/typescript-resolvers@4.4.0. Thank you for reporting!

Hi all, There will be an option called avoidCheckingAbstractTypesRecursively. Please use it together with the defaultMapper option if defaultMapper is recursive:

config: {
  defaultMapper: 'DeepPartial<{T}>',  
  avoidCheckingAbstractTypesRecursively: true // required if you have complex nested abstract types
},

There’s an alpha version here: 4.4.0-alpha-20241014102200-ddc58bcd59abae2c907ea72c013c42ae94232b54 Please try it out and let me know if it fixes the issue. Once confirmed, I can try to release it ASAP.

@eddeee888 Thank you! That alpha version with the new option fixes the issue for me!

You are right, let me have a chat with the team to understand this a bit more.

I’ll see what I can do 🙂 Just a note, mappers will have first-class support so new features will be tested against it. I think defaultMapper was added to support some use cases but may not have the guarantee to always work.

This is a bit confusing because both features are documented with the same level of importance and there’s no indication provided other than this comment that users should avoid defaultMapper. In fact, this exact use of DeepPartial as the defaultMapper is an example from the docs.

@eddeee888 Yeah, this is for server side code, and my resolvers don’t always return the full type, sometimes there is additional fetching in the “leaves” subtypes so I allow returning partial responses while still ensuring type safety to some degree