GraphQL introspection returns type.name null if type.kind is NON_NULL or LIST

The type.name is null if type.kind is NON_NULL or LIST

Environment: https://graphql.eu.fauna.com

{
   "name": "history",
   "type": {
     "name": null,
     "kind": "NON_NULL"
   }
},
{
  "name": "treatments",
  "type": {
    "name": null,
    "kind": "LIST"
  }
}

I’m expecting that:

{
   "name": "history",
   "type": {
     "name": "TRP_History",
     "kind": "NON_NULL"
   }
},
{
  "name": "treatments",
  "type": {
    "name": "TRP_Treatments",
    "kind": "LIST"
  }
}

Introspection query:

{
  __schema {
    types {
      name
      kind
      fields {
        name
        type {
          name
          kind
        }
      }
      
    }
  }
}

This is expected behavior. You need to select ofType as well when it’s a NON_NULL type or LIST type. Check out more about introspection queries at graphql.org:

id looks a bit weird there, it has no name for the type. That’s because it’s a “wrapper” type of kind NON_NULL. If we queried for ofType on that field’s type, we would find the ID type there, telling us that this is a non-null ID.

Similarly, both friends and appearsIn have no name, since they are the LIST wrapper type. We can query for ofType on those types, which will tell us what these are lists of.

{
  __type(name: "Droid") {
    name
    fields {
      name
      type {
        name
        kind
        ofType {
          name
          kind
        }
      }
    }
  }
}

Indeed, helpful - Seems like I rushed before to fast through the introspection doc :see_no_evil: - because I missed that part completely. Thank you for pointing it out!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.