Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Allow custom fetch on mutations (small PR) #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codegen/codegen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion codegen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const plugin: PluginFunction<any> = (
const defaultTypes = `
type SubscribeWrapperArgs<T> = {
variables?: T,
fetch?: typeof fetch
}

interface CacheFunctionOptions {
Expand Down Expand Up @@ -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<GFetchReturnWithErrors<${op}>> =>
g.fetch<${op}>({
queries: [{ query: ${pascalName}Doc, variables }],
Expand Down
3 changes: 2 additions & 1 deletion docs/src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ export async function getAdminTags(
}

export const deleteTag = ({
variables
variables,
fetch = window?.fetch
}: SubscribeWrapperArgs<DeleteTagMutationVariables>): Promise<
GFetchReturnWithErrors<DeleteTagMutation>
> =>
Expand Down
1 change: 1 addition & 0 deletions example/src/lib/listing/Series.gq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type FetchWrapperArgs<T> = {

type SubscribeWrapperArgs<T> = {
variables?: T,
fetch?: typeof fetch,
}

interface CacheFunctionOptions {
Expand Down