@apollo/client#MutationTuple TypeScript Examples
The following examples show how to use
@apollo/client#MutationTuple.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Apollo.ts From graphql-ts-client with MIT License | 6 votes |
export function useTypedMutation<
TData extends object,
TVariables extends object,
TContext = DefaultContext,
TCache extends ApolloCache<any> = ApolloCache<any>
>(
fetcher: Fetcher<"Mutation", TData, TVariables>,
options?: MutationHookOptions<TData, TVariables, TContext> & {
readonly operationName?: string
}
): MutationTuple<
TData,
TVariables,
TContext,
TCache
> {
const body = requestBody(fetcher);
const request = useMemo<DocumentNode>(() => {
const operationName = options?.operationName ?? `mutation_${util.toMd5(body)}`;
return gql`mutation ${operationName}${body}`;
}, [body, options?.operationName]);
const response = useMutation<
TData,
TVariables,
TContext,
TCache
>(request, options);
const responseData = response[1].data;
const newResponseData = useMemo(() => util.exceptNullValues(responseData), [responseData]);
return newResponseData === responseData ? response : [
response[0],
{ ...response[1], data: newResponseData }
];
}
Example #2
Source File: useMutation.ts From lexicon with MIT License | 6 votes |
export function useMutation<TData, TVariables = OperationVariables>(
query: DocumentNode,
options?: MutationHookOptions<TData, TVariables>,
errorAlert: ErrorAlertOptionType = 'SHOW_ALERT',
): MutationTuple<TData, TVariables> {
const { navigate } = useNavigation<TabNavProp<'Home'>>();
const onErrorDefault = (error: ApolloError) => {
errorHandlerAlert(error, navigate);
};
const { ...others } = options ?? {};
const {
onError = errorAlert === 'SHOW_ALERT' ? onErrorDefault : undefined,
...otherOptions
} = others;
let [mutationFunction, mutationResult] = useMutationBase<TData, TVariables>(
query,
{
onError,
...otherOptions,
},
);
return [mutationFunction, mutationResult];
}
Example #3
Source File: form.create.mutation.ts From ui with GNU Affero General Public License v3.0 | 6 votes |
useFormCreateMutation = (
options: MutationHookOptions<Data, Variables> = {}
): MutationTuple<Data, Variables> => {
const oldUpdate = options.update
options.update = (cache, result, options) => {
cache.evict({
fieldName: 'listForms',
})
cache.gc()
if (oldUpdate) {
oldUpdate(cache, result, options)
}
}
return useMutation<Data, Variables>(MUTATION, options)
}
Example #4
Source File: form.delete.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useFormDeleteMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
Example #5
Source File: form.update.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useFormUpdateMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
Example #6
Source File: profile.update.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useProfileUpdateMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
Example #7
Source File: register.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useRegisterMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
Example #8
Source File: user.delete.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useUserDeleteMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)
Example #9
Source File: user.update.mutation.ts From ui with GNU Affero General Public License v3.0 | 5 votes |
useUserUpdateMutation = ( data?: MutationHookOptions<Data, Variables> ): MutationTuple<Data, Variables> => useMutation<Data, Variables>(MUTATION, data)