Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/utilities/formatSdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ const sortSchema = (key, value, options: OptionsType) => {
sortArguments && key === 'arguments'
) {
return value.slice().sort((a, b) => {
if (a.kind === 'SchemaDefinition') {
const nonNamedKinds = ['SchemaDefinition', 'SchemaExtension'];
if (nonNamedKinds.includes(a.kind)) {
return -1;
}

if (b.kind === 'SchemaDefinition') {
if (nonNamedKinds.includes(b.kind)) {
return 1;
}

Expand Down
23 changes: 23 additions & 0 deletions test/format-graphql/utilities/formatSdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ test('does not strip description', (t) => {
t.is(formatSdl(input), expectedOutput);
});

test('supports schema extensions', (t) => {
const input = `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@shareable"])

type GenericResponse @shareable {
success: Boolean!
message: String
}
`;

const expectedOutput = `extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])

type GenericResponse @shareable {
message: String
success: Boolean!
}
`;

t.is(formatSdl(input), expectedOutput);
});

// @see https://github.com/graphql/graphql-js/issues/2241#issuecomment-546711570
// eslint-disable-next-line ava/no-skip-test
test.skip('does not strip comments', (t) => {
Expand Down