Skip to content

Commit

Permalink
Fix out-of-memory issue (#889)
Browse files Browse the repository at this point in the history
* Add v8 error: JavaScript heap out of memory error

* added unit test that passes

* changeset

* remove test

* cleanup

---------

Co-authored-by: Seppe Dekeyser <[email protected]>
  • Loading branch information
AlecAivazis and SeppahBaws authored Feb 3, 2023
1 parent 0ce14a5 commit fcba9f0
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-ghosts-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Fix out of memory error with nested recursive fragments
2 changes: 2 additions & 0 deletions e2e/sveltekit/src/routes/plugin/query/layout/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
<div id="result">
{$result.data?.user.name}
</div>

<slot />
135 changes: 135 additions & 0 deletions packages/houdini/src/codegen/generators/artifacts/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4068,3 +4068,138 @@ test('some artifactData added to artifact specific to plugins', async function (
"HoudiniHash=8e483259f3d69f416c01b6106c0440fa0f916abb4cadb75273f8226a1ff0a5e2";
`)
})

test('nested recursive fragments', async function () {
// the documents to test
const docs: Document[] = [
mockCollectedDoc(`
query MyAnimalQuery {
node(id: "some_id") {
id
...NodeDetails
... on User {
...UserThings
}
}
}
`),
mockCollectedDoc(`
fragment UserThings on User {
id
name
...NodeDetails
}
`),
mockCollectedDoc(`
fragment NodeDetails on Node {
id
... on User {
id
}
}
`),
]

// execute the generator
await runPipeline(config, docs)
expect(docs[0]).toMatchInlineSnapshot(`
export default {
"name": "MyAnimalQuery",
"kind": "HoudiniQuery",
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"raw": \`query MyAnimalQuery {
node(id: "some_id") {
id
...NodeDetails
... on User {
...UserThings
}
__typename
}
}
fragment NodeDetails on Node {
id
... on User {
id
}
}
fragment UserThings on User {
id
name
...NodeDetails
}
\`,
"rootType": "Query",
"selection": {
"fields": {
"node": {
"type": "Node",
"keyRaw": "node(id: \\"some_id\\")",
"nullable": true,
"selection": {
"fields": {
"id": {
"type": "ID",
"keyRaw": "id"
},
"__typename": {
"type": "String",
"keyRaw": "__typename"
}
},
"abstractFields": {
"fields": {
"User": {
"id": {
"type": "ID",
"keyRaw": "id"
},
"name": {
"type": "String",
"keyRaw": "name"
},
"__typename": {
"type": "String",
"keyRaw": "__typename"
}
}
},
"typeMap": {}
}
},
"abstract": true
}
}
},
"plugin_data": {
"plugin-tmp1": {
"added_stuff": {
"yop": "true"
}
}
},
"policy": "CacheOrNetwork",
"partial": false
};
"HoudiniHash=e9f7a1f9d6bc08c4b811af38914ba9311471ad1e31dc943c142b676c2f1c36c9";
`)
})
1 change: 0 additions & 1 deletion packages/houdini/src/codegen/generators/artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export default function artifactGenerator(stats: {
docs.map(async (doc) => {
// pull out the info we need from the collected doc
const { document, name, generateArtifact: generateArtifact } = doc

// if the document is generated, don't write it to disk - it's use is to provide definitions
// for the other transforms
if (!generateArtifact) {
Expand Down
10 changes: 8 additions & 2 deletions packages/houdini/src/codegen/utils/flattenSelections.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as graphql from 'graphql'
import type graphql from 'graphql'

import type { Config } from '../../lib'
import { HoudiniError } from '../../lib'
Expand Down Expand Up @@ -188,7 +188,13 @@ class FieldCollection {
}

// convert the selection to a real selection set
fragment.astNode.selectionSet.selections = fragment.selection.toSelectionSet()
fragment.astNode = {
...fragment.astNode,
selectionSet: {
...fragment.astNode.selectionSet,
selections: fragment.selection.toSelectionSet(),
},
}

// return the value
return [fragment.astNode]
Expand Down

0 comments on commit fcba9f0

Please sign in to comment.