graphql-to-elm icon indicating copy to clipboard operation
graphql-to-elm copied to clipboard

How should we approach recursive input?

Open choonkeat opened this issue 3 years ago • 2 comments

given such a schema

schema {
  query: query
}

type query {
    string(node: Node): String
}

input Node {
    name: String
    child: Node
}

this works

query {
    string(node: { name: "" })
}

but this doesn't

query ($node: Node) {
    string(node: $node)
}
node prebuild.js
reading schema ./schema.graphql
processing schema
processing enums
processing query ./query.graphql
Error: processing query ./query.graphql
RangeError: Maximum call stack size exceeded
    at /Users/choonkeat/git/graphql-to-elm-try/node_modules/graphql-to-elm/lib/queries/queryIntel.js:30:15
    at async Promise.all (index 0)
make: *** [run] Error 1

the infinite loop is https://github.com/harmboschloo/graphql-to-elm/blob/d6a4e410cf7678309e8ce12dacb72b5e828ff985/src/gen/queries/queryIntel.ts#L262-L277

I tentatively added a cache and max depth limit of 10

      fields: Object.keys(fields).map(key => {
        let found = mapInputFieldCache[String(fields[key].type)]
        if (found) {
          return { ...found, name: fields[key].name }
        }
        return mapInputField(fields[key], schema, depth + 1)
      })
    };
  } else if (depth >= maxDepth) {
    value = {
      kind: "scalar",
      typeName: "jsonb"

fwiw, I'm using hasura and some inputs are akin to "sql where clauses" and is somehow recursive

choonkeat avatar Feb 23 '21 04:02 choonkeat