Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit e7bd8af

Browse files
committed
update projects list when we create a new project
1 parent 89e4d63 commit e7bd8af

File tree

5 files changed

+190
-43
lines changed

5 files changed

+190
-43
lines changed

management-api/schema.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type CreateProjectPayload {
3434
The created project
3535
"""
3636
project: Project!
37+
projectEdge: QueryProjectsConnectionEdge!
3738
}
3839

3940
"""

management-api/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const yoga = createYoga<Env>({
2323
const jwt = authorization.split(" ")[1];
2424

2525
let authUserId: string | null = null;
26+
2627
if (jwt) {
2728
const { payload } = await jwtVerify(
2829
jwt, // The raw Bearer Token extracted from the request header

management-api/src/schema/project.ts

+34-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { v4 as uuidv4 } from "uuid";
44
import { ProjectConfigurationSchema, SUPPORTED_CHAINS } from "utils";
55
import { and, asc, eq, gt, or, sql } from "drizzle-orm";
66
import { decodeGlobalID } from "@pothos/plugin-relay";
7+
import {
8+
InputShapeFromFields,
9+
InputFieldMap,
10+
MaybePromise,
11+
} from "@pothos/core";
12+
import { Context } from "context";
13+
import { GraphQLResolveInfo } from "graphql";
714

815
const Chain = builder.enumType("Chain", {
916
values: SUPPORTED_CHAINS,
@@ -129,13 +136,29 @@ builder.node(Project, {
129136
.where(sql`${project.id} IN (${ids})`),
130137
});
131138

132-
builder.queryField("projects", (t) => {
133-
return t.connection({
139+
const ProjectsEdge = builder.edgeObject({
140+
name: "QueryProjectsConnectionEdge",
141+
type: Project,
142+
});
143+
144+
const ProjectsConnection = builder.connectionObject(
145+
{
146+
name: "QueryProjectsConnection",
134147
type: Project,
148+
},
149+
ProjectsEdge,
150+
);
151+
152+
builder.queryField("projects", (t) => {
153+
return t.field({
154+
type: ProjectsConnection,
135155
description: "List of projects",
136156
authScopes: {
137157
isAuthenticated: true,
138158
},
159+
args: {
160+
...t.arg.connectionArgs(),
161+
},
139162
resolve: async (_parent, { first, after }, { db }) => {
140163
const limit = first ?? 10;
141164

@@ -338,6 +361,15 @@ builder.relayMutationField(
338361
description: "The created project",
339362
resolve: (res) => res,
340363
}),
364+
projectEdge: t.field({
365+
type: ProjectsEdge,
366+
resolve: (res) => {
367+
return {
368+
cursor: `${res.createdAt}__${res.id}`,
369+
node: res,
370+
};
371+
},
372+
}),
341373
}),
342374
},
343375
);

web/src/components/create/__generated__/createProjectMutation.graphql.ts

+132-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/components/create/index.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
DialogTitle,
2828
DialogTrigger,
2929
} from "../ui/dialog";
30-
import { graphql, useMutation } from "react-relay";
30+
import { ConnectionHandler, graphql, useMutation } from "react-relay";
3131
import { useForm } from "react-hook-form";
3232
import { z } from "zod";
3333
import { createProjectMutation } from "./__generated__/createProjectMutation.graphql";
@@ -75,6 +75,12 @@ export function CreateProject() {
7575
const [commit, isInFlight] = useMutation<createProjectMutation>(graphql`
7676
mutation createProjectMutation($input: CreateProjectInput!) {
7777
createProject(input: $input) {
78+
projectEdge {
79+
node {
80+
id
81+
...projects_ProjectCard
82+
}
83+
}
7884
project {
7985
id
8086
}
@@ -105,6 +111,21 @@ export function CreateProject() {
105111
// TODO: handle errors
106112
console.log("error", error);
107113
},
114+
updater(store) {
115+
const root = store.getRoot();
116+
117+
const payload = store.getRootField("createProject");
118+
const serverEdge = payload?.getLinkedRecord("projectEdge");
119+
if (!serverEdge) return;
120+
121+
const connection = ConnectionHandler.getConnection(
122+
root,
123+
"ProjectsGrid_projects",
124+
);
125+
if (!connection) return;
126+
127+
ConnectionHandler.insertEdgeAfter(connection, serverEdge);
128+
},
108129
onCompleted() {
109130
setIsOpened(false);
110131
form.reset();

0 commit comments

Comments
 (0)