Skip to content

Commit 5dbd328

Browse files
committed
feat: Add base Extension interface to GQL schema
1 parent 27d90bc commit 5dbd328

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

scripts/generate-gql-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
1616
consola.info("Generating GraphQL types...");
1717
const introspection = await introspect(fetch);
1818

19+
if (introspection.errors) {
20+
console.error("Introspection errors:", introspection.errors);
21+
throw Error("Introspection failed", { cause: introspection.errors });
22+
}
23+
1924
const {
2025
queryType,
2126
mutationType,
@@ -50,6 +55,8 @@ export async function generateGqlTypes(fetch: ServerSideFetch = app.build()) {
5055
return writeObjectType(code, argTypes, type);
5156
case "SCALAR":
5257
return writeScalarType(code, type);
58+
case "INTERFACE":
59+
return writeObjectType(code, argTypes, type);
5360
default:
5461
return consola.warn("Unknown kind:", {
5562
kind: type.kind,

src/assets/schema.gql

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,68 @@ type Query {
2121
firefoxAddons(ids: [String!]!): [FirefoxAddon]!
2222
}
2323

24-
type ChromeExtension {
24+
interface Extension {
2525
id: String!
2626
name: String!
2727
iconUrl: String!
2828
storeUrl: String!
2929
shortDescription: String!
3030
longDescription: String!
31-
weeklyActiveUsers: Int!
31+
"""
32+
Different extension stores report users in different units (e.g., weekly active users, daily active users).
33+
34+
This field is meant to be used as a generic representation of the number of users. Each type that extends this one has individual fields denoting the unit (`ChromeExtension.weeklyActiveUsers`, `FirefoxAddon.dailyActiveUsers`, etc).
35+
"""
36+
users: Int!
3237
version: String!
3338
lastUpdated: String!
3439
rating: Float
3540
reviewCount: Int
3641
screenshots: [Screenshot!]!
3742
}
3843

39-
type FirefoxAddon {
44+
type ChromeExtension implements Extension {
45+
# Extension fields
46+
4047
id: String!
4148
name: String!
4249
iconUrl: String!
4350
storeUrl: String!
4451
shortDescription: String!
4552
longDescription: String!
46-
dailyActiveUsers: Int!
53+
"Same as weeklyActiveUsers"
54+
users: Int!
55+
version: String!
56+
lastUpdated: String!
57+
rating: Float
58+
reviewCount: Int
59+
screenshots: [Screenshot!]!
60+
61+
# Additional fields
62+
63+
weeklyActiveUsers: Int!
64+
}
65+
66+
type FirefoxAddon implements Extension {
67+
# Extension fields
68+
69+
id: String!
70+
name: String!
71+
iconUrl: String!
72+
storeUrl: String!
73+
shortDescription: String!
74+
longDescription: String!
75+
"Same as dailyActiveUsers"
76+
users: Int!
4777
version: String!
4878
lastUpdated: String!
4979
rating: Float
5080
reviewCount: Int
5181
screenshots: [Screenshot!]!
82+
83+
# Additional fields
84+
85+
dailyActiveUsers: Int!
5286
}
5387

5488
type Screenshot {

src/utils/chrome/chrome-crawler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function crawlExtension(
5959

6060
// Header
6161

62-
const weeklyActiveUsers = tryExtract("weeklyActiveUsers", validateInt, [
62+
const weeklyActiveUsersText = tryExtract("weeklyActiveUsers", validateInt, [
6363
() => {
6464
const userCountRow = document.querySelector(
6565
"main > * > section:first-child > section > div > div:last-child",
@@ -74,6 +74,7 @@ export async function crawlExtension(
7474
);
7575
},
7676
]);
77+
const weeklyActiveUsers = Number(weeklyActiveUsersText);
7778

7879
const rating = tryExtract("rating", validateFloat, [
7980
() =>
@@ -149,7 +150,8 @@ export async function crawlExtension(
149150
name,
150151
iconUrl,
151152
storeUrl,
152-
weeklyActiveUsers: Number(weeklyActiveUsers),
153+
users: weeklyActiveUsers,
154+
weeklyActiveUsers,
153155
lastUpdated,
154156
version,
155157
shortDescription,

src/utils/firefox/firefox-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function createFirefoxApiClient() {
2929
shortDescription: Object.values<string>(json.summary)[0]!,
3030
storeUrl: json.url,
3131
version: json.current_version.version,
32+
users: json.average_daily_users,
3233
dailyActiveUsers: json.average_daily_users,
3334
screenshots: (json.previews as any[]).map<Gql.Screenshot>(
3435
(preview, i) => ({

0 commit comments

Comments
 (0)