diff --git a/packages/plugins/typescript/react-apollo/src/index.ts b/packages/plugins/typescript/react-apollo/src/index.ts index faa9e4f0648..8ba13e90c2b 100644 --- a/packages/plugins/typescript/react-apollo/src/index.ts +++ b/packages/plugins/typescript/react-apollo/src/index.ts @@ -108,6 +108,25 @@ export interface ReactApolloRawPluginConfig extends RawClientSideBasePluginConfi * @default Component */ componentSuffix?: string; + /** + * @name reactApolloVersion + * @type 2 | 3 + * @description Customized the output by enabling/disabling the HOC. + * @default 2 + * + * @example + * ```yml + * generates: + * path/to/file.ts: + * plugins: + * - typescript + * - typescript-operations + * - typescript-react-apollo + * config: + * reactApolloVersion: 3 + * ``` + */ + reactApolloVersion?: 2 | 3; } export const plugin: PluginFunction = (schema: GraphQLSchema, documents: Types.DocumentFile[], config: ReactApolloRawPluginConfig) => { diff --git a/packages/plugins/typescript/react-apollo/src/visitor.ts b/packages/plugins/typescript/react-apollo/src/visitor.ts index 2e1cf4450bb..e51c6c4ffe8 100644 --- a/packages/plugins/typescript/react-apollo/src/visitor.ts +++ b/packages/plugins/typescript/react-apollo/src/visitor.ts @@ -13,6 +13,7 @@ export interface ReactApolloPluginConfig extends ClientSideBasePluginConfig { hooksImportFrom: string; reactApolloImportFrom: string; componentSuffix: string; + reactApolloVersion: 2 | 3; } export class ReactApolloVisitor extends ClientSideBaseVisitor { @@ -25,6 +26,7 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor;`; + return `export type ${this.convertName(node.name.value + 'MutationFn')} = ReactApollo.${MutationFnNameForVersionMap[this.config.reactApolloVersion]}<${operationResultType}, ${operationVariablesTypes}>;`; } return null; } @@ -142,3 +144,8 @@ export function use${operationName}(baseOptions?: ReactApolloHooks.${operationTy return [mutationFn, component, hoc, hooks].filter(a => a).join('\n'); } } + +const MutationFnNameForVersionMap = { + 2: 'MutationFn', + 3: 'MutationFunction', +};