Skip to content

Commit 839b348

Browse files
authored
refactor: remove deprecated resolver code (#509)
1 parent 98fc627 commit 839b348

File tree

5 files changed

+8
-211
lines changed

5 files changed

+8
-211
lines changed

apps/api/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
"license": "MIT",
55
"scripts": {
66
"build": "tsc",
7-
"start": "node build/server.js",
8-
"dev": "ts-node-dev src/server.ts",
9-
"start:yjs": "node build/yjs-server.js",
10-
"dev:yjs": "ts-node-dev src/yjs-server.ts",
7+
"start": "node build/run.js",
8+
"dev": "ts-node-dev src/run.ts",
119
"test": "jest --config jest.config.js"
1210
},
1311
"dependencies": {

apps/api/src/resolver_repo.ts

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -123,78 +123,11 @@ async function repo(_, { id }, { userId }) {
123123
include: {
124124
owner: true,
125125
collaborators: true,
126-
pods: {
127-
include: {
128-
children: true,
129-
parent: true,
130-
},
131-
orderBy: {
132-
index: "asc",
133-
},
134-
},
135-
edges: true,
136126
},
137127
});
138128
if (!repo) throw Error("Repo not found");
139129
await updateUserRepoData({ userId, repoId: id });
140-
return {
141-
...repo,
142-
edges: repo.edges.map((edge) => ({
143-
source: edge.sourceId,
144-
target: edge.targetId,
145-
})),
146-
};
147-
}
148-
149-
async function addEdge(_, { source, target }, { userId }) {
150-
if (!userId) throw new Error("Not authenticated.");
151-
const sourcePod = await prisma.pod.findFirst({ where: { id: source } });
152-
const targetPod = await prisma.pod.findFirst({ where: { id: target } });
153-
if (!sourcePod || !targetPod) throw new Error("Pods not found.");
154-
if (sourcePod.repoId !== targetPod.repoId)
155-
throw new Error("Pods are not in the same repo.");
156-
await ensureRepoEditAccess({ repoId: sourcePod.repoId, userId });
157-
await prisma.edge.create({
158-
data: {
159-
source: {
160-
connect: {
161-
id: source,
162-
},
163-
},
164-
target: {
165-
connect: {
166-
id: target,
167-
},
168-
},
169-
repo: {
170-
connect: {
171-
id: sourcePod.repoId,
172-
},
173-
},
174-
},
175-
});
176-
return true;
177-
}
178-
179-
async function deleteEdge(_, { source, target }, { userId }) {
180-
if (!userId) throw new Error("Not authenticated.");
181-
const sourcePod = await prisma.pod.findFirst({ where: { id: source } });
182-
const targetPod = await prisma.pod.findFirst({ where: { id: target } });
183-
if (!sourcePod || !targetPod) throw new Error("Pods not found.");
184-
if (sourcePod.repoId !== targetPod.repoId)
185-
throw new Error("Pods are not in the same repo.");
186-
await ensureRepoEditAccess({ repoId: sourcePod.repoId, userId });
187-
await prisma.edge.deleteMany({
188-
where: {
189-
source: {
190-
id: source,
191-
},
192-
target: {
193-
id: target,
194-
},
195-
},
196-
});
197-
return true;
130+
return repo;
198131
}
199132

