Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Maximum call stack size exceeded, possibly due to self-referencing type #44

Closed
mterrel opened this issue Apr 25, 2018 · 3 comments
Closed

Comments

@mterrel
Copy link

mterrel commented Apr 25, 2018

When I run relay-compiler while using this plugin to generate TypeScript output, I get the following output and error:

> relay-compiler --src ./frontend/src --schema mydb_schema.graphql --language typescript --artifactDirectory relay-generated

Watchman:  Watchman was not found in PATH.  See https://facebook.github.io/watchman/docs/install.html for installation instructions
HINT: pass --watch to keep watching for changes.

Writing ts
ERROR:
Error writing modules:
RangeError: Maximum call stack size exceeded
    at Object.createIdentifier (/src/node_modules/typescript/lib/typescript.js:48807:30)
    at transformGraphQLEnumType (/src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:55:42)
    at transformNonNullableInputType (/src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:79:16)
    at transformInputType (/src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:63:13)
    at /src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:89:30
    at Array.map (<anonymous>)
    at transformNonNullableInputType (/src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:86:14)
    at transformInputType (/src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:63:13)
    at /src/node_modules/relay-compiler-language-typescript/lib/TypeScriptTypeTransformers.js:89:30
    at Array.map (<anonymous>)

Although I haven't yet created a minimal repro of the issue, the crash is caused when I use a particular type as input parameter to a query. The query is:

const query = graphql`
    query DashboardRepoQuery($filter: DbRepoFilter) {
        allDbRepos(filter: $filter) {
            nodes {
                slug
            }
        }
    }
`;

And the DbRepoFilter type (which is auto-generated by Postgraphile) is:

input DbRepoFilter {
  """Filter by the object’s `slug` field."""
  slug: StringFilter

  """Filter by the object’s `content` field."""
  content: JSONFilter

  """Checks for all expressions in this list."""
  and: [DbRepoFilter!]

  """Checks for any expressions in this list."""
  or: [DbRepoFilter!]

  """Negates the expression."""
  not: DbRepoFilter
}

If this info isn't sufficient, let me know and I can try to create a simpler and more self-contained repro.

mterrel added a commit to mterrel/relay-compiler-language-typescript that referenced this issue Apr 26, 2018
Issue was caused by a GraphQL type that references itself: When
transforming input types, transformNonNullableInputType would
recursively expand each member field...infinitely.
Fix is to transform fields of objects that have a non-scalar type into a
reference to the type instead of an inline expansion of the type.
Then, we output the object types as a separate step, similar to how enum
types are done.
@mterrel
Copy link
Author

mterrel commented Apr 26, 2018

I just created a pull request that fixes the issue for me. I wasn't familiar enough with the structure of the current unit tests to easily add a new test case that specifically covers the self-referencing type issue described here. However, the existing snapshot unit tests do cover the new format of the output.

mterrel added a commit to mterrel/relay-compiler-language-typescript that referenced this issue Apr 26, 2018
Issue was caused by a GraphQL type that references itself: When
transforming input types, transformNonNullableInputType would
recursively expand each member field...infinitely.
Fix is to transform fields of objects that have a non-scalar type into a
reference to the type instead of an inline expansion of the type.
Then, we output the object types as a separate step, similar to how enum
types are done.
@waterfoul
Copy link

I've hit this one as well and can confirm it's a problem with self referencing types

@alloy
Copy link
Member

alloy commented Jul 30, 2018

Apologies for how long it took me to find the time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants