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

Add a way to view subgraph metadata on target schemas page #6350

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export class SchemaManager {
@atomic(stringifySelector)
async getMaybeSchemasOfVersion(schemaVersion: SchemaVersion) {
this.logger.debug('Fetching schemas (schemaVersionId=%s)', schemaVersion.id);
return this.storage.getSchemasOfVersion({ versionId: schemaVersion.id });
// !note: The decorators are doing something to prevent passing in an additional boolean for "includeMetadata"...
// so for now always include metadata
return this.storage.getSchemasOfVersion({ versionId: schemaVersion.id, includeMetadata: true });
Copy link
Collaborator Author

@jdolle jdolle Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with atomic but if I added an additional includeMetadata boolean argument to the getMaybeSchemasOfVersion, it would always be undefined. So I assume the decorator is messing with the function definition.

And I'm not sure why the metadata was excluded initially from some calls. I assume the push was for fetching metadata from the CDN and therefore it may have been removed from the schema? Any additional context anyone has on this would help.

}

async getMatchingServiceSchemaOfVersions(versions: { before: string | null; after: string }) {
Expand Down
2 changes: 1 addition & 1 deletion packages/services/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ export async function createStorage(

return transformSchema(result);
},
async getSchemasOfVersion({ versionId: version, includeMetadata = false }) {
async getSchemasOfVersion({ versionId: version, includeMetadata }) {
const result = await pool.query<
Pick<
OverrideProp<schema_log, 'action', 'PUSH'>,
Expand Down
38 changes: 33 additions & 5 deletions packages/web/app/src/pages/target.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ function SchemaBlock({ schema }: { schema: CompositeSchema }) {
return (
<Accordion.Item value={schema.id} key={schema.id} className="border-2 border-gray-900/50">
<Accordion.Header>
<div>
<div className="text-base" id={schema.service ? `service-${schema.service}` : undefined}>
{schema.service ?? 'SDL'}
</div>
{schema.url ? <div className="text-xs text-gray-500">{schema.url}</div> : null}
<div className="text-base" id={schema.service ? `service-${schema.service}` : undefined}>
{schema.service ?? 'SDL'}
</div>
{schema.url ? <div className="text-xs text-gray-500">{schema.url}</div> : null}
</Accordion.Header>
<Accordion.Content>
<div className="p-2">
{schema.metadata ? <SchemaMetadata metadata={JSON.stringify(JSON.parse(schema.metadata), undefined, 2)} /> : null}
<GraphQLHighlight code={schema.source} />
</div>
</Accordion.Content>
Expand Down Expand Up @@ -129,9 +128,11 @@ const SchemaView_SchemaFragment = graphql(`
... on SingleSchema {
id
source
metadata @include(if: $includeMetadata)
}
... on CompositeSchema {
id
metadata @include(if: $includeMetadata)
source
service
url
Expand All @@ -155,6 +156,28 @@ const SchemaView_TargetFragment = graphql(`
}
`);

function SchemaMetadata(props: { metadata: string }): ReactElement | null {
return (
<Popover>
<PopoverTrigger asChild onClick={event => event.stopPropagation()}>
<Button variant="secondary" role="button" size="sm">
metadata
</Button>
</PopoverTrigger>
<PopoverContent
className="w-[400px] truncate p-0"
onClick={event => event.stopPropagation()}
side="right"
align="start"
>
<ScrollArea className="relative p-2">
<pre>{props.metadata}</pre>
</ScrollArea>
</PopoverContent>
</Popover>
);
}

function SchemaView(props: {
organization: FragmentType<typeof SchemaView_OrganizationFragment>;
project: FragmentType<typeof SchemaView_ProjectFragment>;
Expand Down Expand Up @@ -265,6 +288,7 @@ const TargetSchemaPageQuery = graphql(`
$organizationSlug: String!
$projectSlug: String!
$targetSlug: String!
$includeMetadata: Boolean = false
) {
organization(selector: { organizationSlug: $organizationSlug }) {
organization {
Expand All @@ -290,13 +314,15 @@ function TargetSchemaPage(props: {
organizationSlug: string;
projectSlug: string;
targetSlug: string;
includeMetadata?: boolean;
}) {
const [query] = useQuery({
query: TargetSchemaPageQuery,
variables: {
organizationSlug: props.organizationSlug,
projectSlug: props.projectSlug,
targetSlug: props.targetSlug,
includeMetadata: props.includeMetadata,
},
});

Expand Down Expand Up @@ -361,6 +387,7 @@ export function TargetPage(props: {
organizationSlug: string;
projectSlug: string;
targetSlug: string;
includeMetadata?: boolean;
}) {
return (
<>
Expand All @@ -369,6 +396,7 @@ export function TargetPage(props: {
organizationSlug={props.organizationSlug}
projectSlug={props.projectSlug}
targetSlug={props.targetSlug}
includeMetadata={props.includeMetadata}
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions packages/web/app/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ const targetIndexRoute = createRoute({
organizationSlug={organizationSlug}
projectSlug={projectSlug}
targetSlug={targetSlug}
includeMetadata
/>
);
},
Expand Down
Loading