Skip to content

Commit

Permalink
Upgrade Grats and adopt new patterns
Browse files Browse the repository at this point in the history
Summary:

Test Plan:
  • Loading branch information
captbaritone committed Dec 16, 2024
1 parent 2a82192 commit 9a12a61
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 208 deletions.
13 changes: 3 additions & 10 deletions packages/skin-database/api/graphql/ModernSkinsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SkinModel from "../../data/SkinModel";
import { knex } from "../../db";
import ModernSkinResolver from "./resolvers/ModernSkinResolver";
import { Ctx } from ".";
import { Query } from "./resolvers/QueryResolver";

/**
* A collection of "modern" Winamp skins
Expand Down Expand Up @@ -44,16 +43,10 @@ export default class ModernSkinsConnection {

/**
* All modern skins in the database
* @gqlField */
* @gqlQueryField */
export async function modern_skins(
_: Query,
{
first = 10,
offset = 0,
}: {
first?: Int;
offset?: Int;
}
first: Int = 10,
offset: Int = 0
): Promise<ModernSkinsConnection> {
if (first > 1000) {
throw new Error("Maximum limit is 1000");
Expand Down
28 changes: 12 additions & 16 deletions packages/skin-database/api/graphql/SkinsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import LRU from "lru-cache";
import { Int } from "grats";
import { ISkin } from "./resolvers/CommonSkinResolver";
import { Ctx } from ".";
import { Query } from "./resolvers/QueryResolver";

const options = {
max: 100,
Expand Down Expand Up @@ -171,21 +170,18 @@ Only the skins that have been tweeted
* All classic skins in the database
*
* **Note:** We don't currently support combining sorting and filtering.
* @gqlField */
export function skins(
_: Query,
{
first = 10,
offset = 0,
sort,
filter,
}: {
first?: Int;
offset?: Int;
sort?: SkinsSortOption | null;
filter?: SkinsFilterOption | null;
}
): SkinsConnection {
* @gqlQueryField */
export function skins({
first = 10,
offset = 0,
sort,
filter,
}: {
first?: Int;
offset?: Int;
sort?: SkinsSortOption | null;
filter?: SkinsFilterOption | null;
}): SkinsConnection {
if (first > 1000) {
throw new Error("Maximum limit is 1000");
}
Expand Down
24 changes: 10 additions & 14 deletions packages/skin-database/api/graphql/TweetsConnection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Int } from "grats";
import TweetModel from "../../data/TweetModel";
import { knex } from "../../db";
import { Query } from "./resolvers/QueryResolver";

/** @gqlEnum */
export type TweetsSortOption = "LIKES" | "RETWEETS";
Expand Down Expand Up @@ -51,20 +50,17 @@ export default class TweetsConnection {

/**
* Tweets tweeted by @winampskins
* @gqlField
* @gqlQueryField
*/
export async function tweets(
_: Query,
{
first = 10,
offset = 0,
sort,
}: {
first?: Int;
offset?: Int;
sort?: TweetsSortOption | null;
}
): Promise<TweetsConnection> {
export async function tweets({
first = 10,
offset = 0,
sort,
}: {
first?: Int;
offset?: Int;
sort?: TweetsSortOption | null;
}): Promise<TweetsConnection> {
if (first > 1000) {
throw new Error("Maximum limit is 1000");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Int } from "grats";
import * as Skins from "../../../data/skins";
import { Query } from "./QueryResolver";

/**
* Statistics about the contents of the Museum's database.
Expand Down Expand Up @@ -92,7 +91,7 @@ export default class DatabaseStatisticsResolver {

/**
* A namespace for statistics about the database
* @gqlField */
export function statistics(_: Query): DatabaseStatisticsResolver {
* @gqlQueryField */
export function statistics(): DatabaseStatisticsResolver {
return new DatabaseStatisticsResolver();
}
14 changes: 5 additions & 9 deletions packages/skin-database/api/graphql/resolvers/FeedbackMutation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { Ctx } from "..";
import { Mutation } from "./MutationResolver";

/**
* Send a message to the admin of the site. Currently this appears in Discord.
* @gqlField */
* @gqlMutationField */
export async function send_feedback(
_: Mutation,
{
message,
email,
url,
}: { message: string; email?: string | null; url?: string | null },
req: Ctx
req: Ctx,
message: string,
email?: string | null,
url?: string | null
): Promise<boolean> {
req.notify({
type: "GOT_FEEDBACK",
Expand Down

This file was deleted.

8 changes: 2 additions & 6 deletions packages/skin-database/api/graphql/resolvers/NodeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ export function fromId(base64Id: string): { graphqlType: string; id: string } {
* Get a globally unique object by its ID.
*
* https://graphql.org/learn/global-object-identification/
* @gqlField
* @gqlQueryField
*/
export async function node(
_: Query,
{ id }: { id: ID },
{ ctx }: Ctx
): Promise<NodeResolver | null> {
export async function node(id: ID, { ctx }: Ctx): Promise<NodeResolver | null> {
const { graphqlType, id: localId } = fromId(id);
// TODO Use typeResolver
switch (graphqlType) {
Expand Down
2 changes: 0 additions & 2 deletions packages/skin-database/api/graphql/resolvers/QueryResolver.ts

This file was deleted.

30 changes: 8 additions & 22 deletions packages/skin-database/api/graphql/resolvers/ReviewMutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SkinModel from "../../../data/SkinModel";
import * as Skins from "../../../data/skins";
import { Ctx } from "..";
import { Mutation } from "./MutationResolver";

function requireAuthed(handler) {
return (args, req: Ctx) => {
Expand All @@ -17,12 +16,8 @@ function requireAuthed(handler) {
* Reject skin for tweeting
*
* **Note:** Requires being logged in
* @gqlField */
export function reject_skin(
_: Mutation,
md5: string,
req: Ctx
): Promise<boolean> {
* @gqlMutationField */
export function reject_skin(md5: string, req: Ctx): Promise<boolean> {
return _reject_skin(md5, req);
}

Expand All @@ -41,12 +36,8 @@ const _reject_skin = requireAuthed(async (md5: string, req: Ctx) => {
* Approve skin for tweeting
*
* **Note:** Requires being logged in
* @gqlField */
export function approve_skin(
_: Mutation,
md5: string,
req: Ctx
): Promise<boolean> {
* @gqlMutationField */
export function approve_skin(md5: string, req: Ctx): Promise<boolean> {
return _approve_skin(md5, req);
}

Expand All @@ -65,12 +56,8 @@ const _approve_skin = requireAuthed(async (md5: string, req: Ctx) => {
* Mark a skin as NSFW
*
* **Note:** Requires being logged in
* @gqlField */
export function mark_skin_nsfw(
_: Mutation,
md5: string,
req: Ctx
): Promise<boolean> {
* @gqlMutationField */
export function mark_skin_nsfw(md5: string, req: Ctx): Promise<boolean> {
return _mark_skin_nsfw(md5, req);
}

Expand All @@ -89,10 +76,9 @@ const _mark_skin_nsfw = requireAuthed(async (md5: string, req: Ctx) => {
* Request that an admin check if this skin is NSFW.
* Unlike other review mutation endpoints, this one does not require being logged
* in.
* @gqlField */
* @gqlMutationField */
export async function request_nsfw_review_for_skin(
_: Mutation,
{ md5 }: { md5: string },
md5: string,
req: Ctx
): Promise<boolean> {
req.log(`Reporting skin with hash "${md5}"`);
Expand Down
16 changes: 5 additions & 11 deletions packages/skin-database/api/graphql/resolvers/SkinResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import UserContext from "../../../data/UserContext";
import ClassicSkinResolver from "./ClassicSkinResolver";
import { ISkin } from "./CommonSkinResolver";
import ModernSkinResolver from "./ModernSkinResolver";
import { Query } from "./QueryResolver";
import algoliasearch from "algoliasearch";
import * as Skins from "../../../data/skins";

Expand Down Expand Up @@ -35,11 +34,10 @@ export default class SkinResolver {

/**
* Get a skin by its MD5 hash
* @gqlField
* @gqlQueryField
*/
export async function fetch_skin_by_md5(
_: Query,
{ md5 }: { md5: string },
md5: string,
{ ctx }: Ctx
): Promise<ISkin | null> {
const skin = await SkinModel.fromMd5(ctx, md5);
Expand All @@ -53,10 +51,9 @@ export async function fetch_skin_by_md5(
* Search the database using the Algolia search index used by the Museum.
*
* Useful for locating a particular skin.
* @gqlField
* @gqlQueryField
*/
export async function search_skins(
_: Query,
{
query,
first = 10,
Expand All @@ -83,11 +80,8 @@ export async function search_skins(
}
/**
* A random skin that needs to be reviewed
* @gqlField */
export async function skin_to_review(
_: Query,
{ ctx }: Ctx
): Promise<ISkin | null> {
* @gqlQueryField */
export async function skin_to_review({ ctx }: Ctx): Promise<ISkin | null> {
if (!ctx.authed()) {
return null;
}
Expand Down
9 changes: 3 additions & 6 deletions packages/skin-database/api/graphql/resolvers/SkinUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import SkinModel from "../../../data/SkinModel";
import UserContext from "../../../data/UserContext";
import { knex } from "../../../db";
import { ISkin } from "./CommonSkinResolver";
import { Query } from "./QueryResolver";
import SkinResolver from "./SkinResolver";

/**
* Get the status of a batch of uploads by md5s
* @gqlField
* @gqlQueryField
* @deprecated Prefer `upload_statuses` instead, were we operate on ids.
*/
export async function upload_statuses_by_md5(
_: Query,
{ md5s }: { md5s: string[] },
{ ctx }: Ctx
): Promise<Array<SkinUpload | null>> {
Expand All @@ -21,10 +19,9 @@ export async function upload_statuses_by_md5(

/**
* Get the status of a batch of uploads by ids
* @gqlField */
* @gqlQueryField */
export async function upload_statuses(
_: Query,
{ ids }: { ids: string[] },
ids: string[],
{ ctx }: Ctx
): Promise<Array<SkinUpload | null>> {
return _upload_statuses({ keyName: "id", keys: ids }, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as S3 from "../../../s3";
import * as Skins from "../../../data/skins";
import { processUserUploads } from "../../processUserUploads";
import { Ctx } from "..";
import { Mutation } from "./MutationResolver";

// We don't use a resolver here, just return the value directly.
/**
Expand Down Expand Up @@ -83,7 +82,7 @@ class UploadMutationResolver {

/**
* Mutations for the upload flow
* @gqlField */
export async function upload(_: Mutation): Promise<UploadMutationResolver> {
* @gqlMutationField */
export async function upload(): Promise<UploadMutationResolver> {
return new UploadMutationResolver();
}
5 changes: 2 additions & 3 deletions packages/skin-database/api/graphql/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Ctx } from "..";
import { Query } from "./QueryResolver";

/** @gqlType User */
export default class UserResolver {
Expand All @@ -11,8 +10,8 @@ export default class UserResolver {

/**
* The currently authenticated user, if any.
* @gqlField
* @gqlQueryField
*/
export function me(_: Query): UserResolver | null {
export function me(): UserResolver | null {
return new UserResolver();
}
Loading

0 comments on commit 9a12a61

Please sign in to comment.