From adcf26f957cd00550bf2b01bc55d47834c467b51 Mon Sep 17 00:00:00 2001 From: scottBowles Date: Tue, 12 Apr 2022 17:11:35 -0400 Subject: [PATCH] Allow custom fetch on mutations --- codegen/codegen.js | 3 ++- codegen/codegen.ts | 3 ++- docs/src/docs.md | 3 ++- example/src/lib/listing/Series.gq.ts | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/codegen/codegen.js b/codegen/codegen.js index 5b9db30..071c10e 100644 --- a/codegen/codegen.js +++ b/codegen/codegen.js @@ -27,6 +27,7 @@ export const plugin = (schema, documents, config) => { const defaultTypes = ` type SubscribeWrapperArgs = { variables?: T, + fetch?: typeof fetch; } interface CacheFunctionOptions { @@ -66,7 +67,7 @@ export async function get${pascalName}({ fetch, variables }: GGetParameters<${op // This is where the mutation code is generated // We're grabbing the mutation name and using it as a string in the generated code operations += ` -export const ${name} = ({ variables }: SubscribeWrapperArgs<${opv}>): +export const ${name} = ({ variables, fetch = window?.fetch }: SubscribeWrapperArgs<${opv}>): Promise> => g.fetch<${op}>({ queries: [{ query: ${pascalName}Doc, variables }], diff --git a/codegen/codegen.ts b/codegen/codegen.ts index 2f83c10..e63fc38 100644 --- a/codegen/codegen.ts +++ b/codegen/codegen.ts @@ -63,6 +63,7 @@ export const plugin: PluginFunction = ( const defaultTypes = ` type SubscribeWrapperArgs = { variables?: T, + fetch?: typeof fetch } interface CacheFunctionOptions { @@ -102,7 +103,7 @@ export async function get${pascalName}({ fetch, variables }: GGetParameters<${op // This is where the mutation code is generated // We're grabbing the mutation name and using it as a string in the generated code operations += ` -export const ${name} = ({ variables }: SubscribeWrapperArgs<${opv}>): +export const ${name} = ({ variables, fetch = window?.fetch }: SubscribeWrapperArgs<${opv}>): Promise> => g.fetch<${op}>({ queries: [{ query: ${pascalName}Doc, variables }], diff --git a/docs/src/docs.md b/docs/src/docs.md index d9f5702..787a4db 100644 --- a/docs/src/docs.md +++ b/docs/src/docs.md @@ -296,7 +296,8 @@ export async function getAdminTags( } export const deleteTag = ({ - variables + variables, + fetch = window?.fetch }: SubscribeWrapperArgs): Promise< GFetchReturnWithErrors > => diff --git a/example/src/lib/listing/Series.gq.ts b/example/src/lib/listing/Series.gq.ts index dd4be78..81c6298 100644 --- a/example/src/lib/listing/Series.gq.ts +++ b/example/src/lib/listing/Series.gq.ts @@ -18,6 +18,7 @@ type FetchWrapperArgs = { type SubscribeWrapperArgs = { variables?: T, + fetch?: typeof fetch, } interface CacheFunctionOptions {