Skip to content

Commit 2b656de

Browse files
committed
Provide backward compatibility with useFlowReadOnlyTypes flag
1 parent 9a91128 commit 2b656de

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

packages/apollo-codegen-flow/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212

1313
import * as t from "@babel/types";
1414

15-
import { CompilerOptions } from "apollo-codegen-core/lib/compiler";
15+
import { FlowCompilerOptions } from "./language";
1616

1717
const builtInScalarMap = {
1818
[GraphQLString.name]: t.stringTypeAnnotation(),
@@ -23,7 +23,7 @@ const builtInScalarMap = {
2323
};
2424

2525
export function createTypeAnnotationFromGraphQLTypeFunction(
26-
compilerOptions: CompilerOptions
26+
compilerOptions: FlowCompilerOptions
2727
): Function {
2828
const arrayType = compilerOptions.useReadOnlyTypes
2929
? "$ReadOnlyArray"

packages/apollo-codegen-typescript/src/language.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ export type ObjectProperty = {
1616
type: t.TSType;
1717
};
1818

19-
export interface TypescriptCompilerOptions extends CompilerOptions {
20-
useReadOnlyTypes: boolean;
21-
}
22-
2319
export default class TypescriptGenerator {
24-
options: TypescriptCompilerOptions;
20+
options: CompilerOptions;
2521
typeFromGraphQLType: Function;
2622

27-
constructor(compilerOptions: TypescriptCompilerOptions) {
23+
constructor(compilerOptions: CompilerOptions) {
2824
this.options = compilerOptions;
2925

3026
this.typeFromGraphQLType = createTypeFromGraphQLTypeFunction(

packages/apollo/src/commands/client/__tests__/generate.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,24 @@ describe("client:codegen", () => {
337337
}
338338
);
339339

340+
test
341+
.fs({
342+
"schema.json": fullSchemaJsonString,
343+
"queryOne.graphql": simpleQuery.toString(),
344+
"my.config.js": defaultConfig
345+
})
346+
.command([
347+
"client:codegen",
348+
"--config=my.config.js",
349+
"--target=flow",
350+
"--outputFlat",
351+
"--useFlowReadOnlyTypes",
352+
"__tmp__API.js"
353+
])
354+
.it("writes read-only Flow types when the flag is set", () => {
355+
expect(fs.readFileSync("__tmp__API.js").toString()).toMatchSnapshot();
356+
});
357+
340358
test
341359
.fs({
342360
"schema.json": fullSchemaJsonString,

packages/apollo/src/commands/client/codegen.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export default class Generate extends ClientCommand {
7878
description: "Use Flow exact objects for generated types [flow only]"
7979
}),
8080

81+
useFlowReadOnlyTypes: flags.boolean({
82+
description:
83+
"Use read only types for generated types [flow only]. **Deprecated in favor of `useReadOnlyTypes`.**"
84+
}),
85+
8186
// flow / TS
8287
useReadOnlyTypes: flags.boolean({
8388
description: "Use read only types for generated types [flow | typescript]"
@@ -193,7 +198,8 @@ export default class Generate extends ClientCommand {
193198
mergeInFieldsFromFragmentSpreads:
194199
flags.mergeInFieldsFromFragmentSpreads,
195200
useFlowExactObjects: flags.useFlowExactObjects,
196-
useReadOnlyTypes: flags.useReadOnlyTypes,
201+
useReadOnlyTypes:
202+
flags.useReadOnlyTypes || flags.useFlowReadOnlyTypes,
197203
globalTypesFile: flags.globalTypesFile
198204
}
199205
);

0 commit comments

Comments
 (0)