mirror of
https://github.com/graphql-hive/console
synced 2026-05-22 16:48:56 +00:00
Co-authored-by: Mart Ganzevles <martganzevles@gmail.com> Co-authored-by: Mart Ganzevles <mart.ganzevles@klm.com>
This commit is contained in:
parent
a039245da8
commit
3fce7af292
1 changed files with 65 additions and 1 deletions
|
|
@ -23,9 +23,21 @@ const UnusedSchemaView_UnusedSchemaExplorerFragment = graphql(`
|
|||
__typename
|
||||
... on GraphQLObjectType {
|
||||
name
|
||||
fields {
|
||||
__typename
|
||||
args {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
... on GraphQLInterfaceType {
|
||||
name
|
||||
fields {
|
||||
__typename
|
||||
args {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
... on GraphQLUnionType {
|
||||
name
|
||||
|
|
@ -35,6 +47,9 @@ const UnusedSchemaView_UnusedSchemaExplorerFragment = graphql(`
|
|||
}
|
||||
... on GraphQLInputObjectType {
|
||||
name
|
||||
fields {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
... on GraphQLScalarType {
|
||||
name
|
||||
|
|
@ -70,7 +85,9 @@ const UnusedSchemaView = memo(function _UnusedSchemaView(props: {
|
|||
return grouped;
|
||||
}, [types]);
|
||||
|
||||
const letters = Array.from(typesGroupedByFirstLetter.keys()).sort();
|
||||
const letters = useMemo(() => {
|
||||
return Array.from(typesGroupedByFirstLetter.keys()).sort();
|
||||
}, [typesGroupedByFirstLetter]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedLetter) {
|
||||
|
|
@ -78,6 +95,38 @@ const UnusedSchemaView = memo(function _UnusedSchemaView(props: {
|
|||
}
|
||||
}, [selectedLetter, setSelectedLetter]);
|
||||
|
||||
const unused = useMemo(() => {
|
||||
const count = {
|
||||
fields: 0,
|
||||
fieldArguments: 0,
|
||||
types: 0,
|
||||
};
|
||||
|
||||
for (const type of types) {
|
||||
if (type.__typename === 'GraphQLInputObjectType') {
|
||||
count.types++;
|
||||
count.fields += type.fields.length;
|
||||
} else if (
|
||||
type.__typename === 'GraphQLObjectType' ||
|
||||
type.__typename === 'GraphQLInterfaceType'
|
||||
) {
|
||||
count.types++;
|
||||
|
||||
for (const field of type.fields) {
|
||||
if (field.args.length === 0) {
|
||||
// if there are no arguments, it means the entire field is unused
|
||||
count.fields++;
|
||||
} else {
|
||||
// if there are arguments, the field is used, but the arguments are not
|
||||
count.fieldArguments += field.args.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}, [types]);
|
||||
|
||||
if (types.length === 0) {
|
||||
return (
|
||||
<div className="flex h-[250px] shrink-0 items-center justify-center rounded-md border border-dashed">
|
||||
|
|
@ -97,8 +146,23 @@ const UnusedSchemaView = memo(function _UnusedSchemaView(props: {
|
|||
return null;
|
||||
}
|
||||
|
||||
const unusedFieldsMessage = [
|
||||
unused.fields ? `${unused.fields} unused fields` : null,
|
||||
unused.fieldArguments ? `${unused.fieldArguments} unused field arguments` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' and ');
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{unusedFieldsMessage.length ? (
|
||||
<div>
|
||||
<p className="text-sm text-gray-400">
|
||||
You have a total of {unusedFieldsMessage} within {unused.types} different types in the
|
||||
selected time period
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
<div>
|
||||
<TooltipProvider>
|
||||
{letters.map(letter => (
|
||||
|
|
|
|||
Loading…
Reference in a new issue