Skip to content

Commit

Permalink
fix: view usage for enums and inputs (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin authored Nov 24, 2023
1 parent 6c823f6 commit 0d652b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions studio/src/components/analytics/field-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const FieldUsageSheet = () => {

const { range, dateRange } = useAnalyticsQueryState();
const isNamedType = searchParams.get("isNamedType") === "true";
const isEnum = searchParams.get("isEnum") === "true";
const showUsage = searchParams.get("showUsage");

const [type, field] = showUsage?.split(".") ?? [];
Expand All @@ -342,8 +343,8 @@ export const FieldUsageSheet = () => {

const { data, error, isLoading, refetch } = useQuery({
...getFieldUsage.useQuery({
field,
typename: isNamedType ? undefined : type,
field: isEnum ? undefined : field,
typename: isEnum ? field : isNamedType ? undefined : type,
namedType: isNamedType ? type : undefined,
graphName: graph?.graph?.name,
range: range,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ const Fields = (props: {
const hasDetails = props.fields.some(
(f) => !!f.description || !!f.deprecationReason,
);
const hasUsage = !(
["scalars", "enums", "inputs"] as GraphQLTypeCategory[]
).includes(props.category);
const hasUsage = !(["scalars"] as GraphQLTypeCategory[]).includes(
props.category,
);

const openUsage = (fieldName: string) => {
const query: Record<string, string> = {};
Expand All @@ -121,6 +121,11 @@ const Fields = (props: {
query.showUsage = `${router.query.typename || "Query"}.${fieldName}`;
}

if (props.category === "enums") {
query.isNamedType = "true";
query.isEnum = "true";
}

router.replace({
pathname: router.pathname,
query: {
Expand Down Expand Up @@ -312,7 +317,7 @@ const TypeWrapper = ({ ast }: { ast: GraphQLSchema }) => {

if (category && !typename) {
const list = getTypesByCategory(ast, category);
const hasUsage = category !== "inputs";
const hasUsage = true;

const openUsage = (type: string) => {
router.replace({
Expand Down

0 comments on commit 0d652b2

Please sign in to comment.