Description
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.