diff --git a/packages/skin-database/api/graphql/index.ts b/packages/skin-database/api/graphql/index.ts index 36286331d..8b7116463 100644 --- a/packages/skin-database/api/graphql/index.ts +++ b/packages/skin-database/api/graphql/index.ts @@ -1,7 +1,7 @@ -import { RequestHandler, Router } from "express"; -import { graphqlHTTP } from "express-graphql"; +import { Router } from "express"; +import { createHandler } from "graphql-http/lib/use/express"; -import DEFAULT_QUERY from "./defaultQuery"; +// import DEFAULT_QUERY from "./defaultQuery"; import { getSchema } from "./schema"; /** @gqlContext */ @@ -9,53 +9,34 @@ export type Ctx = Express.Request; const router = Router(); -function getQueryNameFromDocument(document) { - const operationDefinition = document.definitions.find( - (def) => def.kind === "OperationDefinition" - ); - if (!operationDefinition) { - return null; - } - return operationDefinition.name?.value; -} - -const extensions = ({ - variables, - operationName, - context: req, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - document, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - result, -}) => { - const runTime = Date.now() - req.startTime; - const vars = JSON.stringify(variables); - const queryName = operationName ?? getQueryNameFromDocument(document); - // TODO: Log/notify on error. - req.log( - `Handled GraphQL Query: "${queryName}" with variables ${vars} in ${runTime}ms` - ); - return { runTime }; -}; - router.use( "/", - graphqlHTTP({ + createHandler({ schema: getSchema(), + context: (req) => { + return req.raw; + }, + /* graphiql: { defaultQuery: DEFAULT_QUERY, - }, - customFormatErrorFn: (error) => { - console.error(error); - return { - message: error.message, - locations: error.locations, - stack: error.stack ? error.stack.split("\n") : [], - path: error.path, - }; - }, - extensions, - }) as RequestHandler + },*/ + // graphqlHTTP({ + // schema: getSchema(), + // graphiql: { + // defaultQuery: DEFAULT_QUERY, + // }, + // customFormatErrorFn: (error) => { + // console.error(error); + // return { + // message: error.message, + // locations: error.locations, + // stack: error.stack ? error.stack.split("\n") : [], + // path: error.path, + // }; + // }, + // extensions, + // }) as RequestHandler + }) ); export default router; diff --git a/packages/skin-database/api/graphql/resolvers/ReviewMutations.ts b/packages/skin-database/api/graphql/resolvers/ReviewMutations.ts index 7975f6b82..b35309dc2 100644 --- a/packages/skin-database/api/graphql/resolvers/ReviewMutations.ts +++ b/packages/skin-database/api/graphql/resolvers/ReviewMutations.ts @@ -75,7 +75,7 @@ export function mark_skin_nsfw( } const _mark_skin_nsfw = requireAuthed(async (md5: string, req: Ctx) => { - req.log(`Approving skin with hash "${md5}"`); + req.log(`Marking skin with hash "${md5}" NSFW`); const skin = await SkinModel.fromMd5(req.ctx, md5); if (skin == null) { return false; diff --git a/packages/skin-database/api/graphql/schema.ts b/packages/skin-database/api/graphql/schema.ts index a3877e7a9..4ac98e5cc 100644 --- a/packages/skin-database/api/graphql/schema.ts +++ b/packages/skin-database/api/graphql/schema.ts @@ -1099,7 +1099,7 @@ export function getSchema(): GraphQLSchema { } }, resolve(source, args, context) { - return assertNonNull(mutationApprove_skinResolver(source, args, context)); + return assertNonNull(mutationApprove_skinResolver(source, args.md5, context)); } }, mark_skin_nsfw: { @@ -1113,7 +1113,7 @@ export function getSchema(): GraphQLSchema { } }, resolve(source, args, context) { - return assertNonNull(mutationMark_skin_nsfwResolver(source, args, context)); + return assertNonNull(mutationMark_skin_nsfwResolver(source, args.md5, context)); } }, reject_skin: { @@ -1127,7 +1127,7 @@ export function getSchema(): GraphQLSchema { } }, resolve(source, args, context) { - return assertNonNull(mutationReject_skinResolver(source, args, context)); + return assertNonNull(mutationReject_skinResolver(source, args.md5, context)); } }, request_nsfw_review_for_skin: { diff --git a/packages/skin-database/package.json b/packages/skin-database/package.json index ee33a4f50..5e85088c2 100644 --- a/packages/skin-database/package.json +++ b/packages/skin-database/package.json @@ -22,7 +22,8 @@ "express-sitemap-xml": "^2.0.0", "fast-xml-parser": "^4.2.2", "graphql": "^16.8.1", - "grats": "^0.0.28", + "graphql-http": "^1.22.1", + "grats": "^0.0.29", "imagemin": "^7.0.0", "imagemin-optipng": "^7.0.0", "knex": "^0.21.1", diff --git a/yarn.lock b/yarn.lock index e05f56e42..45e2bf056 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14846,6 +14846,11 @@ graphql-depth-limit@^1.1.0: dependencies: arrify "^1.0.1" +graphql-http@^1.22.1: + version "1.22.1" + resolved "https://registry.yarnpkg.com/graphql-http/-/graphql-http-1.22.1.tgz#3857ac75366e55db189cfe09ade9cc4c4f2cfd09" + integrity sha512-4Jor+LRbA7SfSaw7dfDUs2UBzvWg3cKrykfHRgKsOIvQaLuf+QOcG2t3Mx5N9GzSNJcuqMqJWz0ta5+BryEmXg== + graphql-ws@5.12.1: version "5.12.1" 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: resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07" integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw== -grats@^0.0.28: - version "0.0.28" - resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.28.tgz#232fa29cc4387607950e2e408e18c26582586e1b" - integrity sha512-rNsUJv2V2CtjFrMsfYWHz/0v5ndv2zfaEWj5NdzUzEsezQsCu8CTkKFTyz9DIUZfeU32YaScj2a96Q6yXGFpiQ== +grats@^0.0.29: + version "0.0.29" + resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.29.tgz#9efe40da41a90c35c75f7ee4617290623a4318a9" + integrity sha512-6A77DUF+FHeVEWPUr2DENA9M3iCrR7/TbGQdmJGW7mXs6a5QhnDigq8PkQQdliVzE6KIj86SokkRWS4rAljlPg== dependencies: commander "^10.0.0" graphql "^16.9.0" + semver "^7.5.4" typescript "5.5.4" gulp-eslint@^3.0.1: