RisingStack / graffiti-mongoose

⚠️ DEVELOPMENT DISCONTINUED - Mongoose (MongoDB) adapter for graffiti (Node.js GraphQL ORM)

Home Page:https://risingstack-graffiti.signup.team/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graffitti breaks on recursive models (Upgrading from 4.3.3 to 5.0.8) RangeError: Maximum call stack size exceeded

jontonsoup opened this issue · comments

When I upgraded from 4.3.3 to 5.0.8 I'm getting an error (RangeError: Maximum call stack size exceeded) in lodash that seems to be related to recursive schemas.

Here is a summary of my model (This worked in 4.3.3):

const RecursiveSchema = new mongoose.Schema({})
RecursiveSchema.add({
  name: {
    type: String,
    required: true,
    match: /^\S+$/
  },
  description: String,
  children: [RecursiveSchema]
})

const mainSchema = new mongoose.Schema({
  fields.....
  recursive: [RecursiveSchema],

}, { timestamps: true })

Here is a stacktrace of the error:

11:07:16 PM web.1  |  /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2309
11:07:16 PM web.1  |      function baseClone(value, isDeep, customizer, key, object, stack) {
11:07:16 PM web.1  |                        ^
11:07:16 PM web.1  |  RangeError: Maximum call stack size exceeded
11:07:16 PM web.1  |      at baseClone (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2309:23)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2358:34
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4127:15
11:07:16 PM web.1  |      at baseForOwn (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2639:24)
11:07:16 PM web.1  |      at baseClone (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2357:39)
11:07:16 PM web.1  |      at baseMergeDeep (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:3175:24)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:3111:11
11:07:16 PM web.1  |      at arrayEach (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:482:11)
11:07:16 PM web.1  |      at baseMerge (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:3104:7)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:11633:7
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4075:13
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:9183:31
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:118:30
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:809:11
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4127:15
11:07:16 PM web.1  |      at baseForOwn (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2639:24)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4096:18
11:07:16 PM web.1  |      at baseReduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:806:5)
11:07:16 PM web.1  |      at reduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8096:14)
11:07:16 PM web.1  |      at extractPaths (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:117:29)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:84:20
11:07:16 PM web.1  |      at arrayReduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:669:21)
11:07:16 PM web.1  |      at reduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8123:14)
11:07:16 PM web.1  |      at extractPath (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:79:34)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:118:39
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:809:11
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4127:15
11:07:16 PM web.1  |      at baseForOwn (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2639:24)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4096:18
11:07:16 PM web.1  |      at baseReduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:806:5)
11:07:16 PM web.1  |      at reduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8096:14)
11:07:16 PM web.1  |      at extractPaths (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:117:29)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:84:20
11:07:16 PM web.1  |      at arrayReduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:669:21)
11:07:16 PM web.1  |      at reduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8123:14)
11:07:16 PM web.1  |      at extractPath (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:79:34)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:118:39
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:809:11
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4127:15
11:07:16 PM web.1  |      at baseForOwn (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2639:24)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4096:18
11:07:16 PM web.1  |      at baseReduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:806:5)
11:07:16 PM web.1  |      at reduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8096:14)
11:07:16 PM web.1  |      at extractPaths (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:117:29)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:84:20
11:07:16 PM web.1  |      at arrayReduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:669:21)
11:07:16 PM web.1  |      at reduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8123:14)
11:07:16 PM web.1  |      at extractPath (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:79:34)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:118:39
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:809:11
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4127:15
11:07:16 PM web.1  |      at baseForOwn (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:2639:24)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:4096:18
11:07:16 PM web.1  |      at baseReduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:806:5)
11:07:16 PM web.1  |      at reduce (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8096:14)
11:07:16 PM web.1  |      at extractPaths (/src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:117:29)
11:07:16 PM web.1  |      at /src/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:84:20
11:07:16 PM web.1  |      at arrayReduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:669:21)
11:07:16 PM web.1  |      at reduceRight (/src/node_modules/@risingstack/graffiti-mongoose/node_modules/lodash/lodash.js:8123:14)

Here is the diff of my package.json

-    "@risingstack/graffiti": "2.1.2",
-    "@risingstack/graffiti-mongoose": "4.3.3",
+    "@risingstack/graffiti": "3.0.2",
+    "@risingstack/graffiti-mongoose": "5.0.8",
-    "express-graphql": "0.4.5",
+    "express-graphql": "0.4.9",
-    "graphql": "0.4.14",
-    "graphql-relay": "0.3.5",
+    "graphql": "0.4.18",
-    "lodash": "3.10.1",
+    "lodash": "4.5.1",
     "mongoose": "4.3.4",

Any help would be awesome!
Thanks,
Jon

Confirmed this also happens when bumped to 5.0.

Thanks for the report. I will try to reproduce and fix this.

I've managed to reproduce the error, although I didn't have a solution just yet. :/

Not sure, cause this fix error with mutation objects, which use new introduced code toInputObject few commits ago.

But it can help, if your problem was with mutations. Just try on your project ;)