blob: 177dff07820edd88934aa316d4294b7c4f8d2479 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { omit } from '$lib/Utils';
import type { Client } from '@urql/svelte';
import * as gql from './graphql';
type Typename = '__typename';
type Identifiers = Typename | 'id';
export type OmitTypename<T> = Omit<T, Typename>;
export type OmitIdentifiers<T> = Omit<T, Identifiers>;
export type RequiredName<T> = T & { name: string };
export type MutationWith<T> = (
client: Client,
args: { ids: number[] | number; input: T }
) => Promise<unknown>;
export function omitIdentifiers<T extends { __typename?: unknown; id: number }>(
obj: T
): OmitIdentifiers<T> {
return omit(obj, '__typename', 'id');
}
export function isSuccess(object: any): object is gql.Success {
if (object.__typename === undefined) {
return false;
}
return object.__typename.endsWith('Success') && (object as gql.Success).message !== undefined;
}
export function isError(object: any): object is gql.Error {
if (object.__typename === undefined) {
return false;
}
return object.__typename.endsWith('Error') && (object as gql.Error).message !== undefined;
}
|