Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useMutation): export MutationExecutionOptions interface #203

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

jbaubree
Copy link
Contributor

Just a simple export that is needed when we want to override some data or hooks.

Example:

import type { Client, CombinedError, MaybeRef, MutationApi, Operation, QueryExecutionContext } from 'villus'
import { useMutation as useMutationRequeset } from 'villus'
import { isNil, omitBy } from 'lodash-es'

// NEED THIS THAT IS NOT EXPORTED ------------------------------>
interface MutationExecutionOptions<TData> {
  context: MaybeRef<QueryExecutionContext>
  client?: Client
  clearCacheTags?: string[]
  refetchTags?: string[]
  onData?: (data: TData) => void
  onError?: (err: CombinedError) => void
}

export function useMutation<TData = any, TVars = any>(
  query: Operation<TData, TVars>['query'],
  // HERE ------------------------------>
  args: Partial<MutationExecutionOptions<TData>>): MutationApi<TData, TVars> {
  const { onData } = args

  return useMutationRequeset<TData, TVars>(unref(query), {
    ...args,
    onData: (data) => {
      // TO DO SOME EXAMPLE OF OVERRIDE THERE ------------------------------>
      if (typeof data === 'object' && !Object.keys(omitBy(data, isNil)).length)
        return
      onData?.(data)
    },
  })
}

@logaretm logaretm merged commit cb1f05f into logaretm:main Dec 16, 2023
4 of 5 checks passed
@logaretm
Copy link
Owner

Many thanks, and sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants