Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

graphqlgen gives UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined #449

Open
devautor opened this issue Feb 11, 2019 · 10 comments
Labels
bug/0-needs-info More information is needed for reproduction. kind/bug

Comments

@devautor
Copy link

devautor commented Feb 11, 2019

EDIT: This issue was actually happening with version 0.4.0 which I was unknowingly executing with graphqlgen (global install), and realised when I did npx graphqlgen. Actual issue as the subject reads has been reported in this comment, and is requested to be taken up from there.

Kindly find a reproduction throwing this error here: https://github.com/devautor/graphqlgen-repro-unhandledPromise

graphqlgen execution gives me this error trace (out of heap memory):

G:\apollo\prod\apollo-server>graphqlgen

<--- Last few GCs --->

[28164:00000205D273F330]   360312 ms: Mark-sweep 1179.9 (1220.6) -> 1179.9 (1220.6) MB, 342.1 / 0.0 ms  allocation failure GC in old space requested[28164:00000205D273F330]   360658 ms: Mark-sweep 1179.9 (1220.6) -> 1179.9 (1186.6) MB, 346.2 / 0.0 ms  last resort GC in old space requested
[28164:00000205D273F330]   361001 ms: Mark-sweep 1179.9 (1186.6) -> 1179.9 (1186.6) MB, 342.7 / 0.0 ms  last resort GC in old space requested
<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 000002446BAA5879 <JSObject>
    0: builtin exit frame: concat(this=000003DD60626801 <JSArray[30393831]>,00000081E787F9A9 <JSArray[8603361]>)

    1: flatten(aka flatten) [C:\Users\gaurav\AppData\Roaming\npm\node_modules\graphqlgen\dist\utils.js:~49] [pc=000003129AB542C3](this=00000214B0A822D1 <undefined>,a=000003DD60626801 <JSArray[30393831]>,b=00000081E787F9A9 <JSArray[8603361]>)
    2: arguments adaptor frame: 4->2
   ...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node_module_register
 2: v8::internal::FatalProcessOutOfMemory
 3: v8::internal::FatalProcessOutOfMemory
 4: v8::internal::Factory::NewUninitializedFixedArray
 5: v8::internal::Factory::NewJSArrayStorage
 6: v8::internal::WasmDebugInfo::SetupForTesting
 7: v8_inspector::protocol::Debugger::API::SearchMatch::fromJSONString
 8: v8_inspector::protocol::Debugger::API::SearchMatch::fromJSONString
 9: v8_inspector::protocol::Debugger::API::SearchMatch::fromJSONString
10: 000003129AA06B21

G:\apollo\prod\apollo-server>

Also, for comparison, graphql-code-generator generates model types and resolvers from the same schema file successfully:

$ gql-gen
  √ Parse configuration
  √ Generate outputs
Done in 4.24s.

Issue #310 earlier reported that this happens with huge schema, so to put in context, my schema.graphql is about 4k loc (introspected and downloaded from prisma-playground). Also, I am not using graphql-import, but typescript files to define schema, and prisma generated types are not imported, but reused (since that issue mentions that as a possible source of error). Against this comment by @victorkangsh, I too am reusing nested structure from primsa input types.

Note: This has earlier been reported in issue #436 and was suggested to be posted independently.

@jasonkuhrt
Copy link
Member

Hey @devautor thanks for creating this. Are you able to share a repro that I can try?

@jasonkuhrt jasonkuhrt added the bug/0-needs-info More information is needed for reproduction. label Feb 12, 2019
@devautor
Copy link
Author

Hi again @jasonkuhrt Since I have no clue what's going on here, carving out a minimal repro would not be straightforward, but I will try as soon as I find some time. Thank you for your patience :)

@jasonkuhrt
Copy link
Member

@devautor even if its a non-minimal repro, if you can share, it will still be useful probably!

Thanks for all your participation to date by the way 🙏

@devautor
Copy link
Author

devautor commented Feb 12, 2019

I won't give to OSS my business app server code that is only possible due to the same OSS community :D
I will definitely try, maybe will try to test nested inputs themselves in minimal schema types, and report if that could fall apart :). It could possibly take time (since I have started with resolvers yesterday <3 ).

@jasonkuhrt That means a lot! I am working towards founding a startup, and that dream stands on the shoulders of beautiful people like yourself. Thank you :)

EDIT: I'm trying to put in a reproduction, because I want graphqlgen to work with me; currently stuck at yet another typescript error on runninggraphqlgen:
(node:28056) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kind' of undefined

EDIT 2: I was using global install of graphqlgen which is at version 0.4.0, executing local install on both the projects with npx graphqlgen (projects: reproduction as well as the project with heap memory issue is now giving me the same error), which is:

(node:31284) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
    at Object.exports.printFieldLikeType (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\common.js:135:52)    at renderTypeResolver (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:234:31)
    at G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:210:82    at Array.map (<anonymous>)
    at renderResolverFunctionInterfaces (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:209:10)
    at renderNamespace (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:153:274)
    at G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:118:16    at Array.map (<anonymous>)
    at renderObjectNamespaces (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:117:10)
    at renderNamespaces (G:\git_projs\bug_repro\graphqlgen-heap-burst\node_modules\graphqlgen\dist\generators\typescript\generator.js:112:21)(node:31284) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31284) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that arenot handled will terminate the Node.js process with a non-zero exit code.

Yes, I am stupid! But, still have to get it working :)

@jasonkuhrt
Copy link
Member

@devautor IIUC you encountered the memory issue because you were using 0.4.x graphqlgen. Can you update the title of this issue to the actual problem you are now facing, or, if its the same as #436 just close this issue? Thanks.

@devautor
Copy link
Author

Hi @jasonkuhrt for the confusion, I had somehow missed it :(
Should #436 remain open for extend support (as that issue is still there when a typescript file is used in schema config), or should I close it?
For this #449 please direct me to any solved issue or mis-step (I couldn't solve this), as this is the actual issue blocking my use of graphqlgen (given that I am using schema.graphql downloaded from prisma-playground in schema config). Or, should I close this, and you will help me on #436 itself?

P.S. Sorry for all this trouble, but I just can't get gen working :(

@devautor devautor changed the title graphqlgen gives FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory graphqlgen gives UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined Feb 12, 2019
@jasonkuhrt
Copy link
Member

Thanks for updating the title, looks different than #436, lets keep this open 👍

@devautor
Copy link
Author

@jasonkuhrt Have shared a repro for your night :)

@rares-lupascu
Copy link

we managed to get the same error

maybe it helps to know that commenting the following line from type Query

node(id: ID!): Node

and also commenting the entire code for the Node interface ... will fix the issue (even though i cannot say for sure it does not generate other issues)

@P4sca1
Copy link

P4sca1 commented Feb 26, 2019

Same error here. Relevant files:

graphqlgen.yml

language: typescript
schema: ./prisma/prisma.graphql
context: ./src/index.ts:IApolloContext
output: ./src/generated/graphqlgen.ts
models:
  files:
    - ./src/generated/prisma-client/index.ts

prisma/datamodel.prisma

type User {
  id: ID! @unique
  email: String @unique
  name: String!
  posts: [Post!]!
}

type Post {
  id: ID! @unique
  title: String!
  published: Boolean! @default(value: "false")
  author: User
}

src/index.ts

export interface IApolloContext {
  prisma: Prisma
}

EDIT:
Got it working. I restructured my project and removed graphql-import. Dont know exactly what caused the issue but it could be graphql-import.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/0-needs-info More information is needed for reproduction. kind/bug
Projects
None yet
Development

No branches or pull requests

5 participants