File tree Expand file tree Collapse file tree
apollo-codegen-typescript/src
apollo/src/commands/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
1212
1313import * as t from "@babel/types" ;
1414
15- import { CompilerOptions } from "apollo-codegen-core/lib/compiler " ;
15+ import { FlowCompilerOptions } from "./language " ;
1616
1717const builtInScalarMap = {
1818 [ GraphQLString . name ] : t . stringTypeAnnotation ( ) ,
@@ -23,7 +23,7 @@ const builtInScalarMap = {
2323} ;
2424
2525export function createTypeAnnotationFromGraphQLTypeFunction (
26- compilerOptions : CompilerOptions
26+ compilerOptions : FlowCompilerOptions
2727) : Function {
2828 const arrayType = compilerOptions . useReadOnlyTypes
2929 ? "$ReadOnlyArray"
Original file line number Diff line number Diff 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-
2319export 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 (
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments