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

Make type generic for mutation for onError function #167

Open
LFSCamargo opened this issue Mar 12, 2021 · 1 comment
Open

Make type generic for mutation for onError function #167

LFSCamargo opened this issue Mar 12, 2021 · 1 comment

Comments

@LFSCamargo
Copy link

The Problem

The return type for the server is different from the relay error type so i created the interface and a helper to handle errors and i got the error bellow i think a good solution would be to add the generic type to the useMutation hook

Behaviour

Screen Shot 2021-03-11 at 8 55 08 PM

How i thought to resolve this issue

export interface MutationConfig<TOperation extends MutationParameters, TError = Error> {
    configs?: DeclarativeMutationConfig[];
    cacheConfig?: CacheConfig;
    mutation: GraphQLTaggedNode;
    onError?: ((error: Error) => void) | null;
    onCompleted?:
        | ((response: TOperation['response'], errors: ReadonlyArray<PayloadError> | null | undefined) => void)
        | null;
    onUnsubscribe?: () => void | null | undefined;
    optimisticResponse?: TOperation['response'];
    optimisticUpdater?: SelectorStoreUpdater<TOperation['response']> | null;
    updater?: SelectorStoreUpdater<TOperation['response']> | null;
    uploadables?: UploadableMap | null;
    variables: TOperation['variables'];
}
@morrys
Copy link
Member

morrys commented Mar 15, 2021

Hi @LFSCamargo,
the behavior of useMutation is conditioned by the commitMutation of relay-runtime https://github.com/facebook/relay/blob/master/packages/relay-runtime/mutations/commitMutation.js#L65
It would be more correct to propose this in relay-runtime.

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

No branches or pull requests

2 participants