fix: chema sdl resolver to ignore auto fix composite schema execution… (#7614)

This commit is contained in:
Michael Skorokhodov 2026-02-03 13:44:10 +01:00 committed by GitHub
parent b344569706
commit e853916513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 59 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'hive': patch
---
Fix for schema sdl resolver to ignore auto fix composite schema execution in case of monolith

View file

@ -1242,6 +1242,7 @@ export function fetchLatestValidSchema(token: string) {
}
}
tags
sdl
schemas {
nodes {
... on SingleSchema {

View file

@ -67,3 +67,34 @@ test.concurrent(
expect(result.schemaVersionByCommit?.sdl).toIncludeSubstringWithoutWhitespace(latestSchema);
},
);
test.concurrent('valid monolith schema ignores the schema composition auto fix', async () => {
const { createOrg } = await initSeed().createOwner();
const { createProject } = await createOrg();
const { createTargetAccessToken } = await createProject(ProjectType.Single);
const token = await createTargetAccessToken({});
const sdl = /* GraphQL */ `
schema {
query: RootQueryType
}
type Link {
link: String
}
type RootQueryType {
foo: Link
}
`;
await token
.publishSchema({
sdl,
})
.then(r => r.expectNoGraphQLErrors());
const schema = await token.fetchLatestValidSchema();
expect(schema.latestValidVersion?.sdl).toMatchInlineSnapshot(sdl);
});

View file

@ -105,12 +105,17 @@ export class SchemaVersionHelper {
async getCompositeSchemaSdl(schemaVersion: SchemaVersion) {
if (schemaVersion.hasPersistedSchemaChanges) {
if (!schemaVersion.supergraphSDL) {
return schemaVersion.compositeSchemaSDL;
}
return schemaVersion.compositeSchemaSDL
? this.autoFixCompositeSchemaSdl(schemaVersion.compositeSchemaSDL, schemaVersion.id)
: null;
}
const composition = await this.composeSchemaVersion(schemaVersion);
if (composition === null) {
return null;
}
@ -134,6 +139,7 @@ export class SchemaVersionHelper {
@cache<SchemaVersion>(version => version.id)
async getCompositeSchemaAst(schemaVersion: SchemaVersion) {
const compositeSchemaSdl = await this.getCompositeSchemaSdl(schemaVersion);
if (compositeSchemaSdl === null) {
return null;
}

View file

@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo } from 'react';
import clsx from 'clsx';
import { buildSchema, introspectionFromSchema } from 'graphql';
import { throttle } from 'lodash';
import { toast } from 'sonner';
import { useMutation, useQuery } from 'urql';
import { Page, TargetLayout } from '@/components/layouts/target';
import { ConnectLabModal } from '@/components/target/laboratory/connect-lab-modal';
@ -605,10 +606,21 @@ function LaboratoryPageContent(props: {
});
const sdl = query.data?.target?.latestSchemaVersion?.sdl;
const introspection = useMemo(
() => (sdl ? introspectionFromSchema(buildSchema(sdl)) : null),
[sdl],
);
const introspection = useMemo(() => {
if (!sdl) {
return null;
}
try {
return introspectionFromSchema(buildSchema(sdl));
} catch (err) {
toast.error('Failed to fetch schema', {
description: err instanceof Error ? err.message : 'Unknown error',
});
return null;
}
}, [sdl]);
if (laboratoryState.fetching) {
return null;