Skip to content

Commit

Permalink
chore: remove commentDescriptions support
Browse files Browse the repository at this point in the history
For more informations, please refer to: graphql/graphql-js#2900
  • Loading branch information
GeoffreyHervet committed Nov 18, 2022
1 parent 035145b commit 2727ec4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
8 changes: 3 additions & 5 deletions src/utils/emitSchemaDefinitionFile.ts
@@ -1,14 +1,12 @@
import { GraphQLSchema, printSchema, lexicographicSortSchema } from "graphql";
import { Options as GraphQLPrintSchemaOptions } from "graphql/utilities/printSchema";
import { GraphQLSchema, printSchema, lexicographicSortSchema, buildClientSchema } from "graphql";

import { outputFile, outputFileSync } from "../helpers/filesystem";

export interface PrintSchemaOptions extends Required<GraphQLPrintSchemaOptions> {
export interface PrintSchemaOptions {
sortedSchema: boolean;
}

export const defaultPrintSchemaOptions: PrintSchemaOptions = {
commentDescriptions: false,
sortedSchema: true,
};

Expand Down Expand Up @@ -40,5 +38,5 @@ export async function emitSchemaDefinitionFile(

function getSchemaFileContent(schema: GraphQLSchema, options: PrintSchemaOptions) {
const schemaToEmit = options.sortedSchema ? lexicographicSortSchema(schema) : schema;
return generatedSchemaWarning + printSchema(schemaToEmit, options);
return generatedSchemaWarning + printSchema(schemaToEmit);
}
24 changes: 4 additions & 20 deletions tests/functional/emit-schema-sdl.ts
Expand Up @@ -56,7 +56,7 @@ describe("Emitting schema definition file", () => {

function checkSchemaSDL(
SDL: string,
{ commentDescriptions, sortedSchema }: PrintSchemaOptions = defaultPrintSchemaOptions,
{ sortedSchema }: PrintSchemaOptions = defaultPrintSchemaOptions,
) {
expect(SDL).toContain("THIS FILE WAS GENERATED");
expect(SDL).toContain("MyObject");
Expand All @@ -65,11 +65,7 @@ describe("Emitting schema definition file", () => {
} else {
expect(SDL.indexOf("descriptionProperty")).toBeGreaterThan(SDL.indexOf("normalProperty"));
}
if (commentDescriptions) {
expect(SDL).toContain(`# Description test`);
} else {
expect(SDL).toContain(`"""Description test"""`);
}
expect(SDL).toContain(`"""Description test"""`);
}

describe("emitSchemaDefinitionFile", () => {
Expand All @@ -83,7 +79,6 @@ describe("Emitting schema definition file", () => {
it("should use provided options to write file with schema SDL", async () => {
const targetPath = path.join(TEST_DIR, "schemas", "test1", "schema.gql");
const options: PrintSchemaOptions = {
commentDescriptions: true,
sortedSchema: false,
};
await emitSchemaDefinitionFile(targetPath, schema, options);
Expand Down Expand Up @@ -129,7 +124,6 @@ describe("Emitting schema definition file", () => {
it("should use provided options to write file with schema SDL", async () => {
const targetPath = path.join(TEST_DIR, "schemas", "test1", "schema.gql");
const options: PrintSchemaOptions = {
commentDescriptions: true,
sortedSchema: false,
};
emitSchemaDefinitionFileSync(targetPath, schema, options);
Expand Down Expand Up @@ -195,14 +189,12 @@ describe("Emitting schema definition file", () => {
await buildSchema({
resolvers: [MyResolverClass],
emitSchemaFile: {
commentDescriptions: true,
path: targetPath,
sortedSchema: false,
},
});
expect(fs.existsSync(targetPath)).toEqual(true);
checkSchemaSDL(fs.readFileSync(targetPath).toString(), {
commentDescriptions: true,
sortedSchema: false,
});
});
Expand All @@ -212,14 +204,11 @@ describe("Emitting schema definition file", () => {
const targetPath = path.join(process.cwd(), "schema.gql");
await buildSchema({
resolvers: [MyResolverClass],
emitSchemaFile: {
commentDescriptions: true,
},
emitSchemaFile: {},
});
expect(fs.existsSync(targetPath)).toEqual(true);
checkSchemaSDL(fs.readFileSync(targetPath).toString(), {
...defaultPrintSchemaOptions,
commentDescriptions: true,
});
});
});
Expand Down Expand Up @@ -251,14 +240,12 @@ describe("Emitting schema definition file", () => {
buildSchemaSync({
resolvers: [MyResolverClass],
emitSchemaFile: {
commentDescriptions: true,
path: targetPath,
sortedSchema: false,
},
});
expect(fs.existsSync(targetPath)).toEqual(true);
checkSchemaSDL(fs.readFileSync(targetPath).toString(), {
commentDescriptions: true,
sortedSchema: false,
});
});
Expand All @@ -268,14 +255,11 @@ describe("Emitting schema definition file", () => {
const targetPath = path.join(process.cwd(), "schema.gql");
buildSchemaSync({
resolvers: [MyResolverClass],
emitSchemaFile: {
commentDescriptions: true,
},
emitSchemaFile: {},
});
expect(fs.existsSync(targetPath)).toEqual(true);
checkSchemaSDL(fs.readFileSync(targetPath).toString(), {
...defaultPrintSchemaOptions,
commentDescriptions: true,
});
});
});
Expand Down

0 comments on commit 2727ec4

Please sign in to comment.