-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgraphql.ts
161 lines (131 loc) · 4.35 KB
/
graphql.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import gql from 'graphql-tag';
import * as Urql from 'urql';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
};
export type AddLocationResponse = Location | LocationExists;
export type AddTaskResponse = Task;
export type Location = {
__typename?: 'Location';
id: Scalars['ID'];
name: Scalars['String'];
};
export type LocationExists = {
__typename?: 'LocationExists';
message: Scalars['String'];
};
export type Mutation = {
__typename?: 'Mutation';
addLocation: AddLocationResponse;
addTask: AddTaskResponse;
};
export type MutationAddLocationArgs = {
name: Scalars['String'];
};
export type MutationAddTaskArgs = {
locationName?: Maybe<Scalars['String']>;
name: Scalars['String'];
};
export type Query = {
__typename?: 'Query';
locations: Array<Location>;
tasks: Array<Task>;
};
export type Task = {
__typename?: 'Task';
id: Scalars['ID'];
location?: Maybe<Location>;
name: Scalars['String'];
};
export type TasksQueryVariables = Exact<{ [key: string]: never; }>;
export type TasksQuery = { __typename?: 'Query', tasks: Array<{ __typename?: 'Task', id: string, name: string, location?: { __typename?: 'Location', name: string } | null | undefined }> };
export type LocationsQueryVariables = Exact<{ [key: string]: never; }>;
export type LocationsQuery = { __typename?: 'Query', locations: Array<{ __typename?: 'Location', id: string, name: string }> };
export type TaskFieldsFragment = { __typename?: 'Task', id: string, name: string, location?: { __typename?: 'Location', name: string } | null | undefined };
export type LocationFieldsFragment = { __typename?: 'Location', id: string, name: string };
export type AddTaskMutationVariables = Exact<{
name: Scalars['String'];
locationName: Scalars['String'];
}>;
export type AddTaskMutation = { __typename?: 'Mutation', addTask: { __typename: 'Task', id: string, name: string, location?: { __typename?: 'Location', name: string } | null | undefined } };
export type AddLocationMutationVariables = Exact<{
name: Scalars['String'];
}>;
export type AddLocationMutation = { __typename?: 'Mutation', addLocation: { __typename: 'Location', id: string, name: string } | { __typename: 'LocationExists', message: string } };
export const TaskFieldsFragmentDoc = gql`
fragment TaskFields on Task {
id
name
location {
name
}
}
`;
export const LocationFieldsFragmentDoc = gql`
fragment LocationFields on Location {
id
name
}
`;
export const TasksDocument = gql`
query Tasks {
tasks {
...TaskFields
}
}
${TaskFieldsFragmentDoc}`;
export function useTasksQuery(options: Omit<Urql.UseQueryArgs<TasksQueryVariables>, 'query'> = {}) {
return Urql.useQuery<TasksQuery>({ query: TasksDocument, ...options });
};
export const LocationsDocument = gql`
query Locations {
locations {
...LocationFields
}
}
${LocationFieldsFragmentDoc}`;
export function useLocationsQuery(options: Omit<Urql.UseQueryArgs<LocationsQueryVariables>, 'query'> = {}) {
return Urql.useQuery<LocationsQuery>({ query: LocationsDocument, ...options });
};
export const AddTaskDocument = gql`
mutation AddTask($name: String!, $locationName: String!) {
addTask(name: $name, locationName: $locationName) {
__typename
... on Task {
__typename
...TaskFields
}
}
}
${TaskFieldsFragmentDoc}`;
export function useAddTaskMutation() {
return Urql.useMutation<AddTaskMutation, AddTaskMutationVariables>(AddTaskDocument);
};
export const AddLocationDocument = gql`
mutation AddLocation($name: String!) {
addLocation(name: $name) {
__typename
... on LocationExists {
__typename
message
}
... on Location {
__typename
...LocationFields
}
}
}
${LocationFieldsFragmentDoc}`;
export function useAddLocationMutation() {
return Urql.useMutation<AddLocationMutation, AddLocationMutationVariables>(AddLocationDocument);
};