Skip to content

Commit 43a5b6b

Browse files
committed
feat: update
1 parent 26cfbe2 commit 43a5b6b

File tree

7 files changed

+1063
-3882
lines changed

7 files changed

+1063
-3882
lines changed

package-lock.json

Lines changed: 993 additions & 3851 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,27 @@
3838
"@fastify/env": "^4.2.0",
3939
"@fastify/sensible": "^5.0.0",
4040
"@fastify/swagger": "^8.6.0",
41-
"@fastify/swagger-ui": "^1.9.0",
42-
"@fastify/type-provider-typebox": "^3.2.0",
41+
"@fastify/swagger-ui": "^2.0.0",
42+
"@fastify/type-provider-typebox": "^4.0.0",
4343
"@prisma/client": "^5.0.0",
4444
"dataloader": "^2.1.0",
4545
"fastify": "^4.0.0",
46-
"fastify-cli": "^5.5.1",
46+
"fastify-cli": "^6.0.0",
4747
"fastify-plugin": "^4.0.0",
4848
"graphql": "^16.6.0",
4949
"graphql-depth-limit": "^1.1.0",
5050
"graphql-parse-resolve-info": "^4.13.0"
5151
},
5252
"devDependencies": {
5353
"@types/graphql-depth-limit": "^1.1.3",
54-
"@types/node": "^18.0.0",
54+
"@types/node": "^20.0.0",
5555
"@types/tap": "^15.0.5",
56-
"@typescript-eslint/eslint-plugin": "^5.59.11",
57-
"@typescript-eslint/parser": "^5.59.11",
56+
"@typescript-eslint/eslint-plugin": "^6.0.0",
57+
"@typescript-eslint/parser": "^6.0.0",
5858
"concurrently": "^7.0.0",
5959
"eslint": "^8.43.0",
60-
"eslint-config-prettier": "^8.8.0",
61-
"fastify-tsconfig": "^1.0.1",
62-
"npm": "^9.8.0",
60+
"eslint-config-prettier": "^9.0.0",
61+
"fastify-tsconfig": "^2.0.0",
6362
"prettier": "^3.0.0",
6463
"prisma": "^5.0.0",
6564
"tap": "^16.1.0",

src/plugins/handle-http-error.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ export class HttpCompatibleError extends Error {
1212
}
1313

1414
export default fp(
15-
async (fastify) =>
15+
async (fastify) => {
1616
fastify.setErrorHandler((error) => {
1717
if (error instanceof HttpCompatibleError) {
1818
return fastify.httpErrors.getHttpError(error.httpCode, error.message);
1919
}
2020
return error;
21-
}),
21+
});
22+
},
2223
{
2324
dependencies: [sensiblePluginTag],
2425
},

test/routes/gql-loader.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getPrismaStats,
88
gqlQuery,
99
subscribeTo,
10+
unsubscribeFrom,
1011
} from '../utils/requests.js';
1112
import { MemberTypeId } from '../../src/routes/member-types/schemas.js';
1213

@@ -71,4 +72,41 @@ await test('gql-loader', async (t) => {
7172
t.ok(foundPostCall);
7273
t.ok(foundMemberTypeCall);
7374
});
75+
76+
await t.test('Dataloader should be created per request.', async (t) => {
77+
const { body: user1 } = await createUser(app);
78+
const { body: user2 } = await createUser(app);
79+
80+
await subscribeTo(app, user1.id, user2.id);
81+
82+
await gqlQuery(app, {
83+
query: `query {
84+
users {
85+
id
86+
userSubscribedTo {
87+
id
88+
}
89+
}
90+
}`,
91+
});
92+
93+
await unsubscribeFrom(app, user1.id, user2.id);
94+
95+
const {
96+
body: { data },
97+
} = await gqlQuery(app, {
98+
query: `query {
99+
users {
100+
id
101+
userSubscribedTo {
102+
id
103+
}
104+
}
105+
}`,
106+
});
107+
108+
const foundUser1 = data.users.find(({ id }) => id === user1.id);
109+
110+
t.ok(foundUser1.userSubscribedTo.length === 0);
111+
});
74112
});

test/routes/gql-queries.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ await test('gql-queries', async (t) => {
2222
await createPost(app, user1.id);
2323
await createProfile(app, user1.id, MemberTypeId.BASIC);
2424

25-
const [{ body: memberTypes }, { body: posts }, { body: users }, { body: profiles }] =
26-
await Promise.all([
27-
getMemberTypes(app),
28-
getPosts(app),
29-
getUsers(app),
30-
getProfiles(app),
31-
]);
25+
const { body: memberTypes } = await getMemberTypes(app);
26+
const { body: posts } = await getPosts(app);
27+
const { body: users } = await getUsers(app);
28+
const { body: profiles } = await getProfiles(app);
3229

3330
const {
3431
body: { data },
@@ -151,7 +148,7 @@ await test('gql-queries', async (t) => {
151148
const { body: profile1 } = await createProfile(app, user1.id, MemberTypeId.BASIC);
152149

153150
const {
154-
body: { data: dataUser, errors: errorsUser },
151+
body: { data: dataUser },
155152
} = await gqlQuery(app, {
156153
query: `query ($userId: UUID!) {
157154
user(id: $userId) {
@@ -172,7 +169,7 @@ await test('gql-queries', async (t) => {
172169
},
173170
});
174171
const {
175-
body: { data: dataUsers, errors: errorsUsers },
172+
body: { data: dataUsers },
176173
} = await gqlQuery(app, {
177174
query: `query {
178175
users {
@@ -190,8 +187,6 @@ await test('gql-queries', async (t) => {
190187
}`,
191188
});
192189

193-
t.ok(!errorsUser);
194-
t.ok(!errorsUsers);
195190
t.ok(dataUser.user.id === user1.id);
196191
t.ok(dataUser.user.profile.id === profile1.id);
197192
t.ok(dataUser.user.profile.memberType?.id === MemberTypeId.BASIC);
@@ -217,12 +212,14 @@ await test('gql-queries', async (t) => {
217212
id
218213
userSubscribedTo {
219214
id
215+
name
220216
subscribedToUser {
221217
id
222218
}
223219
}
224220
subscribedToUser {
225221
id
222+
name
226223
userSubscribedTo {
227224
id
228225
}
@@ -234,10 +231,12 @@ await test('gql-queries', async (t) => {
234231
},
235232
});
236233

237-
t.ok(data.user.id === user1.id);
238234
t.ok(data.user.userSubscribedTo[0].id === user2.id);
235+
t.ok(data.user.userSubscribedTo[0].name === user2.name);
239236
t.ok(data.user.userSubscribedTo[0].subscribedToUser[0].id === user1.id);
237+
240238
t.ok(data.user.subscribedToUser[0].id === user3.id);
239+
t.ok(data.user.subscribedToUser[0].name === user3.name);
241240
t.ok(data.user.subscribedToUser[0].userSubscribedTo[0].id === user1.id);
242241
});
243242
});

test/utils/requests.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,25 @@ export async function subscribeTo(
151151
return { res, body };
152152
}
153153

154-
export async function usedSubscribedTo(app: FastifyInstance, userId: string) {
154+
export async function subscribedToUser(app: FastifyInstance, userId: string) {
155155
const res = await app.inject({
156-
url: `/users/${userId}/user-subscribed-to`,
156+
url: `/users/${userId}/subscribed-to-user`,
157157
method: 'GET',
158158
});
159159
const body = (await res.json()) as UserBody[];
160160
return { res, body };
161161
}
162162

163-
export async function subscribedToUser(app: FastifyInstance, userId: string) {
163+
export async function unsubscribeFrom(
164+
app: FastifyInstance,
165+
userId: string,
166+
authorId: string,
167+
) {
164168
const res = await app.inject({
165-
url: `/users/${userId}/subscribed-to-user`,
166-
method: 'GET',
169+
url: `/users/${userId}/user-subscribed-to/${authorId}`,
170+
method: 'DELETE',
167171
});
168-
const body = (await res.json()) as UserBody[];
169-
return { res, body };
172+
return { res, body: {} };
170173
}
171174

172175
export async function getPrismaStats(app: FastifyInstance) {

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"noImplicitAny": false,
55
"noUnusedLocals": false,
6-
"target": "ES2022",
76
"outDir": "dist",
87
"sourceMap": true,
98
"moduleResolution": "nodenext",

0 commit comments

Comments
 (0)