Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeply nested list fails with "Uncaught RuntimeException: Reached the limit of nesting in type info" #36

Open
jausions opened this issue Nov 24, 2024 · 0 comments

Comments

@jausions
Copy link

jausions commented Nov 24, 2024

I had an issue with a schema that had a element of this type:

{
  "data": {
    "__type": {
      "name": "BsvhuMetadataFields",
      "kind": "OBJECT",
      "fields": [
        {
          "name": "sealed",
          "description": "Liste des champs scellés",
          "isDeprecated": false,
          "deprecationReason": null,
          "type": {
            "name": null,
            "kind": "NON_NULL",
            "description": null,
            "ofType": {
              "name": null,
              "kind": "LIST",
              "ofType": {
                "name": null,
                "kind": "NON_NULL",
                "ofType": {
                  "name": null,
                  "kind": "LIST",
                  "ofType": {
                    "name": null,
                    "kind": "NON_NULL",
                    "ofType": {
                      "name": "String",
                      "kind": "SCALAR",
                      "ofType": null
                    }
                  }
                }
              }
            }
          },
          "args": []
        }
      ]
    }
  }
}

The generator chocked on the issue with this error:

Fatal error: Uncaught RuntimeException: Reached the limit of nesting in type info in some/path/\vendor/gmostafa/php-graphql-oqm/src/SchemaGenerator/SchemaClassGenerator.php:333

Indeed, by adding more depth to the introspection sub-query \GraphQL\SchemaGenerator\SchemaInspector::TYPE_SUB_QUERY, I was able to unlock the problem:

{
    __type(name: "BsvhuMetadataFields") {
        name
        kind
        fields(includeDeprecated: true){
            name
            description
            isDeprecated
            deprecationReason
            type{
                name
                kind
                description
                ofType{
                    name
                    kind
                    ofType{
                        name
                        kind
                        ofType{
                            name
                            kind
                            ofType{
                                name
                                kind
                                ofType{
                                    name
                                    kind
                                    ofType{
                                        name
                                        kind
                                    }
                                }
                            }
                        }
                    }
                }
            }
            args{
                name
                description
                defaultValue
                type{
                    name
                    kind
                    description
                    ofType{
                        name
                        kind
                        ofType{
                            name
                            kind
                            ofType{
                                name
                                kind
                                ofType{
                                    name
                                    kind
                                    ofType{
                                        name
                                        kind
                                        ofType{
                                            name
                                            kind
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

But, this is hardly an solution. That solved my problem punctually and very temporarily.

No doubt, that someone will encounter a even more deeply nested type. So, the solution would be to try to go deeper whenever the ofType is not found, until we get the exact same answer from the server. If we get the same answer after trying to do deeper, then that's our cue that something is wrong with the schema, then naturally bail out of the generation process (as currently)

Alternatively, we could add an option to indicate how deep one wants to go.

I could try to code that into a PR, but I don't know when I'll be able to.

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

No branches or pull requests

1 participant