Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[graphiql] Display more types in <SchemaDocumentation /> #3000

Closed
hasparus opened this issue Jan 20, 2023 · 2 comments · Fixed by #3077
Closed

[graphiql] Display more types in <SchemaDocumentation /> #3000

hasparus opened this issue Jan 20, 2023 · 2 comments · Fixed by #3077

Comments

@hasparus
Copy link
Contributor

Hello 👋

Currently, SchemaDocumentation shows only the root types in the initial screen, and has a lot of screen real estate that could be used to show more types. That would bring the UI closer to the results of { __schema { types { name } } } query, so it's IMHO both a nice use of the empty space an pretty consistent.

I'm up for sending a PR if you feel it would be a worthwhile contribution. With TypeLink and schema.getTypeMap() the implementation seems be pretty straightforward.

Got a hacky implementation working with `pnpm patch`.
@@ -19643,6 +19634,9 @@ function SchemaDocumentation(props2) {
   const queryType = props2.schema.getQueryType();
   const mutationType = (_b = (_a = props2.schema).getMutationType) == null ? void 0 : _b.call(_a);
   const subscriptionType = (_d = (_c = props2.schema).getSubscriptionType) == null ? void 0 : _d.call(_c);
+  
+  const typeMap = props2.schema.getTypeMap && props2.schema.getTypeMap();
+  
   return /* @__PURE__ */ jsxs(Fragment, {
     children: [/* @__PURE__ */ jsx(MarkdownContent, {
       type: "description",
@@ -19671,6 +19665,29 @@ function SchemaDocumentation(props2) {
           type: subscriptionType
         })]
       })]
+    }), !typeMap ? null : jsxs(ExplorerSection, {
+      title: "Possible Types",
+      children: [
+        Object.values(typeMap).map(typeValue => {
+          const renderedKinds = [
+            "Interface",
+            "Object",
+          ].map(s => `GraphQL${s}Type`)
+
+          const ctorName = typeValue.constructor.name
+          const typeName = typeValue.name;
+
+          const ignoredTypes = ['Query', 'Subscription'];
+
+          if (renderedKinds.includes(ctorName) && !ignoredTypes.includes(typeName) && typeName[0] !== '_') {
+            return jsxs("div", {
+              children: [jsx(TypeLink, { type: typeValue })],
+            })
+          }
+
+          return null;
+        })   
+      ]
     })]
   });
 }
@@ -19811,7 +19828,6 @@ function fillInChunks(_ref4) {
       });
     }
   }
 }
Screen.Recording.2023-01-20.at.18.56.03.mov

As alternatives, I've considered disabling the Documentation Explorer plugin and swapping it with my own version, and mutating DOC_EXPLORER_PLUGIN export like a bandit, but I feel like it would be nice to have this feature in all GraphiQLs, not only in mine :)

@dimaMachina
Copy link
Collaborator

Sorry for the late response, I like this idea, let's wait for thoughts for the team cc @acao @jonathanawesome @thomasheyenbrock

@acao
Copy link
Member

acao commented Feb 7, 2023

@hasparus I really like this idea! we could also label it 'all schema types'

noting that some schemas include a lengthy markdown in the Schema.description, so perhaps we can make it disable-able via a plugin setting, but I like the idea of enabling this feature by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants