Use stripIgnoredCharacters when publishing from cli (#7712)

This commit is contained in:
jdolle 2026-02-20 09:50:15 -08:00 committed by GitHub
parent ceaa0e6942
commit a95deb7563
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 10 deletions

View file

@ -0,0 +1,7 @@
---
'@graphql-hive/cli': patch
---
Replace custom regex logic that stripped all spaces on publish. Use graphqljs' stripIgnoredCharacters
function instead. This maintains the useful spacing in multiline descriptions while stripping out other
unnecessary characters

View file

@ -1,13 +1,26 @@
directive @inline on FIELD_DEFINITION
"""
Multi line comment:
Multi line description:
1. Foo
2. Bar
3. Should stay in a list format
# with single line comment
"""
type Query { status: Status }
type Query {
# shows the status
# with comments on
# multiple lines
status: Status @inline value: Boolean @deprecated
}
# Another comment here
enum Status {
ACTIVE INACTIVE
PENDING
}
type User
extend type User { id: ID! # comment on same line
email: String }

View file

@ -1207,6 +1207,7 @@ export function fetchLatestSchema(token: string) {
deletedService
}
}
isValid
sdl
supergraph
schemas {

View file

@ -1103,7 +1103,7 @@ test.concurrent(
},
);
test.concurrent.skip('schema:publish ignores SDL formatting', async ({ expect }) => {
test.concurrent('schema:publish ignores SDL formatting', async ({ expect }) => {
const { createOrg } = await initSeed().createOwner();
const { inviteAndJoinMember, createProject, organization } = await createOrg();
await inviteAndJoinMember();
@ -1135,15 +1135,21 @@ test.concurrent.skip('schema:publish ignores SDL formatting', async ({ expect })
`);
const latest = await latestSchema();
expect(latest.latestVersion?.isValid).toBe(true);
expect(latest.latestVersion?.schemas.nodes?.[0]?.source).toMatchInlineSnapshot(`
directive @inline on FIELD_DEFINITION
"""
Multi line comment:
Multi line description:
1. Foo
2. Bar
3. Should stay in a list format
# with single line comment
"""
type Query {
status: Status
status: Status @inline
value: Boolean @deprecated
}
enum Status {
@ -1151,25 +1157,36 @@ test.concurrent.skip('schema:publish ignores SDL formatting', async ({ expect })
INACTIVE
PENDING
}
type User
extend type User {
id: ID!
email: String
}
`);
// API Schema maintains formatting
// API Schema maintains the multiline description's formatting
expect(latest.latestVersion?.sdl).toEqual(
expect.stringContaining(`"""
Multi line comment:
Multi line description:
1. Foo
2. Bar
3. Should stay in a list format
# with single line comment
"""`),
);
// Supergraph maintains formatting
expect(latest.latestVersion?.supergraph).toEqual(
expect.stringContaining(`"""
Multi line comment:
Multi line description:
1. Foo
2. Bar
3. Should stay in a list format
# with single line comment
"""`),
);
});

View file

@ -1,4 +1,4 @@
import { concatAST, print } from 'graphql';
import { concatAST, print, stripIgnoredCharacters } from 'graphql';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
@ -168,5 +168,5 @@ export async function loadSchema(
}
export function minifySchema(schema: string) {
return schema.replace(/\s+/g, ' ').trim();
return stripIgnoredCharacters(schema);
}