Skip to content

Commit 5f71c64

Browse files
committed
-
1 parent d9d914f commit 5f71c64

File tree

8 files changed

+3203
-0
lines changed

8 files changed

+3203
-0
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
import { QueryHookOptions, useQuery, LazyQueryHookOptions, useLazyQuery, MutationHookOptions, useMutation } from "@apollo/client";
2+
import { FetchResult } from "@apollo/client";
3+
import { ApolloClient } from "@apollo/client";
4+
import { FetchVehicleGraphFieldsByIdQuery } from "../";
5+
import { FetchVehicleGraphFieldsByIdQueryVariables } from "../";
6+
import { FetchVehicleGraphFieldsByIdDocument } from "../";
7+
import { FetchVehicleGraphFieldsQuery } from "../";
8+
import { FetchVehicleGraphFieldsDocument } from "../";
9+
import { FetchVehicleGraphFieldsQueryVariables } from "../";
10+
import { Vehicle_Insert_Input } from "../";
11+
import { Vehicle_On_Conflict } from "../";
12+
import { InsertVehicleGraphFieldsMutation } from "../";
13+
import { InsertVehicleGraphFieldsMutationVariables } from "../";
14+
import { InsertVehicleGraphFieldsDocument } from "../";
15+
import { Vehicle_Set_Input } from "../";
16+
import { UpdateVehicleGraphFieldsByIdMutation } from "../";
17+
import { UpdateVehicleGraphFieldsByIdMutationVariables } from "../";
18+
import { UpdateVehicleGraphFieldsByIdDocument } from "../";
19+
import { UpdateVehicleGraphFieldsMutation } from "../";
20+
import { UpdateVehicleGraphFieldsMutationVariables } from "../";
21+
import { UpdateVehicleGraphFieldsDocument } from "../";
22+
import { RemoveVehicleModelMutation } from "../";
23+
import { RemoveVehicleModelMutationVariables } from "../";
24+
import { RemoveVehicleModelDocument } from "../";
25+
import { RemoveVehicleModelByIdMutation } from "../";
26+
import { RemoveVehicleModelByIdMutationVariables } from "../";
27+
import { RemoveVehicleModelByIdDocument } from "../";
28+
29+
// vehicle React
30+
//------------------------------------------------
31+
32+
// Fetch Hooks
33+
//
34+
35+
/**
36+
* __useFetchVehicleGraphFieldsObjectByIdQuery__
37+
*
38+
* To run a query within a React component, call `useVehicleGraphFieldsObjectByIdQuery`
39+
* When your component renders, `useVehicleGraphFieldsObjectByIdQuery` returns an object from Apollo Client that contains loading, error, data properties, and a shortcut result property
40+
*
41+
* @param queryHookOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
42+
*
43+
* @example
44+
* const { result, loading, error } = useFetchVehicleGraphFieldsObjectByIdQuery({ vehicleId:<value> });
45+
*/
46+
47+
// Fetch Hook
48+
//
49+
export function useFetchVehicleGraphFieldsObjectByIdQuery({
50+
vehicleId,
51+
queryHookOptions
52+
}: {
53+
vehicleId: string;
54+
queryHookOptions?: Omit<QueryHookOptions<FetchVehicleGraphFieldsByIdQuery, FetchVehicleGraphFieldsByIdQueryVariables>, "query" | "variables">;
55+
}) {
56+
const query = useQuery<FetchVehicleGraphFieldsByIdQuery, FetchVehicleGraphFieldsByIdQueryVariables>(FetchVehicleGraphFieldsByIdDocument, {
57+
variables: { vehicleId },
58+
...queryHookOptions
59+
});
60+
return { ...query, returning: query && query.data && query.data.vehicle_by_pk };
61+
}
62+
63+
// Lazy Fetch Hook
64+
//
65+
export function useFetchVehicleObjectByIdLazyQuery({
66+
vehicleId,
67+
queryHookOptions
68+
}: {
69+
vehicleId: string;
70+
queryHookOptions?: Omit<LazyQueryHookOptions<FetchVehicleGraphFieldsByIdQuery, FetchVehicleGraphFieldsByIdQueryVariables>, "query" | "variables">;
71+
}) {
72+
const lazyQuery = useLazyQuery<FetchVehicleGraphFieldsByIdQuery, FetchVehicleGraphFieldsByIdQueryVariables>(FetchVehicleGraphFieldsByIdDocument, {
73+
variables: { vehicleId },
74+
...queryHookOptions
75+
});
76+
77+
return [lazyQuery[0], { ...lazyQuery[1], returning: lazyQuery[1] && lazyQuery[1].data && lazyQuery[1].data.vehicle_by_pk }];
78+
}
79+
80+
// Fetch Collection Hook
81+
//
82+
export function useFetchVehicleObjectsQuery({
83+
queryHookOptions
84+
}: {
85+
queryHookOptions: Omit<QueryHookOptions<FetchVehicleGraphFieldsQuery, FetchVehicleGraphFieldsQueryVariables>, "query">;
86+
}) {
87+
const query = useQuery<FetchVehicleGraphFieldsQuery, FetchVehicleGraphFieldsQueryVariables>(FetchVehicleGraphFieldsDocument, queryHookOptions);
88+
return { ...query, returning: query && query.data && query.data.vehicle };
89+
}
90+
91+
// Lazy Fetch Collection Hook
92+
//
93+
export function useFetchVehicleObjectsLazyQuery({
94+
queryHookOptions
95+
}: {
96+
queryHookOptions?: Omit<LazyQueryHookOptions<FetchVehicleGraphFieldsQuery, FetchVehicleGraphFieldsQueryVariables>, "query">;
97+
}) {
98+
const lazyQuery = useLazyQuery<FetchVehicleGraphFieldsQuery, FetchVehicleGraphFieldsQueryVariables>(FetchVehicleGraphFieldsDocument, queryHookOptions);
99+
100+
return [lazyQuery[0], { ...lazyQuery[1], returning: lazyQuery[1] && lazyQuery[1].data && lazyQuery[1].data.vehicle }];
101+
}
102+
103+
// Insert Hooks
104+
//
105+
106+
export async function useInsertVehicleGraphFieldsObject({
107+
vehicle,
108+
onConflict,
109+
mutationHookOptions
110+
}: {
111+
vehicle: Vehicle_Insert_Input;
112+
onConflict?: Vehicle_On_Conflict;
113+
mutationHookOptions?: Omit<MutationHookOptions<InsertVehicleGraphFieldsMutation, InsertVehicleGraphFieldsMutationVariables>, "mutation" | "variables">;
114+
}) {
115+
const lazyMutation = useMutation<InsertVehicleGraphFieldsMutation, InsertVehicleGraphFieldsMutationVariables>(InsertVehicleGraphFieldsDocument, {
116+
variables: { objects: [vehicle], onConflict },
117+
...mutationHookOptions
118+
});
119+
120+
return [
121+
lazyMutation[0],
122+
{
123+
...lazyMutation[1],
124+
returning:
125+
lazyMutation[1] &&
126+
lazyMutation[1].data &&
127+
lazyMutation[1].data.insert_vehicle &&
128+
lazyMutation[1].data.insert_vehicle!.returning &&
129+
lazyMutation[1].data.insert_vehicle!.returning[0]
130+
}
131+
];
132+
}
133+
134+
export async function insertVehicleGraphFieldsObjects({
135+
mutationHookOptions
136+
}: {
137+
mutationHookOptions: Omit<MutationHookOptions<InsertVehicleGraphFieldsMutation, InsertVehicleGraphFieldsMutationVariables>, "mutation">;
138+
}) {
139+
const lazyMutation = useMutation<InsertVehicleGraphFieldsMutation, InsertVehicleGraphFieldsMutationVariables>(InsertVehicleGraphFieldsDocument, { ...mutationHookOptions });
140+
141+
return [
142+
lazyMutation[0],
143+
{ ...lazyMutation[1], returning: lazyMutation[1] && lazyMutation[1].data && lazyMutation[1].data.insert_vehicle && lazyMutation[1].data.insert_vehicle!.returning }
144+
];
145+
}
146+
147+
// Update Hooks
148+
//
149+
150+
export async function updateVehicleGraphFieldsObjectById({
151+
vehicleId,
152+
set,
153+
mutationHookOptions
154+
}: {
155+
vehicleId: string;
156+
set: Vehicle_Set_Input;
157+
mutationHookOptions?: Omit<MutationHookOptions<UpdateVehicleGraphFieldsByIdMutation, UpdateVehicleGraphFieldsByIdMutationVariables>, "mutation">;
158+
}) {
159+
const lazyMutation = useMutation<UpdateVehicleGraphFieldsByIdMutation, UpdateVehicleGraphFieldsByIdMutationVariables>(UpdateVehicleGraphFieldsByIdDocument, {
160+
variables: { id: vehicleId, set },
161+
...mutationHookOptions
162+
});
163+
164+
return [
165+
lazyMutation[0],
166+
{
167+
...lazyMutation[1],
168+
returning:
169+
lazyMutation[1] &&
170+
lazyMutation[1].data &&
171+
lazyMutation[1].data.update_vehicle &&
172+
lazyMutation[1].data.update_vehicle!.returning &&
173+
lazyMutation[1].data.update_vehicle!.returning[0]
174+
}
175+
];
176+
}
177+
178+
export async function updateVehicleGraphFieldsObjects({
179+
apolloClient,
180+
mutationHookOptions
181+
}: {
182+
apolloClient: ApolloClient<object>;
183+
mutationHookOptions: Omit<MutationHookOptions<UpdateVehicleGraphFieldsMutation, UpdateVehicleGraphFieldsMutationVariables>, "mutation">;
184+
}) {
185+
const lazyMutation = useMutation<UpdateVehicleGraphFieldsMutation, UpdateVehicleGraphFieldsMutationVariables>(UpdateVehicleGraphFieldsDocument, { ...mutationHookOptions });
186+
187+
return [
188+
lazyMutation[0],
189+
{ ...lazyMutation[1], returning: lazyMutation[1] && lazyMutation[1].data && lazyMutation[1].data.update_vehicle && lazyMutation[1].data.update_vehicle!.returning }
190+
];
191+
}
192+
193+
// Delete Hooks
194+
//
195+
196+
export async function removeVehicleModelObjectById({
197+
vehicleId,
198+
mutationHookOptions
199+
}: {
200+
vehicleId: string;
201+
mutationHookOptions?: Omit<MutationHookOptions<RemoveVehicleModelByIdMutation, RemoveVehicleModelByIdMutationVariables>, "mutation">;
202+
}) {
203+
const lazyMutation = useMutation<RemoveVehicleModelByIdMutation, RemoveVehicleModelByIdMutationVariables>(RemoveVehicleModelByIdDocument, {
204+
variables: { id: vehicleId },
205+
...mutationHookOptions
206+
});
207+
208+
return [
209+
lazyMutation[0],
210+
{ ...lazyMutation[1], returning: lazyMutation[1] && lazyMutation[1].data && lazyMutation[1].data.delete_vehicle && lazyMutation[1].data.delete_vehicle!.affected_rows }
211+
];
212+
}
213+
214+
export async function removeVehicleModelObjects({
215+
mutationHookOptions
216+
}: {
217+
mutationHookOptions: Omit<MutationHookOptions<RemoveVehicleModelMutation, RemoveVehicleModelMutationVariables>, "mutation">;
218+
}) {
219+
const lazyMutation = useMutation<RemoveVehicleModelMutation, RemoveVehicleModelMutationVariables>(RemoveVehicleModelDocument, { ...mutationHookOptions });
220+
221+
return [
222+
lazyMutation[0],
223+
{ ...lazyMutation[1], returning: lazyMutation[1] && lazyMutation[1].data && lazyMutation[1].data.delete_vehicle && lazyMutation[1].data.delete_vehicle!.affected_rows }
224+
];
225+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
dist
4+
temp
5+
yarn-error.log
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# graphql-codegen-hasura-typescript-react-from-documents-documents-documents
2+
3+
## Summary
4+
5+
When used in conjunction with [graphql-code-generator](https://graphql-code-generator.com/), this plugin will automatically generate [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) TypeScript helper methods for every _Table_ defined in the Hasura database. Every scalar field in each table is included in the fragments.
6+
7+
graphql-codegen-hasura-typescript-react-from-documents-documents is a code generator plugin for [graphql-code-generator](https://graphql-code-generator.com/) designed to automate some coding tasks around the development of a strongly typed [Hasura](https://hasura.io/) backend with an [Apollo GraphQL](https://www.apollographql.com/) React client.
8+
9+
## Instructions
10+
11+
See the associated [graphql-codegen-hasura GitHub repo](https://github.com/ahrnee/graphql-codegen-hasura) for usage and configuration information.
12+
13+
## Motivation
14+
15+
[Hasura](https://hasura.io/) is a fantastic tool for the rapid development of a GraphQL backend. [Apollo GraphQL](https://www.apollographql.com/) is a suite of GraphQL tooling, including a great Client. [graphql-code-generator](https://graphql-code-generator.com/) is a fantastic code generation tool and library, to automate the generation of much of the boilerplate code required to use GraphQL. However, there still remained quite a bit of boiler plate code to be written.
16+
17+
The consistency and predictability of the Hasura](https://hasura.io/) GQL backend implementation, provided an opportunity to automate much of the remaining code for standard single-table mutations and queries, and multi-table helper code. This plugin is an attempt to do some of that.
18+
19+
## Disclaimers
20+
21+
This code was initially developed for use in a single separate commercial project. It is being shared in case useful to others, and as a contribution to the development community and the great GraphQL tools that already exist. The original implementation did just enough to meet the goals and needs of the initial project. There are many refinements and enhancements that would be beneficial - and contributions to that end are encouraged. See the associated [graphql-codegen-hasura GitHub repo](https://github.com/ahrnee/graphql-codegen-hasura) for additional information.
22+
23+
## Note
24+
25+
This is development is not affiliated with either the [graphql-code-generator](https://graphql-code-generator.com/) team, the [Hasura](https://hasura.io/) team, or the [Apollo GraphQL](https://www.apollographql.com/) team.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "graphql-codegen-hasura-typescript-react-from-documents",
3+
"version": "2.2.1",
4+
"description": "GraphQL Code Generator plugin for generating a CRUD TypeScript for Hasura from Documents",
5+
"author": "ahrnee <[email protected]>",
6+
"license": "MIT",
7+
"homepage": "https://github.com/ahrnee/graphql-codegen-hasura",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/ahrnee/graphql-codegen-hasura"
11+
},
12+
"scripts": {
13+
"build": "tsc --build --verbose",
14+
"rebuild": "tsc --build --force --verbose",
15+
"link": "yarn link"
16+
},
17+
"publishConfig": {
18+
"access": "public"
19+
},
20+
"peerDependencies": {
21+
"graphql-tag": "^2.0.0"
22+
},
23+
"devDependencies": {
24+
"@graphql-codegen/core": "^1.8.3",
25+
"@graphql-codegen/plugin-helpers": "1.8.3",
26+
"@graphql-codegen/typescript": "^1.8.3",
27+
"@graphql-codegen/visitor-plugin-common": "1.8.3",
28+
"graphql": "^14.5.8",
29+
"path": "^0.12.7",
30+
"react": "^16.12.0",
31+
"tslib": "1.10.0",
32+
"typescript": "3.7.2"
33+
},
34+
"sideEffects": false,
35+
"main": "dist/graphql-codegen-hasura-typescript-react-from-documents/src/index.js",
36+
"typings": "dist/graphql-codegen-hasura-typescript-react-from-documents/src/index.d.ts",
37+
"typescript": {
38+
"definition": "dist/graphql-codegen-hasura-typescript-react-from-documents/src/index.d.ts"
39+
},
40+
"files": [
41+
"README.md",
42+
"dist/**/*"
43+
],
44+
"gitHead": "41b2d8aab654a4f5722781e71d266200c273710e"
45+
}

0 commit comments

Comments
 (0)