Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{}
{
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrder": [
"<BUILTIN_MODULES>",
"<THIRD_PARTY_MODULES>",
"^~/(.*)$",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
2 changes: 1 addition & 1 deletion backend/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import js from "@eslint/js";
import { defineConfig, globalIgnores } from "eslint/config";
import globals from "globals";
import tseslint from "typescript-eslint";
import { defineConfig, globalIgnores } from "eslint/config";

export default defineConfig([
globalIgnores(["**/dist/**", "**/*.generated.ts"]),
Expand Down
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@eddeee888/gcg-typescript-resolver-files": "^0.19.0",
"@eslint/js": "^10.0.1",
"@graphql-codegen/cli": "^7.4.6",
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",
"@types/node": "^26.6.6",
Expand Down
58 changes: 58 additions & 0 deletions backend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2";
import { betterAuth } from "better-auth";
import {
APIError,
createAuthMiddleware,
getSessionFromCtx,
} from "better-auth/api";
import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2";

import { db } from "~/db";
import * as schema from "~/db/schema";

Expand Down
3 changes: 2 additions & 1 deletion backend/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "dotenv/config";
import { defineRelations } from "drizzle-orm";
import { drizzle } from "drizzle-orm/node-postgres";

import {
account,
bookGenres,
books,
bookReviews,
bookToGenres,
books,
favoriteBooks,
session,
user,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/schema/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pgTable, text, timestamp, boolean, index } from "drizzle-orm/pg-core";
import { boolean, index, pgTable, text, timestamp } from "drizzle-orm/pg-core";

const user = pgTable("user", {
id: text("id").primaryKey(),
Expand Down
6 changes: 3 additions & 3 deletions backend/src/db/schema/books.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
index,
integer,
pgTable,
varchar,
text,
primaryKey,
real,
index,
text,
varchar,
} from "drizzle-orm/pg-core";

const books = pgTable(
Expand Down
1 change: 1 addition & 0 deletions backend/src/db/schema/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
text,
timestamp,
} from "drizzle-orm/pg-core";

import { user } from "./auth";
import { books } from "./books";

Expand Down
1 change: 1 addition & 0 deletions backend/src/db/schema/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
timestamp,
unique,
} from "drizzle-orm/pg-core";

import { user } from "./auth";
import { books } from "./books";

Expand Down
14 changes: 8 additions & 6 deletions backend/src/db/seed/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { createReadStream } from "node:fs";
import { resolve, dirname } from "node:path";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

import { parse } from "csv-parse";

import { EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD, auth } from "~/auth";
import { db } from "~/db";
import { parseRating } from "~/db/seed/parseRatings";
import { parsePublishYear } from "~/db/seed/parsePublishYear";
import {
type InsertBook,
bookGenres,
books,
bookToGenres,
type InsertBook,
books,
} from "~/db/schema/books";
import { parsePublishYear } from "~/db/seed/parsePublishYear";
import { parseRating } from "~/db/seed/parseRatings";
import { emptyToNull } from "~/utils/emptyToNull";
import { auth, EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD } from "~/auth";

interface BookRow {
bookId: string;
Expand Down
12 changes: 7 additions & 5 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import http from "http";

import { ApolloServer } from "@apollo/server";
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
import express from "express";
import http from "http";
import cors from "cors";
import { expressMiddleware } from "@as-integrations/express5";
import { typeDefs } from "~/schema/typeDefs.generated";
import { resolvers } from "~/schema/resolvers.generated";
import { fromNodeHeaders, toNodeHandler } from "better-auth/node";
import cors from "cors";
import express from "express";

import { auth } from "~/auth";
import { createBookGenresLoader } from "~/schema/loaders";
import { maxAliasesRule } from "~/schema/requestLimits";
import { resolvers } from "~/schema/resolvers.generated";
import { typeDefs } from "~/schema/typeDefs.generated";

export interface ApolloContext {
session: Awaited<ReturnType<typeof auth.api.getSession>>;
Expand Down
5 changes: 3 additions & 2 deletions backend/src/schema/books/bookFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type SQL,
and,
eq,
exists,
Expand All @@ -7,11 +8,11 @@ import {
lte,
or,
sql,
type SQL,
} from "drizzle-orm";
import { GraphQLError } from "graphql/error";

import { db } from "~/db";
import { bookGenres, books, bookToGenres } from "~/db/schema";
import { bookGenres, bookToGenres, books } from "~/db/schema";
import type { QuerysearchBooksArgs } from "~/schema/types.generated";

// The arguments that decide which books match a search. searchBooks and
Expand Down
5 changes: 3 additions & 2 deletions backend/src/schema/books/facets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { and, asc, count, desc, eq, isNotNull, type SQL } from "drizzle-orm";
import { type SQL, and, asc, count, desc, eq, isNotNull } from "drizzle-orm";

import { db } from "~/db";
import { bookGenres, books, bookToGenres } from "~/db/schema";
import { bookGenres, bookToGenres, books } from "~/db/schema";
import type { FacetValue } from "~/schema/types.generated";

// Every list is ordered by the number of books, and then alphabetically
Expand Down
3 changes: 2 additions & 1 deletion backend/src/schema/books/resolvers/BookFacets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { BookFacetsResolvers } from "./../../types.generated";
import { buildBookFilter } from "~/schema/books/bookFilter";
import {
allBookFormats,
Expand All @@ -8,6 +7,8 @@ import {
countGenres,
} from "~/schema/books/facets";

import type { BookFacetsResolvers } from "./../../types.generated";

// Each list is counted without its own filter, so the user can still switch to
// another option. When nothing else is filtered, the cached counts for all
// books are used instead
Expand Down
1 change: 1 addition & 0 deletions backend/src/schema/books/resolvers/BookSearchResult.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import type { BookSearchResultResolvers } from "./../../types.generated";

export const BookSearchResult: BookSearchResultResolvers = {};
1 change: 1 addition & 0 deletions backend/src/schema/books/resolvers/FacetValue.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import type { FacetValueResolvers } from "./../../types.generated";

export const FacetValue: FacetValueResolvers = {};
3 changes: 2 additions & 1 deletion backend/src/schema/books/resolvers/Query/book.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { QueryResolvers } from "./../../../types.generated";
import { db } from "~/db";

import type { QueryResolvers } from "./../../../types.generated";

export const book: NonNullable<QueryResolvers["book"]> = async (
_parent,
args,
Expand Down
3 changes: 2 additions & 1 deletion backend/src/schema/books/resolvers/Query/bookFacets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { QueryResolvers } from "./../../../types.generated";
import { assertBookFilterArgs } from "~/schema/books/bookFilter";

import type { QueryResolvers } from "./../../../types.generated";

// The lists are counted by the BookFacets field resolvers, so only the lists
// the query asks for are counted
export const bookFacets: NonNullable<QueryResolvers["bookFacets"]> = (
Expand Down
2 changes: 1 addition & 1 deletion backend/src/schema/books/resolvers/Query/bookFormats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryResolvers } from "~/schema/types.generated";
import { allBookFormats } from "~/schema/books/facets";
import type { QueryResolvers } from "~/schema/types.generated";

// The same cached counts as bookFacets uses when nothing is filtered
export const bookFormats: NonNullable<
Expand Down
2 changes: 1 addition & 1 deletion backend/src/schema/books/resolvers/Query/genres.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryResolvers } from "~/schema/types.generated";
import { allGenres } from "~/schema/books/facets";
import type { QueryResolvers } from "~/schema/types.generated";

// The same cached counts as bookFacets uses when nothing is filtered
export const genres: NonNullable<QueryResolvers["genres"]> = async () =>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/schema/books/resolvers/Query/languages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryResolvers } from "~/schema/types.generated";
import { allLanguages } from "~/schema/books/facets";
import type { QueryResolvers } from "~/schema/types.generated";

// The same cached counts as bookFacets uses when nothing is filtered
export const languages: NonNullable<QueryResolvers["languages"]> = async () =>
Expand Down
7 changes: 4 additions & 3 deletions backend/src/schema/books/resolvers/Query/searchBooks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { asc, desc, sql, type SQL } from "drizzle-orm";
import { type SQL, asc, desc, sql } from "drizzle-orm";

import { db } from "~/db";
import { assertLimit, assertOffset } from "~/schema/pagination";
import { books } from "~/db/schema";
import {
assertBookFilterArgs,
buildBookFilter,
} from "~/schema/books/bookFilter";
import { books } from "~/db/schema";
import { assertLimit, assertOffset } from "~/schema/pagination";
import type {
BookSortField,
QueryResolvers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { MutationResolvers } from "~/schema/types.generated";
import { db } from "~/db";
import { GraphQLError } from "graphql/error";

import { db } from "~/db";
import { favoriteBooks } from "~/db/schema";
import type { MutationResolvers } from "~/schema/types.generated";

export const addFavoriteBook: NonNullable<
MutationResolvers["addFavoriteBook"]
Expand Down
Loading