Skip to content

Commit a09fd68

Browse files
committed
feat: fetch suggested relationships from Hasura
1 parent 7981b51 commit a09fd68

File tree

2 files changed

+94
-280
lines changed

2 files changed

+94
-280
lines changed

scripts/hasura/src/configure-hasura.script.ts

Lines changed: 2 additions & 278 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { configDotenv } from "dotenv";
22
import { z } from "zod";
33

4-
import { CustomFunction, HasuraMetadataApi, RelationshipConfig } from "./internal.js";
4+
import { CustomFunction, HasuraMetadataApi } from "./internal.js";
55

66
configDotenv();
77

@@ -30,276 +30,6 @@ const tables = [
3030

3131
type Tables = typeof tables;
3232

33-
// Array relationships to track
34-
const arrayRelationships: RelationshipConfig<Tables>[] = [
35-
// Projects array relationships
36-
{
37-
name: "applications",
38-
table: {
39-
name: "projects",
40-
schema: "public",
41-
},
42-
using: {
43-
manual_configuration: {
44-
remote_table: {
45-
name: "applications",
46-
schema: "public",
47-
},
48-
source: "default",
49-
column_mapping: {
50-
id: "project_id",
51-
chain_id: "chain_id",
52-
},
53-
},
54-
},
55-
source: "default",
56-
},
57-
{
58-
name: "projectRoles",
59-
table: {
60-
name: "projects",
61-
schema: "public",
62-
},
63-
using: {
64-
manual_configuration: {
65-
remote_table: {
66-
name: "project_roles",
67-
schema: "public",
68-
},
69-
source: "default",
70-
column_mapping: {
71-
id: "project_id",
72-
chain_id: "chain_id",
73-
},
74-
},
75-
},
76-
source: "default",
77-
},
78-
{
79-
name: "rounds",
80-
table: {
81-
name: "projects",
82-
schema: "public",
83-
},
84-
using: {
85-
manual_configuration: {
86-
remote_table: {
87-
name: "rounds",
88-
schema: "public",
89-
},
90-
source: "default",
91-
column_mapping: {
92-
id: "project_id",
93-
chain_id: "chain_id",
94-
},
95-
},
96-
},
97-
source: "default",
98-
},
99-
// Rounds array relationships
100-
{
101-
name: "applications",
102-
table: {
103-
name: "rounds",
104-
schema: "public",
105-
},
106-
using: {
107-
manual_configuration: {
108-
remote_table: {
109-
name: "applications",
110-
schema: "public",
111-
},
112-
source: "default",
113-
column_mapping: {
114-
id: "round_id",
115-
chain_id: "chain_id",
116-
},
117-
},
118-
},
119-
source: "default",
120-
},
121-
{
122-
name: "roundRoles",
123-
table: {
124-
name: "rounds",
125-
schema: "public",
126-
},
127-
using: {
128-
manual_configuration: {
129-
remote_table: {
130-
name: "round_roles",
131-
schema: "public",
132-
},
133-
source: "default",
134-
column_mapping: {
135-
id: "round_id",
136-
chain_id: "chain_id",
137-
},
138-
},
139-
},
140-
source: "default",
141-
},
142-
// Applications array relationships
143-
{
144-
name: "applicationsPayouts",
145-
table: {
146-
name: "applications",
147-
schema: "public",
148-
},
149-
using: {
150-
manual_configuration: {
151-
remote_table: {
152-
name: "applications_payouts",
153-
schema: "public",
154-
},
155-
source: "default",
156-
column_mapping: {
157-
id: "application_id",
158-
chain_id: "chain_id",
159-
round_id: "round_id",
160-
},
161-
},
162-
},
163-
source: "default",
164-
},
165-
];
166-
167-
// Object relationships to track
168-
const objectRelationships: RelationshipConfig<Tables>[] = [
169-
// Project roles object relationships
170-
{
171-
name: "project",
172-
table: {
173-
name: "project_roles",
174-
schema: "public",
175-
},
176-
using: {
177-
manual_configuration: {
178-
remote_table: {
179-
name: "projects",
180-
schema: "public",
181-
},
182-
source: "default",
183-
column_mapping: {
184-
project_id: "id",
185-
chain_id: "chain_id",
186-
},
187-
},
188-
},
189-
source: "default",
190-
},
191-
// Rounds object relationships
192-
{
193-
name: "project",
194-
table: {
195-
name: "rounds",
196-
schema: "public",
197-
},
198-
using: {
199-
manual_configuration: {
200-
remote_table: {
201-
name: "projects",
202-
schema: "public",
203-
},
204-
source: "default",
205-
column_mapping: {
206-
project_id: "id",
207-
chain_id: "chain_id",
208-
},
209-
},
210-
},
211-
source: "default",
212-
},
213-
// Round roles object relationships
214-
{
215-
name: "round",
216-
table: {
217-
name: "round_roles",
218-
schema: "public",
219-
},
220-
using: {
221-
manual_configuration: {
222-
remote_table: {
223-
name: "rounds",
224-
schema: "public",
225-
},
226-
source: "default",
227-
column_mapping: {
228-
round_id: "id",
229-
chain_id: "chain_id",
230-
},
231-
},
232-
},
233-
source: "default",
234-
},
235-
// Applications object relationships
236-
{
237-
name: "project",
238-
table: {
239-
name: "applications",
240-
schema: "public",
241-
},
242-
using: {
243-
manual_configuration: {
244-
remote_table: {
245-
name: "projects",
246-
schema: "public",
247-
},
248-
source: "default",
249-
column_mapping: {
250-
project_id: "id",
251-
chain_id: "chain_id",
252-
},
253-
},
254-
},
255-
source: "default",
256-
},
257-
{
258-
name: "round",
259-
table: {
260-
name: "applications",
261-
schema: "public",
262-
},
263-
using: {
264-
manual_configuration: {
265-
remote_table: {
266-
name: "rounds",
267-
schema: "public",
268-
},
269-
source: "default",
270-
column_mapping: {
271-
round_id: "id",
272-
chain_id: "chain_id",
273-
},
274-
},
275-
},
276-
source: "default",
277-
},
278-
// Applications payouts object relationships
279-
{
280-
name: "application",
281-
table: {
282-
name: "applications_payouts",
283-
schema: "public",
284-
},
285-
using: {
286-
manual_configuration: {
287-
remote_table: {
288-
name: "applications",
289-
schema: "public",
290-
},
291-
source: "default",
292-
column_mapping: {
293-
application_id: "id",
294-
chain_id: "chain_id",
295-
round_id: "round_id",
296-
},
297-
},
298-
},
299-
source: "default",
300-
},
301-
];
302-
30333
// Custom functions to track
30434
const customFunctions: CustomFunction[] = [
30535
{
@@ -326,13 +56,7 @@ async function configureHasura(): Promise<void> {
32656
await hasuraApi.setSelectPermission(table);
32757
}
32858

329-
for (const relationship of arrayRelationships) {
330-
await hasuraApi.createArrayRelationship(relationship);
331-
}
332-
333-
for (const relationship of objectRelationships) {
334-
await hasuraApi.createObjectRelationship(relationship);
335-
}
59+
await hasuraApi.createSuggestedRelationships(Array.from(tables));
33660

33761
for (const func of customFunctions) {
33862
await hasuraApi.trackFunction(func);

0 commit comments

Comments
 (0)