Skip to content

Commit e4ef68d

Browse files
committed
Fix GraphQL
1 parent debfb53 commit e4ef68d

File tree

5 files changed

+42
-54
lines changed

5 files changed

+42
-54
lines changed
Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,42 @@
1-
import { RequestHandler, Router } from "express";
2-
import { graphqlHTTP } from "express-graphql";
1+
import { Router } from "express";
2+
import { createHandler } from "graphql-http/lib/use/express";
33

4-
import DEFAULT_QUERY from "./defaultQuery";
4+
// import DEFAULT_QUERY from "./defaultQuery";
55
import { getSchema } from "./schema";
66

77
/** @gqlContext */
88
export type Ctx = Express.Request;
99

1010
const router = Router();
1111

12-
function getQueryNameFromDocument(document) {
13-
const operationDefinition = document.definitions.find(
14-
(def) => def.kind === "OperationDefinition"
15-
);
16-
if (!operationDefinition) {
17-
return null;
18-
}
19-
return operationDefinition.name?.value;
20-
}
21-
22-
const extensions = ({
23-
variables,
24-
operationName,
25-
context: req,
26-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
27-
document,
28-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29-
result,
30-
}) => {
31-
const runTime = Date.now() - req.startTime;
32-
const vars = JSON.stringify(variables);
33-
const queryName = operationName ?? getQueryNameFromDocument(document);
34-
// TODO: Log/notify on error.
35-
req.log(
36-
`Handled GraphQL Query: "${queryName}" with variables ${vars} in ${runTime}ms`
37-
);
38-
return { runTime };
39-
};
40-
4112
router.use(
4213
"/",
43-
graphqlHTTP({
14+
createHandler<Ctx>({
4415
schema: getSchema(),
16+
context: (req) => {
17+
return req.raw;
18+
},
19+
/*
4520
graphiql: {
4621
defaultQuery: DEFAULT_QUERY,
47-
},
48-
customFormatErrorFn: (error) => {
49-
console.error(error);
50-
return {
51-
message: error.message,
52-
locations: error.locations,
53-
stack: error.stack ? error.stack.split("\n") : [],
54-
path: error.path,
55-
};
56-
},
57-
extensions,
58-
}) as RequestHandler
22+
},*/
23+
// graphqlHTTP({
24+
// schema: getSchema(),
25+
// graphiql: {
26+
// defaultQuery: DEFAULT_QUERY,
27+
// },
28+
// customFormatErrorFn: (error) => {
29+
// console.error(error);
30+
// return {
31+
// message: error.message,
32+
// locations: error.locations,
33+
// stack: error.stack ? error.stack.split("\n") : [],
34+
// path: error.path,
35+
// };
36+
// },
37+
// extensions,
38+
// }) as RequestHandler
39+
})
5940
);
6041

6142
export default router;

packages/skin-database/api/graphql/resolvers/ReviewMutations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function mark_skin_nsfw(
7575
}
7676

7777
const _mark_skin_nsfw = requireAuthed(async (md5: string, req: Ctx) => {
78-
req.log(`Approving skin with hash "${md5}"`);
78+
req.log(`Marking skin with hash "${md5}" NSFW`);
7979
const skin = await SkinModel.fromMd5(req.ctx, md5);
8080
if (skin == null) {
8181
return false;

packages/skin-database/api/graphql/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ export function getSchema(): GraphQLSchema {
10991099
}
11001100
},
11011101
resolve(source, args, context) {
1102-
return assertNonNull(mutationApprove_skinResolver(source, args, context));
1102+
return assertNonNull(mutationApprove_skinResolver(source, args.md5, context));
11031103
}
11041104
},
11051105
mark_skin_nsfw: {
@@ -1113,7 +1113,7 @@ export function getSchema(): GraphQLSchema {
11131113
}
11141114
},
11151115
resolve(source, args, context) {
1116-
return assertNonNull(mutationMark_skin_nsfwResolver(source, args, context));
1116+
return assertNonNull(mutationMark_skin_nsfwResolver(source, args.md5, context));
11171117
}
11181118
},
11191119
reject_skin: {
@@ -1127,7 +1127,7 @@ export function getSchema(): GraphQLSchema {
11271127
}
11281128
},
11291129
resolve(source, args, context) {
1130-
return assertNonNull(mutationReject_skinResolver(source, args, context));
1130+
return assertNonNull(mutationReject_skinResolver(source, args.md5, context));
11311131
}
11321132
},
11331133
request_nsfw_review_for_skin: {

packages/skin-database/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"express-sitemap-xml": "^2.0.0",
2323
"fast-xml-parser": "^4.2.2",
2424
"graphql": "^16.8.1",
25-
"grats": "^0.0.28",
25+
"graphql-http": "^1.22.1",
26+
"grats": "^0.0.29",
2627
"imagemin": "^7.0.0",
2728
"imagemin-optipng": "^7.0.0",
2829
"knex": "^0.21.1",

yarn.lock

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14846,6 +14846,11 @@ graphql-depth-limit@^1.1.0:
1484614846
dependencies:
1484714847
arrify "^1.0.1"
1484814848

14849+
graphql-http@^1.22.1:
14850+
version "1.22.1"
14851+
resolved "https://registry.yarnpkg.com/graphql-http/-/graphql-http-1.22.1.tgz#3857ac75366e55db189cfe09ade9cc4c4f2cfd09"
14852+
integrity sha512-4Jor+LRbA7SfSaw7dfDUs2UBzvWg3cKrykfHRgKsOIvQaLuf+QOcG2t3Mx5N9GzSNJcuqMqJWz0ta5+BryEmXg==
14853+
1484914854
graphql-ws@5.12.1:
1485014855
version "5.12.1"
1485114856
resolved "https://registry.yarnpkg.com/graphql-ws/-/graphql-ws-5.12.1.tgz#c62d5ac54dbd409cc6520b0b39de374b3d59d0dd"
@@ -14856,13 +14861,14 @@ graphql@16.8.1, graphql@^16.8.1, graphql@^16.9.0:
1485614861
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07"
1485714862
integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==
1485814863

14859-
grats@^0.0.28:
14860-
version "0.0.28"
14861-
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.28.tgz#232fa29cc4387607950e2e408e18c26582586e1b"
14862-
integrity sha512-rNsUJv2V2CtjFrMsfYWHz/0v5ndv2zfaEWj5NdzUzEsezQsCu8CTkKFTyz9DIUZfeU32YaScj2a96Q6yXGFpiQ==
14864+
grats@^0.0.29:
14865+
version "0.0.29"
14866+
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.29.tgz#9efe40da41a90c35c75f7ee4617290623a4318a9"
14867+
integrity sha512-6A77DUF+FHeVEWPUr2DENA9M3iCrR7/TbGQdmJGW7mXs6a5QhnDigq8PkQQdliVzE6KIj86SokkRWS4rAljlPg==
1486314868
dependencies:
1486414869
commander "^10.0.0"
1486514870
graphql "^16.9.0"
14871+
semver "^7.5.4"
1486614872
typescript "5.5.4"
1486714873

1486814874
gulp-eslint@^3.0.1:

0 commit comments

Comments
 (0)