graphql / graphql/graphql-spec

Add ability to introspect types by kind

Open
#544 0 comments 0 reactions 0 assignees View on GitHub
💭 Strawman (RFC 0)
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.