Skip to content

Commit

Permalink
Upgrade grats
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Aug 26, 2024
1 parent 02b4055 commit 919b52b
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 65 deletions.
1 change: 1 addition & 0 deletions packages/skin-database/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api/graphql/schema.ts
5 changes: 1 addition & 4 deletions packages/skin-database/api/graphql/ModernSkinsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export default class ModernSkinsConnection {
/**
* The list of skins
* @gqlField */
async nodes(
_args: unknown,
{ ctx }: Ctx
): Promise<Array<ModernSkinResolver | null>> {
async nodes({ ctx }: Ctx): Promise<Array<ModernSkinResolver | null>> {
const skins = await this._getQuery()
.select()
.limit(this._first)
Expand Down
2 changes: 1 addition & 1 deletion packages/skin-database/api/graphql/SkinsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class SkinsConnection {
* The list of skins
* @gqlField
*/
async nodes(args: unknown, { ctx }: Ctx): Promise<Array<ISkin | null>> {
async nodes({ ctx }: Ctx): Promise<Array<ISkin | null>> {
if (this._sort === "MUSEUM") {
if (this._filter) {
throw new Error(
Expand Down
1 change: 1 addition & 0 deletions packages/skin-database/api/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { graphqlHTTP } from "express-graphql";
import DEFAULT_QUERY from "./defaultQuery";
import { getSchema } from "./schema";

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

const router = Router();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SkinModel from "../../../data/SkinModel";
* @gqlType ClassicSkin */
export default class ClassicSkinResolver implements NodeResolver, ISkin {
_model: SkinModel;
__typename = "ClassicSkin";
__typename = "ClassicSkin" as const;

constructor(model: SkinModel) {
this._model = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { XMLParser } from "fast-xml-parser";
* @gqlType ModernSkin */
export default class ModernSkinResolver implements NodeResolver, ISkin {
_model: SkinModel;
__typename = "ModernSkin";
__typename = "ModernSkin" as const;

constructor(model: SkinModel) {
this._model = model;
Expand Down
18 changes: 9 additions & 9 deletions packages/skin-database/api/graphql/resolvers/ReviewMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ function requireAuthed(handler) {
* @gqlField */
export function reject_skin(
_: Mutation,
args: { md5: string },
md5: string,
req: Ctx
): Promise<boolean> {
return _reject_skin(args, req);
return _reject_skin(md5, req);
}

const _reject_skin = requireAuthed(async ({ md5 }, req: Ctx) => {
const _reject_skin = requireAuthed(async (md5: string, req: Ctx) => {
req.log(`Rejecting skin with hash "${md5}"`);
const skin = await SkinModel.fromMd5Assert(req.ctx, md5);
if (skin == null) {
Expand All @@ -44,13 +44,13 @@ const _reject_skin = requireAuthed(async ({ md5 }, req: Ctx) => {
* @gqlField */
export function approve_skin(
_: Mutation,
args: { md5: string },
md5: string,
req: Ctx
): Promise<boolean> {
return _approve_skin(args, req);
return _approve_skin(md5, req);
}

const _approve_skin = requireAuthed(async ({ md5 }, req: Ctx) => {
const _approve_skin = requireAuthed(async (md5: string, req: Ctx) => {
req.log(`Approving skin with hash "${md5}"`);
const skin = await SkinModel.fromMd5(req.ctx, md5);
if (skin == null) {
Expand All @@ -68,13 +68,13 @@ const _approve_skin = requireAuthed(async ({ md5 }, req: Ctx) => {
* @gqlField */
export function mark_skin_nsfw(
_: Mutation,
args: { md5: string },
md5: string,
req: Ctx
): Promise<boolean> {
return _mark_skin_nsfw(args, req);
return _mark_skin_nsfw(md5, req);
}

const _mark_skin_nsfw = requireAuthed(async ({ md5 }, req: Ctx) => {
const _mark_skin_nsfw = requireAuthed(async (md5: string, req: Ctx) => {
req.log(`Approving skin with hash "${md5}"`);
const skin = await SkinModel.fromMd5(req.ctx, md5);
if (skin == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ReviewResolver {
* The skin that was reviewed
* @gqlField
*/
skin(args: unknown, { ctx }: Ctx): Promise<ISkin | null> {
skin({ ctx }: Ctx): Promise<ISkin | null> {
return SkinResolver.fromMd5(ctx, this._model.skin_md5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export async function search_skins(
* @gqlField */
export async function skin_to_review(
_: Query,
_args: unknown,
{ ctx }: Ctx
): Promise<ISkin | null> {
if (!ctx.authed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Query } from "./QueryResolver";
/** @gqlType User */
export default class UserResolver {
/** @gqlField */
username(_args: unknown, { ctx }: Ctx): string | null {
username({ ctx }: Ctx): string | null {
return ctx.username;
}
}
Expand Down
82 changes: 44 additions & 38 deletions packages/skin-database/api/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,32 @@ export function getSchema(): GraphQLSchema {
description: "The Internet Archive's unique identifier for this item",
name: "identifier",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getIdentifier(source, args, context, info));
resolve(source) {
return assertNonNull(source.getIdentifier());
}
},
last_metadata_scrape_date_UNSTABLE: {
description: "The date and time that we last scraped this item's metadata.\n**Note:** This field is temporary and will be removed in the future.\nThe date format is just what we get from the database, and it's ambiguous.",
name: "last_metadata_scrape_date_UNSTABLE",
type: GraphQLString,
resolve(source, args, context, info) {
return source.getMetadataTimestamp(source, args, context, info);
resolve(source) {
return source.getMetadataTimestamp();
}
},
metadata_url: {
description: "URL to get the Internet Archive's metadata for this item in JSON form.",
name: "metadata_url",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getMetadataUrl(source, args, context, info));
resolve(source) {
return assertNonNull(source.getMetadataUrl());
}
},
raw_metadata_json: {
description: "Our cached version of the metadata available at \\`metadata_url\\` (above)",
name: "raw_metadata_json",
type: GraphQLString,
resolve(source, args, context, info) {
return source.getMetadataJSON(source, args, context, info);
resolve(source) {
return source.getMetadataJSON();
}
},
skin: {
Expand All @@ -105,8 +105,8 @@ export function getSchema(): GraphQLSchema {
description: "The URL where this item can be viewed on the Internet Archive",
name: "url",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getUrl(source, args, context, info));
resolve(source) {
return assertNonNull(source.getUrl());
}
}
};
Expand Down Expand Up @@ -151,7 +151,10 @@ export function getSchema(): GraphQLSchema {
skin: {
description: "The skin that was reviewed",
name: "skin",
type: SkinType
type: SkinType,
resolve(source, _args, context) {
return source.skin(context);
}
}
};
}
Expand All @@ -165,16 +168,16 @@ export function getSchema(): GraphQLSchema {
description: "Number of likes the tweet has received. Updated nightly. (Note: Recent likes on older tweets may not be reflected here)",
name: "likes",
type: GraphQLInt,
resolve(source, args, context, info) {
return assertNonNull(source.getLikes(source, args, context, info));
resolve(source) {
return assertNonNull(source.getLikes());
}
},
retweets: {
description: "Number of retweets the tweet has received. Updated nightly. (Note: Recent retweets on older tweets may not be reflected here)",
name: "retweets",
type: GraphQLInt,
resolve(source, args, context, info) {
return assertNonNull(source.getRetweets(source, args, context, info));
resolve(source) {
return assertNonNull(source.getRetweets());
}
},
skin: {
Expand All @@ -186,8 +189,8 @@ export function getSchema(): GraphQLSchema {
description: "URL of the tweet. **Note:** Early on in the bot's life we just recorded\n_which_ skins were tweeted, not any info about the actual tweet. This means we\ndon't always know the URL of the tweet.",
name: "url",
type: GraphQLString,
resolve(source, args, context, info) {
return source.getUrl(source, args, context, info);
resolve(source) {
return source.getUrl();
}
}
};
Expand Down Expand Up @@ -293,40 +296,40 @@ export function getSchema(): GraphQLSchema {
description: "The date on the file inside the archive. Given in simplified extended ISO\nformat (ISO 8601).",
name: "date",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getIsoDate(source, args, context, info));
resolve(source) {
return assertNonNull(source.getIsoDate());
}
},
file_md5: {
description: "The md5 hash of the file within the archive",
name: "file_md5",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getFileMd5(source, args, context, info));
resolve(source) {
return assertNonNull(source.getFileMd5());
}
},
filename: {
description: "Filename of the file within the archive",
name: "filename",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getFileName(source, args, context, info));
resolve(source) {
return assertNonNull(source.getFileName());
}
},
is_directory: {
description: "Is the file a directory?",
name: "is_directory",
type: GraphQLBoolean,
resolve(source, args, context, info) {
return assertNonNull(source.getIsDirectory(source, args, context, info));
resolve(source) {
return assertNonNull(source.getIsDirectory());
}
},
size: {
description: "The uncompressed size of the file in bytes.\n\n**Note:** Will be `null` for directories",
name: "size",
type: GraphQLInt,
resolve(source, args, context, info) {
return source.getFileSize(source, args, context, info);
resolve(source) {
return source.getFileSize();
}
},
skin: {
Expand All @@ -338,16 +341,16 @@ export function getSchema(): GraphQLSchema {
description: "The content of the file, if it's a text file",
name: "text_content",
type: GraphQLString,
resolve(source, args, context, info) {
return source.getTextContent(source, args, context, info);
resolve(source) {
return source.getTextContent();
}
},
url: {
description: "A URL to download the file. **Note:** This is powered by a little\nserverless Cloudflare function which tries to exctact the file on the fly.\nIt may not work for all files.",
name: "url",
type: GraphQLString,
resolve(source, args, context, info) {
return assertNonNull(source.getUrl(source, args, context, info));
resolve(source) {
return assertNonNull(source.getUrl());
}
}
};
Expand All @@ -359,7 +362,10 @@ export function getSchema(): GraphQLSchema {
return {
username: {
name: "username",
type: GraphQLString
type: GraphQLString,
resolve(source, _args, context) {
return source.username(context);
}
}
};
}
Expand Down Expand Up @@ -532,8 +538,8 @@ export function getSchema(): GraphQLSchema {
description: "The list of skins",
name: "nodes",
type: new GraphQLList(ModernSkinType),
resolve(source, args, context, info) {
return assertNonNull(defaultFieldResolver(source, args, context, info));
resolve(source, _args, context) {
return assertNonNull(source.nodes(context));
}
}
};
Expand All @@ -556,8 +562,8 @@ export function getSchema(): GraphQLSchema {
description: "The list of skins",
name: "nodes",
type: new GraphQLList(SkinType),
resolve(source, args, context, info) {
return assertNonNull(defaultFieldResolver(source, args, context, info));
resolve(source, _args, context) {
return assertNonNull(source.nodes(context));
}
}
};
Expand Down Expand Up @@ -897,8 +903,8 @@ export function getSchema(): GraphQLSchema {
description: "A random skin that needs to be reviewed",
name: "skin_to_review",
type: SkinType,
resolve(source, args, context) {
return querySkin_to_reviewResolver(source, args, context);
resolve(source, _args, context) {
return querySkin_to_reviewResolver(source, context);
}
},
skins: {
Expand Down
1 change: 1 addition & 0 deletions packages/skin-database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"express-sitemap-xml": "^2.0.0",
"fast-xml-parser": "^4.2.2",
"graphql": "^16.8.1",
"grats": "^0.0.28",
"imagemin": "^7.0.0",
"imagemin-optipng": "^7.0.0",
"knex": "^0.21.1",
Expand Down
21 changes: 13 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14851,19 +14851,19 @@ graphql-ws@5.12.1:
resolved "https://registry.yarnpkg.com/graphql-ws/-/graphql-ws-5.12.1.tgz#c62d5ac54dbd409cc6520b0b39de374b3d59d0dd"
integrity sha512-umt4f5NnMK46ChM2coO36PTFhHouBrK9stWWBczERguwYrGnPNxJ9dimU6IyOBfOkC6Izhkg4H8+F51W/8CYDg==

graphql@^16.6.0, graphql@^16.8.1:
graphql@16.8.1, graphql@^16.8.1, graphql@^16.9.0:
version "16.8.1"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07"
integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==

grats@^0.0.25:
version "0.0.25"
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.25.tgz#c2f872d3843d67f7c5ed957775bd2c58b476cc07"
integrity sha512-kwI4BHauMXIZc4iigVUFyZIqW12fKrBojGvX9ZrJxnvf1CYMkc+WgH2NfLozLcu2EmbGNX5Ss/TeWJH6xP8wHg==
grats@^0.0.28:
version "0.0.28"
resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.28.tgz#232fa29cc4387607950e2e408e18c26582586e1b"
integrity sha512-rNsUJv2V2CtjFrMsfYWHz/0v5ndv2zfaEWj5NdzUzEsezQsCu8CTkKFTyz9DIUZfeU32YaScj2a96Q6yXGFpiQ==
dependencies:
commander "^10.0.0"
graphql "^16.6.0"
typescript "^5.0.2"
graphql "^16.9.0"
typescript "5.5.4"

gulp-eslint@^3.0.1:
version "3.0.1"
Expand Down Expand Up @@ -27415,6 +27415,11 @@ typescript@4.3.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==

typescript@5.5.4:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

typescript@^3.8.3, typescript@^3.9.10:
version "3.9.10"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"
Expand All @@ -27425,7 +27430,7 @@ typescript@^4.1.5, typescript@^4.4.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^5.0.2, typescript@^5.3.3:
typescript@^5.3.3:
version "5.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff"
integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==
Expand Down

0 comments on commit 919b52b

Please sign in to comment.