graphql / graphql/graphql-spec
Add ability to introspect types by kind
- Dominant language
- JavaScript
- Stars
- 14.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Right now the only way to get types from the schema are: `Query.__type`, `Schema.types`, `Schema.queryType`, etc.
It would be nice if you could filter `Schema.types` by `kind` - `ENUM`, `INTERFACE`, etc. For example, here are some of the types in the star wars schema on GraphQL.org:
```json
{
"data": {
"__schema": {
"types": [
{
"name": "Query",
"kind": "OBJECT"
},
{
"name": "Episode",
"kind": "ENUM"
},
{
"name": "Character",
"kind": "INTERFACE"
},
{
"name": "ID",
"kind": "SCALAR"
},
{
"name": "String",
"kind": "SCALAR"
},
```
Here's an example of a query I'd like to run:
```graphql
{ __schema { types(kind: "INTERFACE") { name } } }
```
As for a specific use case, I'd love to recommend this as the way to fill in data for Apollo Client's fragment matcher, which needs to know which fragments match on which selection sets - right now we ask people to query for all of the types and then filter down to just interfaces and unions manually: https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher
I'm not opinionated about the specific structure, but happy to open a PR to the spec if this sounds good!
Contributor guide
Assessment
This issue has not been assessed yet.