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

feat: add all schema types in schema documentation #3077

Merged
merged 4 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-papayas-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

show all schema types in explorer
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export function SchemaDocumentation(props: SchemaDocumentationProps) {
const queryType = props.schema.getQueryType();
const mutationType = props.schema.getMutationType?.();
const subscriptionType = props.schema.getSubscriptionType?.();
const typeMap = props.schema.getTypeMap();
const ignoreTypesInAllSchema = [
queryType?.name,
mutationType?.name,
subscriptionType?.name,
];

return (
<>
Expand Down Expand Up @@ -49,6 +55,26 @@ export function SchemaDocumentation(props: SchemaDocumentationProps) {
</div>
)}
</ExplorerSection>
<ExplorerSection title="All Schema Types">
{typeMap && (
<div>
{Object.values(typeMap).map(type => {
if (
ignoreTypesInAllSchema.includes(type.name) ||
type.name.startsWith('__')
) {
return null;
}

return (
<div key={type.name}>
<TypeLink type={type} />
</div>
);
})}
</div>
)}
</ExplorerSection>
</>
);
}
4 changes: 3 additions & 1 deletion packages/graphiql-react/src/explorer/components/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type ExplorerSectionProps = {
| 'Possible Types'
| 'Enum Values'
| 'Deprecated Enum Values'
| 'Directives';
| 'Directives'
| 'All Schema Types';
};

export function ExplorerSection(props: ExplorerSectionProps) {
Expand Down Expand Up @@ -64,4 +65,5 @@ const TYPE_TO_ICON: Record<ExplorerSectionProps['title'], ComponentType> = {
'Possible Types': TypeIcon,
'Root Types': RootTypeIcon,
Type: TypeIcon,
'All Schema Types': TypeIcon,
};