diff --git a/.changeset/afraid-pans-thank.md b/.changeset/afraid-pans-thank.md new file mode 100644 index 000000000..dc4f930fa --- /dev/null +++ b/.changeset/afraid-pans-thank.md @@ -0,0 +1,5 @@ +--- +'hive': patch +--- + +Fix for schema sdl resolver to ignore auto fix composite schema execution in case of monolith diff --git a/integration-tests/testkit/flow.ts b/integration-tests/testkit/flow.ts index 7727b5348..943e85491 100644 --- a/integration-tests/testkit/flow.ts +++ b/integration-tests/testkit/flow.ts @@ -1242,6 +1242,7 @@ export function fetchLatestValidSchema(token: string) { } } tags + sdl schemas { nodes { ... on SingleSchema { diff --git a/integration-tests/tests/api/schema/schema-version.spec.ts b/integration-tests/tests/api/schema/schema-version.spec.ts index 9e7033e40..410763d97 100644 --- a/integration-tests/tests/api/schema/schema-version.spec.ts +++ b/integration-tests/tests/api/schema/schema-version.spec.ts @@ -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); +}); diff --git a/packages/services/api/src/modules/schema/providers/schema-version-helper.ts b/packages/services/api/src/modules/schema/providers/schema-version-helper.ts index 8113045ba..bcf6bea08 100644 --- a/packages/services/api/src/modules/schema/providers/schema-version-helper.ts +++ b/packages/services/api/src/modules/schema/providers/schema-version-helper.ts @@ -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(version => version.id) async getCompositeSchemaAst(schemaVersion: SchemaVersion) { const compositeSchemaSdl = await this.getCompositeSchemaSdl(schemaVersion); + if (compositeSchemaSdl === null) { return null; } diff --git a/packages/web/app/src/pages/target-laboratory-new.tsx b/packages/web/app/src/pages/target-laboratory-new.tsx index e7dff27d8..afcafda62 100644 --- a/packages/web/app/src/pages/target-laboratory-new.tsx +++ b/packages/web/app/src/pages/target-laboratory-new.tsx @@ -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;