dillonkearns/elm-graphql

non null list of non null list of…

atomkirk opened this issue · 6 comments

I've got my graphql types set up so that valid GeoJSON is generated on the backend (so that I can pass it straight to mapbox), which often has a lot of lists like this:

     {
         "type": "MultiPolygon",
         "coordinates": [
             [
                 [
                     [102.0, 2.0],
                     [103.0, 2.0],
                     [103.0, 3.0],
                     [102.0, 3.0],
                     [102.0, 2.0]
                 ]
             ],
             [
                 [
                     [100.0, 0.0],
                     [101.0, 0.0],
                     [101.0, 1.0],
                     [100.0, 1.0],
                     [100.0, 0.0]
                 ],
                 [
                     [100.2, 0.2],
                     [100.2, 0.8],
                     [100.8, 0.8],
                     [100.8, 0.2],
                     [100.2, 0.2]
                 ]
             ]
         ]
     }

It kind of looks like elm-graphql can't handle this. Does this error make sense to you?

> elm-graphql http://localhost:4000/v1/graphql --base App --scalar-codecs ScalarCodecs

Fetching GraphQL schema...
Generating files...
I couldn't understand the JSON for this schema. Here are some reasons this could fail:

- You may have provided a part of the introspection schema that is incomplete or invalid. Be sure you got it using the correct introspection query, or consider using another option like `elm-graphql --schema-file` if you want to use SDL syntax instead of JSON.
- Perhaps the schema is invalid (even well-established tools sometimes generate incorrect values)
- Or perhaps there's an issue with elm-graphql



Problem with the value at json['__schema'].types[70].fields[0]:

    {
        "args": [],
        "deprecationReason": null,
        "description": null,
        "isDeprecated": false,
        "name": "coordinates",
        "type": {
            "kind": "NON_NULL",
            "name": null,
            "ofType": {
                "kind": "LIST",
                "name": null,
                "ofType": {
                    "kind": "NON_NULL",
                    "name": null,
                    "ofType": {
                        "kind": "NON_NULL",
                        "name": null,
                        "ofType": {
                            "kind": "LIST",
                            "name": null,
                            "ofType": {
                                "kind": "NON_NULL",
                                "name": null,
                                "ofType": {
                                    "kind": "SCALAR",
                                    "name": "Float",
                                    "ofType": null
                                }
                            }
                        }
                    }
                }
            }
        }
    }

Can't have nested non-null types
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@1.0.0 schema: `elm-graphql http://localhost:4000/v1/graphql --base App --scalar-codecs ScalarCodecs`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@1.0.0 schema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/adamkirk/.npm/_logs/2021-07-06T13_33_55_813Z-debug.log

It looks like the GraphQL schema is returning an invalid response.

The GraphQL Spec describes it here https://spec.graphql.org/draft/#sec-The-__Type-Type.Non-Null

It says that for NON_NULL types:

  • kind must return __TypeKind.NON_NULL.
  • ofType must return a type of any kind except Non-Null.
  • All other fields must return null.

(Emphasis added to relevant section). So it looks like it's a bug with the library or server-side framework.

ahhhh

Kirk Screenshot 2021-07-06 at 10 17 45@2x

ok, I see it now. yep, the server lib shouldn't allow that

Looks like you have a list of nothing?

"ofType": {
   "kind": "LIST",
   "name": null
}
Kirk Screenshot 2021-07-06 at 10 17 45@2x

ok, I see it now. yep, the server lib shouldn't allow that

Right, yeah it's just an extra type wrapper that doesn't add any meaning, which is why the GraphQL Spec disallows it. Let me know what the root turns out to be and what you find, I'm curious whether it's from a user-defined double-non-null, or just the server framework (or a plugin) adding the double non-null.

the double non-null was my own code. But now that I've fixed that, I think the

"ofType": {
   "kind": "LIST",
   "name": null
}

is a bug in the server lib. if i remove the non_null decorators, it works

Gotcha, thanks for the info! It might be nice to improve the error message in this particular case, too. Something like:

I found a double non-null. This should probably be a single non-null, maybe check if your types have a redundant non-null somewhere? See https://spec.graphql.org/June2018/#sec-Type-Kinds.Non-Null