Skip to content

Commit 9af4c73

Browse files
committed
Upgrade Grats
1 parent b01cdc5 commit 9af4c73

File tree

15 files changed

+54
-44
lines changed

15 files changed

+54
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Int } from "grats";
22
import SkinModel from "../../data/SkinModel";
33
import { knex } from "../../db";
44
import ModernSkinResolver from "./resolvers/ModernSkinResolver";
5-
import { Ctx } from ".";
5+
import UserContext from "../../data/UserContext.js";
66

77
/**
88
* A collection of "modern" Winamp skins
@@ -30,7 +30,7 @@ export default class ModernSkinsConnection {
3030
/**
3131
* The list of skins
3232
* @gqlField */
33-
async nodes({ ctx }: Ctx): Promise<Array<ModernSkinResolver | null>> {
33+
async nodes(ctx: UserContext): Promise<Array<ModernSkinResolver | null>> {
3434
const skins = await this._getQuery()
3535
.select()
3636
.limit(this._first)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SkinResolver from "./resolvers/SkinResolver";
55
import LRU from "lru-cache";
66
import { Int } from "grats";
77
import { ISkin } from "./resolvers/CommonSkinResolver";
8-
import { Ctx } from ".";
8+
import UserContext from "../../data/UserContext.js";
99

1010
const options = {
1111
max: 100,
@@ -102,7 +102,7 @@ export default class SkinsConnection {
102102
* The list of skins
103103
* @gqlField
104104
*/
105-
async nodes({ ctx }: Ctx): Promise<Array<ISkin | null>> {
105+
async nodes(ctx: UserContext): Promise<Array<ISkin | null>> {
106106
if (this._sort === "MUSEUM") {
107107
if (this._filter) {
108108
throw new Error(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import { createHandler } from "graphql-http/lib/use/express";
33

44
// import DEFAULT_QUERY from "./defaultQuery";
55
import { getSchema } from "./schema";
6+
import UserContext from "../../data/UserContext.js";
67

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

11+
/** @gqlContext */
12+
export function getUserContext(ctx: Ctx): UserContext {
13+
return ctx.ctx;
14+
}
15+
1016
const router = Router();
1117

1218
router.use(

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ID } from "grats";
2-
import { Query } from "./QueryResolver";
3-
import { Ctx } from "..";
42
import SkinModel from "../../../data/SkinModel";
53
import SkinResolver from "./SkinResolver";
4+
import UserContext from "../../../data/UserContext.js";
65

76
/**
87
* A globally unique object. The `id` here is intended only for use within
@@ -36,7 +35,10 @@ export function fromId(base64Id: string): { graphqlType: string; id: string } {
3635
* https://graphql.org/learn/global-object-identification/
3736
* @gqlQueryField
3837
*/
39-
export async function node(id: ID, { ctx }: Ctx): Promise<NodeResolver | null> {
38+
export async function node(
39+
id: ID,
40+
ctx: UserContext
41+
): Promise<NodeResolver | null> {
4042
const { graphqlType, id: localId } = fromId(id);
4143
// TODO Use typeResolver
4244
switch (graphqlType) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Ctx } from "..";
2+
import UserContext from "../../../data/UserContext.js";
23
import { Rating, ReviewRow } from "../../../types";
34
import { ISkin } from "./CommonSkinResolver";
45
import SkinResolver from "./SkinResolver";
@@ -17,7 +18,7 @@ export default class ReviewResolver {
1718
* The skin that was reviewed
1819
* @gqlField
1920
*/
20-
skin({ ctx }: Ctx): Promise<ISkin | null> {
21+
skin(ctx: UserContext): Promise<ISkin | null> {
2122
return SkinResolver.fromMd5(ctx, this._model.skin_md5);
2223
}
2324

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class SkinResolver {
3838
*/
3939
export async function fetch_skin_by_md5(
4040
md5: string,
41-
{ ctx }: Ctx
41+
ctx: UserContext
4242
): Promise<ISkin | null> {
4343
const skin = await SkinModel.fromMd5(ctx, md5);
4444
if (skin == null) {
@@ -59,7 +59,7 @@ export async function search_skins(
5959
first = 10,
6060
offset = 0,
6161
}: { query: string; first?: Int; offset?: Int },
62-
{ ctx }: Ctx
62+
ctx: UserContext
6363
): Promise<Array<ISkin | null>> {
6464
if (first > 1000) {
6565
throw new Error("Can only query 1000 records via search.");
@@ -81,7 +81,7 @@ export async function search_skins(
8181
/**
8282
* A random skin that needs to be reviewed
8383
* @gqlQueryField */
84-
export async function skin_to_review({ ctx }: Ctx): Promise<ISkin | null> {
84+
export async function skin_to_review(ctx: UserContext): Promise<ISkin | null> {
8585
if (!ctx.authed()) {
8686
return null;
8787
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Ctx } from "..";
21
import SkinModel from "../../../data/SkinModel";
32
import UserContext from "../../../data/UserContext";
43
import { knex } from "../../../db";
@@ -11,8 +10,8 @@ import SkinResolver from "./SkinResolver";
1110
* @deprecated Prefer `upload_statuses` instead, were we operate on ids.
1211
*/
1312
export async function upload_statuses_by_md5(
14-
{ md5s }: { md5s: string[] },
15-
{ ctx }: Ctx
13+
md5s: string[],
14+
ctx: UserContext
1615
): Promise<Array<SkinUpload | null>> {
1716
return _upload_statuses({ keyName: "skin_md5", keys: md5s }, ctx);
1817
}
@@ -22,7 +21,7 @@ export async function upload_statuses_by_md5(
2221
* @gqlQueryField */
2322
export async function upload_statuses(
2423
ids: string[],
25-
{ ctx }: Ctx
24+
ctx: UserContext
2625
): Promise<Array<SkinUpload | null>> {
2726
return _upload_statuses({ keyName: "id", keys: ids }, ctx);
2827
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as S3 from "../../../s3";
44
import * as Skins from "../../../data/skins";
55
import { processUserUploads } from "../../processUserUploads";
66
import { Ctx } from "..";
7+
import UserContext from "../../../data/UserContext.js";
78

89
// We don't use a resolver here, just return the value directly.
910
/**
@@ -45,8 +46,8 @@ class UploadMutationResolver {
4546
* @gqlField
4647
*/
4748
async get_upload_urls(
48-
{ files }: { files: UploadUrlRequest[] },
49-
{ ctx }: Ctx
49+
files: UploadUrlRequest[],
50+
ctx: UserContext
5051
): Promise<Array<UploadUrl | null>> {
5152
const missing: UploadUrl[] = [];
5253
await Parallel.each(
@@ -69,7 +70,8 @@ class UploadMutationResolver {
6970
* @gqlField
7071
*/
7172
async report_skin_uploaded(
72-
{ id, md5 }: { id: string; md5: string },
73+
id: string,
74+
md5: string,
7375
req: Ctx
7476
): Promise<boolean> {
7577
// TODO: Validate md5 and id;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Ctx } from "..";
1+
import UserContext from "../../../data/UserContext.js";
22

33
/** @gqlType User */
44
export default class UserResolver {
55
/** @gqlField */
6-
username({ ctx }: Ctx): string | null {
6+
username(ctx: UserContext): string | null {
77
return ctx.username;
88
}
99
}

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Do not manually edit. Regenerate by running `npx grats`.
44
*/
55
import { defaultFieldResolver, GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLBoolean, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLID, GraphQLEnumType, GraphQLInputObjectType } from "graphql";
6+
import { getUserContext as getUserContext } from "./index";
67
import { fetch_archive_file_by_md5 as queryFetch_archive_file_by_md5Resolver } from "./../../data/ArchiveFileModel";
78
import { fetch_internet_archive_item_by_identifier as queryFetch_internet_archive_item_by_identifierResolver } from "./../../data/IaItemModel";
89
import { fetch_skin_by_md5 as queryFetch_skin_by_md5Resolver, search_skins as querySearch_skinsResolver, skin_to_review as querySkin_to_reviewResolver } from "./resolvers/SkinResolver";
@@ -118,7 +119,7 @@ export function getSchema(): GraphQLSchema {
118119
name: "skin",
119120
type: SkinType,
120121
resolve(source, _args, context) {
121-
return source.skin(context);
122+
return source.skin(getUserContext(context));
122123
}
123124
}
124125
};
@@ -329,7 +330,7 @@ export function getSchema(): GraphQLSchema {
329330
name: "username",
330331
type: GraphQLString,
331332
resolve(source, _args, context) {
332-
return source.username(context);
333+
return source.username(getUserContext(context));
333334
}
334335
}
335336
};
@@ -504,7 +505,7 @@ export function getSchema(): GraphQLSchema {
504505
name: "nodes",
505506
type: new GraphQLList(ModernSkinType),
506507
resolve(source, _args, context) {
507-
return assertNonNull(source.nodes(context));
508+
return assertNonNull(source.nodes(getUserContext(context)));
508509
}
509510
}
510511
};
@@ -528,7 +529,7 @@ export function getSchema(): GraphQLSchema {
528529
name: "nodes",
529530
type: new GraphQLList(SkinType),
530531
resolve(source, _args, context) {
531-
return assertNonNull(source.nodes(context));
532+
return assertNonNull(source.nodes(getUserContext(context)));
532533
}
533534
}
534535
};
@@ -753,7 +754,7 @@ export function getSchema(): GraphQLSchema {
753754
}
754755
},
755756
resolve(_source, args, context) {
756-
return queryFetch_archive_file_by_md5Resolver(args.md5, context);
757+
return queryFetch_archive_file_by_md5Resolver(args.md5, getUserContext(context));
757758
}
758759
},
759760
fetch_internet_archive_item_by_identifier: {
@@ -767,7 +768,7 @@ export function getSchema(): GraphQLSchema {
767768
}
768769
},
769770
resolve(_source, args, context) {
770-
return queryFetch_internet_archive_item_by_identifierResolver(args.identifier, context);
771+
return queryFetch_internet_archive_item_by_identifierResolver(args.identifier, getUserContext(context));
771772
}
772773
},
773774
fetch_skin_by_md5: {
@@ -781,7 +782,7 @@ export function getSchema(): GraphQLSchema {
781782
}
782783
},
783784
resolve(_source, args, context) {
784-
return queryFetch_skin_by_md5Resolver(args.md5, context);
785+
return queryFetch_skin_by_md5Resolver(args.md5, getUserContext(context));
785786
}
786787
},
787788
fetch_tweet_by_url: {
@@ -795,7 +796,7 @@ export function getSchema(): GraphQLSchema {
795796
}
796797
},
797798
resolve(_source, args, context) {
798-
return queryFetch_tweet_by_urlResolver(args.url, context);
799+
return queryFetch_tweet_by_urlResolver(args.url, getUserContext(context));
799800
}
800801
},
801802
me: {
@@ -837,7 +838,7 @@ export function getSchema(): GraphQLSchema {
837838
}
838839
},
839840
resolve(_source, args, context) {
840-
return queryNodeResolver(args.id, context);
841+
return queryNodeResolver(args.id, getUserContext(context));
841842
}
842843
},
843844
search_skins: {
@@ -861,15 +862,15 @@ export function getSchema(): GraphQLSchema {
861862
}
862863
},
863864
resolve(_source, args, context) {
864-
return assertNonNull(querySearch_skinsResolver(args, context));
865+
return assertNonNull(querySearch_skinsResolver(args, getUserContext(context)));
865866
}
866867
},
867868
skin_to_review: {
868869
description: "A random skin that needs to be reviewed",
869870
name: "skin_to_review",
870871
type: SkinType,
871872
resolve(_source, _args, context) {
872-
return querySkin_to_reviewResolver(context);
873+
return querySkin_to_reviewResolver(getUserContext(context));
873874
}
874875
},
875876
skins: {
@@ -943,7 +944,7 @@ export function getSchema(): GraphQLSchema {
943944
}
944945
},
945946
resolve(_source, args, context) {
946-
return assertNonNull(queryUpload_statusesResolver(args.ids, context));
947+
return assertNonNull(queryUpload_statusesResolver(args.ids, getUserContext(context)));
947948
}
948949
},
949950
upload_statuses_by_md5: {
@@ -958,7 +959,7 @@ export function getSchema(): GraphQLSchema {
958959
}
959960
},
960961
resolve(_source, args, context) {
961-
return assertNonNull(queryUpload_statuses_by_md5Resolver(args, context));
962+
return assertNonNull(queryUpload_statuses_by_md5Resolver(args.md5s, getUserContext(context)));
962963
}
963964
}
964965
};
@@ -1025,7 +1026,7 @@ export function getSchema(): GraphQLSchema {
10251026
}
10261027
},
10271028
resolve(source, args, context) {
1028-
return assertNonNull(source.get_upload_urls(args, context));
1029+
return assertNonNull(source.get_upload_urls(args.files, getUserContext(context)));
10291030
}
10301031
},
10311032
report_skin_uploaded: {
@@ -1043,7 +1044,7 @@ export function getSchema(): GraphQLSchema {
10431044
}
10441045
},
10451046
resolve(source, args, context) {
1046-
return assertNonNull(source.report_skin_uploaded(args, context));
1047+
return assertNonNull(source.report_skin_uploaded(args.id, args.md5, context));
10471048
}
10481049
}
10491050
};

0 commit comments

Comments
 (0)