200133
async function createRepo(_, {}, { userId }) {
@@ -215,21 +148,6 @@ async function createRepo(_, {}, { userId }) {
215148
return repo;
216149
}
217150

218-
async function getVisibility(_, { repoId }, { userId }) {
219-
if (!userId) throw Error("Unauthenticated");
220-
const repo = await prisma.repo.findFirst({
221-
where: {
222-
id: repoId,
223-
owner: { id: userId || "undefined" },
224-
},
225-
include: {
226-
collaborators: true,
227-
},
228-
});
229-
if (!repo) throw Error("Repo not found");
230-
return { collaborators: repo.collaborators, isPublic: repo.public };
231-
}
232-
233151
async function updateVisibility(_, { repoId, isPublic }, { userId }) {
234152
if (!userId) throw Error("Unauthenticated");
235153
const repo = await prisma.repo.findFirst({
@@ -414,43 +332,6 @@ async function unstar(_, { repoId }, { userId }) {
414332
return true;
415333
}
416334

417-
async function updatePod(_, { id, repoId, input }, { userId }) {
418-
if (!userId) throw new Error("Not authenticated.");
419-
await ensureRepoEditAccess({ repoId, userId });
420-
// if repoId has id, just update
421-
let pod_found = await prisma.pod.findFirst({
422-
where: {
423-
id,
424-
repo: {
425-
id: repoId,
426-
},
427-
},
428-
});
429-
// or, return false and leave it dirty
430-
if (!pod_found) return false;
431-
const pod = await prisma.pod.update({
432-
where: {
433-
id,
434-
},
435-
data: {
436-
...input,
437-
parent: input.parent
438-
? input.parent === "ROOT"
439-
? { disconnect: true }
440-
: {
441-
connect: {
442-
id: input.parent,
443-
},
444-
}
445-
: undefined,
446-
children: {
447-
connect: input.children?.map((id) => ({ id })),
448-
},
449-
},
450-
});
451-
return true;
452-
}
453-
454335
async function copyRepo(_, { repoId }, { userId }) {
455336
// Find the repo
456337
const repo = await prisma.repo.findFirst({
@@ -525,9 +406,6 @@ export const RepoResolver = {
525406
updateRepo,
526407
deleteRepo,
527408
copyRepo,
528-
updatePod,
529-
addEdge,
530-
deleteEdge,
531409
addCollaborator,
532410
updateVisibility,
533411
deleteCollaborator,

apps/api/src/run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { startServer } from "./server";
2+
3+
startServer({ port: 4000 });

apps/api/src/server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ interface TokenInterface {
5050
id: string;
5151
}
5252

53-
async function startServer({ port }) {
53+
export async function startServer({ port }) {
5454
const apollo = new ApolloServer({
5555
typeDefs,
5656
resolvers,
@@ -86,5 +86,3 @@ async function startServer({ port }) {
8686
console.log(`🚀 Server ready at http://localhost:${port}`);
8787
});
8888
}
89-
90-
startServer({ port: 4000 });

apps/api/src/typedefs.ts

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ export const typeDefs = gql`
1212
password: String!
1313
firstname: String!
1414
lastname: String!
15-
codeiumAPIKey: String!
15+
codeiumAPIKey: String
1616
}
1717
1818
type Repo {
1919
id: ID!
2020
name: String
21-
pods: [Pod]
22-
edges: [Edge]
2321
userId: ID!
2422
stargazers: [User]
2523
collaborators: [User]
@@ -29,85 +27,13 @@ export const typeDefs = gql`
2927
accessedAt: String
3028
}
3129
32-
type Edge {
33-
source: String!
34-
target: String!
35-
}
36-
37-
type Pod {
38-
id: ID!
39-
type: String
40-
content: String
41-
githead: String
42-
staged: String
43-
column: Int
44-
lang: String
45-
parent: Pod
46-
index: Int
47-
children: [Pod]
48-
result: String
49-
stdout: String
50-
error: String
51-
imports: String
52-
exports: String
53-
reexports: String
54-
midports: String
55-
fold: Boolean
56-
thundar: Boolean
57-
utility: Boolean
58-
name: String
59-
x: Float
60-
y: Float
61-
width: Float
62-
height: Float
63-
}
64-
65-
input PodInput {
66-
id: ID!
67-
type: String
68-
content: String
69-
column: Int
70-
lang: String
71-
result: String
72-
stdout: String
73-
error: String
74-
imports: String
75-
exports: String
76-
reexports: String
77-
midports: String
78-
fold: Boolean
79-
thundar: Boolean
80-
utility: Boolean
81-
name: String
82-
x: Float
83-
y: Float
84-
width: Float
85-
height: Float
86-
parent: ID
87-
children: [ID]
88-
}
89-
90-
type RuntimeInfo {
91-
startedAt: String
92-
lastActive: String
93-
sessionId: String
94-
ttl: Int
95-
}
96-
97-
input RunSpecInput {
98-
code: String
99-
podId: String
100-
}
101-
10230
type Query {
10331
hello: String
10432
users: [User]
10533
me: User
10634
repos: [Repo]
10735
repo(id: String!): Repo
108-
pod(id: ID!): Pod
10936
getDashboardRepos: [Repo]
110-
activeSessions: [String]
11137
}
11238
11339
type Mutation {
@@ -124,12 +50,6 @@ export const typeDefs = gql`
12450
updateRepo(id: ID!, name: String!): Boolean
12551
deleteRepo(id: ID!): Boolean
12652
copyRepo(repoId: String!): ID!
127-
updatePod(id: String!, repoId: String!, input: PodInput): Boolean
128-
addEdge(source: ID!, target: ID!): Boolean
129-
deleteEdge(source: ID!, target: ID!): Boolean
130-
clearUser: Boolean
131-
clearRepo: Boolean
132-
clearPod: Boolean
13353
updateVisibility(repoId: String!, isPublic: Boolean!): Boolean
13454
addCollaborator(repoId: String!, email: String!): Boolean
13555
deleteCollaborator(repoId: String!, collaboratorId: String!): Boolean

0 commit comments

Comments
 (0)