Set up GQL client

This commit is contained in:
Jorge Vargas 2024-08-18 22:47:36 -06:00
parent ec77cb1d24
commit 6833439a4a
14 changed files with 1349 additions and 418 deletions

2
.gitignore vendored
View file

@ -1,7 +1,9 @@
# build output
dist/
# generated types
.astro/
src/graphql/__generated__/
# dependencies
node_modules/

27
codegen.ts Normal file
View file

@ -0,0 +1,27 @@
import { type CodegenConfig } from '@graphql-codegen/cli'
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files'
const config: CodegenConfig = {
schema: 'src/graphql/typeDefs/**/*.graphql',
documents: ['src/**/*.{astro,ts,tsx,mts}'],
generates: {
'./src/graphql/__generated__/client/': {
preset: 'client',
plugins: [],
presetConfig: { gqlTagName: 'gql' },
config: { useTypeImports: true }
},
'./src/graphql/__generated__/': defineConfig({
resolverGeneration: 'disabled',
typesPluginsConfig: {
contextType: '../client.mts#ResolverContext',
},
add: {
'./types.generated.ts': { content: '// @ts-nocheck' },
},
})
},
ignoreNoDocuments: true
}
export default config

1133
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,25 +3,33 @@
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"dev": "concurrently \"npm:gql:watch\" \"npm:astro:dev\"",
"astro:dev": "astro dev",
"build": "astro check && npm run gql:compile && astro build",
"preview": "astro preview",
"astro": "astro"
"astro": "astro",
"gql:compile": "graphql-codegen",
"gql:watch": "graphql-codegen -w"
},
"dependencies": {
"@apollo/client": "^3.11.4",
"@astrojs/check": "^0.9.2",
"@astrojs/node": "^8.3.2",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.32.0",
"@eddeee888/gcg-typescript-resolver-files": "^0.10.4",
"@graphql-codegen/cli": "^5.0.2",
"@graphql-tools/resolvers-composition": "^7.0.1",
"@graphql-tools/schema": "^10.0.4",
"astro": "^4.13.1",
"auth-astro": "^4.1.2",
"graphql-scalars": "^1.23.0",
"tailwindcss": "^3.4.8"
},
"devDependencies": {
"@eddeee888/gcg-typescript-resolver-files": "^0.10.4",
"@graphql-codegen/cli": "^5.0.2",
"@parcel/watcher": "^2.4.1",
"@typescript-eslint/parser": "^6.21.0",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"eslint-plugin-astro": "^1.2.3",
"eslint-plugin-jsx-a11y": "^6.9.0",

View file

@ -0,0 +1,19 @@
import { makeExecutableSchema } from "@graphql-tools/schema";
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { SchemaLink } from "@apollo/client/link/schema"
import { typeDefs } from "./__generated__/typeDefs.generated";
import { resolvers } from "./__generated__/resolvers.generated";
const schema = makeExecutableSchema({ typeDefs, resolvers })
export type ResolverContext = { request?: Request; /*session?: Session */ }
export async function getApolloClient(request?: Request) {
// const session = request ? await getSession(request) : undefined
return new ApolloClient({
ssrMode: true,
link: new SchemaLink({ schema, context: { request } }),
cache: new InMemoryCache()
})
}

View file

@ -0,0 +1,301 @@
type Album {
id: ID!
title: String!
subTitle: String
releaseDate: String!
label: String
vgmdb: String
description: String
stores: [Store]!
discs: [Disc]!
artists: [Artist]!
categories: [Category]!
classifications: [Classification]!
platforms: [Platform]!
games: [Game]!
animations: [Animation]!
downloads: [Download]!
related: [Album]!
updatedAt: Float!
createdAt: Float!
status: String!
placeholder: String
headerColor: String!
}
type Disc {
id: ID!
number: Int
body: String
tracks: [String]
album: Album
}
type Download {
id: ID!
title: String
small: Boolean
links: [Link]
}
type Store {
id: ID!
provider: String
url: String
}
type Link {
id: ID!
provider: String
custom: String
url: String
directUrl: String
}
type Artist {
name: String!
slug: String!
albums: [Album]
}
type Category {
name: String!
albums: [Album]!
count: Int!
}
type Classification {
name: String!
}
type Game {
slug: String!
name: String
releaseDate: String
placeholder: String
publishers: [Publisher]
platforms: [Platform]
albums(order: [String]): [Album]
series: [Series]
headerColor: String!
}
type Animation {
id: ID!
title: String
subTitle: String
releaseDate: String
placeholder: String
studios: [Studio]!
albums(order: [String]): [Album]!
headerColor: String!
}
type Studio {
slug: String!
name: String
animations: [Animation]!
}
type Platform {
id: ID!
name: String
type: String!
albums: [Album]
games: [Game]!
}
type Publisher {
id: ID!
name: String
games: [Game]
}
type Series {
slug: String!
name: String
placeholder: String
games: [Game]
headerColor: String!
}
type Query {
albums: [Album!]!
downloads(id: ID!): [Download]!
albumCount: Float!
categories: [Category]!
classifications: [Classification]!
album(id: ID): Album
artists: [Artist!]!
platforms: [Platform!]!
platform(id: ID): Platform!
publishers: [Publisher]!
publisher(id: ID!): Publisher!
series: [Series]!
seriesOne(slug: String): Series
games: [Game!]!
game(slug: String): Game!
animations: [Animation]!
animation(id: ID): Animation!
studios: [Studio]!
studio(slug: String!): Studio!
highlight: Album!
searchAlbum(
title: String
categories: [String]
limit: Int
page: Int
order: [String]
mode: String
status: [String!]
): SearchAlbumResult
searchAlbumByArtist(
name: String!
categories: [String]
limit: Int
page: Int
order: [String]
mode: String
status: [String!]
): SearchAlbumResult
searchAnimation(
title: String
limit: Int
page: Int
order: String
mode: String
): SearchAnimResult
searchStudio(
name: String
limit: Int
page: Int
order: String
mode: String
): SearchStudioResult
searchGame(
name: String
limit: Int
page: Int
order: String
mode: String
): SearchGameResult
searchSeries(
name: String
limit: Int
page: Int
order: String
mode: String
): SearchSeriesResult
searchSeriesByName(name: String): [Series]
recentSeries(limit: Int!): [Series]
searchPublishersByName(name: String): [Publisher]
recentPublishers(limit: Int!): [Publisher]
searchPlatformsByName(name: String, categories: [String]!): [Platform]
searchPlatformsByCategories(categories: [String]!): [Platform]!
recentPlatforms(limit: Int!, type: [String]!): [Platform]
getRandomAlbum(limit: Int): [Album!]!
}
type Mutation {
createPlatform(name: String, type: String!): Platform!
updatePlatform(key: ID!, name: String, type: String!): Platform!
deletePlatform(key: ID!): Int
createPublisher(name: String): Publisher!
updatePublisher(id: ID!, name: String): Publisher!
deletePublisher(id: ID!): Int
createSeries(slug: String, name: String, cover: Upload!): Series!
updateSeries(slug: String, name: String, cover: Upload): Series!
deleteSeries(slug: String!): Int
createGame(
releaseDate: String
slug: String
name: String
publishers: [ID]
series: [String]
platforms: [ID]
cover: Upload!
): Game!
updateGame(
releaseDate: String
slug: String
name: String
publishers: [ID]
series: [String]
platforms: [ID]
cover: Upload
): Game!
deleteGame(slug: String!): Int
createStudio(slug: String, name: String): Studio!
updateStudio(slug: String, name: String): Studio!
deleteStudio(slug: String!): Int
createAnimation(
title: String
subTitle: String
releaseDate: String
studios: [String]
cover: Upload
): Animation
updateAnimation(
id: ID!
title: String
subTitle: String
releaseDate: String
studios: [String]
cover: Upload
): Animation
deleteAnimation(id: ID!): Int
createAlbum(
title: String
subTitle: String
cover: Upload
releaseDate: String
label: String
vgmdb: String
description: String
stores: [StoreInput]
downloads: [DownloadInput]
artists: [String]
categories: [String]
classifications: [String]
platforms: [ID]
games: [String]
animations: [ID]
discs: [DiscInput]
related: [ID]
status: String!
request: ID
): Album!
updateAlbum(
id: ID!
title: String
subTitle: String
cover: Upload
releaseDate: String
label: String
vgmdb: String
description: String
stores: [StoreInput]
downloads: [DownloadInput]
artists: [String]
categories: [String]
classifications: [String]
platforms: [ID]
games: [String]
animations: [ID]
discs: [DiscInput]
related: [ID]
status: String!
request: ID
): Album!
deleteAlbum(id: ID!): Int
}

View file

@ -0,0 +1,42 @@
type Comment {
id: ID!
text: String!
anon: Boolean!
album: Album!
username: String
}
type Album {
comments: [Comment]!
selfComment: Comment
isFavorite: Boolean
favorites: Int!
avgRating: AvgRating!
selfScore: Int
}
type User {
comments: [Comment]!
favorites: [Album]!
}
type UserMe {
comments: [Comment]!
favorites: [Album]!
}
type AvgRating {
score: Float!
users: Int!
}
type Query {
recentComments(limit: Int): [Comment]!
}
type Mutation {
updateComment(text: String!, anon: Boolean!, albumId: ID!): Boolean
addFavorite(albumId: String!): Boolean
removeFavorite(albumId: String!): Boolean
rateAlbum(albumId: ID!, score: Int!): Boolean
}

View file

@ -0,0 +1,27 @@
input ArtistInput {
name: String!
slug: String!
}
input StoreInput {
provider: String!
url: String!
}
input DownloadInput {
title: String
small: Boolean
links: [LinkInput]
}
input LinkInput {
provider: String
custom: String
url: String
directUrl: String
}
input DiscInput {
number: Int
body: String
}

View file

@ -0,0 +1,64 @@
type Request {
id: ID!
title: String
link: String
user: String
userID: String
state: String!
donator: Boolean!
reason: String
comments: String
message: String
}
type Submission {
id: ID!
title: String!
vgmdb: String
request: Request
links: String
score: Int!
state: String!
submitter: User!
}
type RequestResult {
count: Int!
rows: [Request]!
}
type Query {
requests(
state: [String!],
donator: [Boolean]!
): [Request]!
request(link: String!): Request
searchRequests(
state: [String!]
donator: [Boolean!]
limit: Int
page: Int
filter: String
): RequestResult!
submissions(filter: String, state: [String]): [Submission]!
}
type Mutation {
editRequest(
id: ID!
title: String
link: String
state: String
comments: String
reason: String
): Request!
submitAlbum(
title: String!
vgmdb: String
request: ID
links: String!
): Submission!
rejectRequest(id: ID!, reason: String): Boolean!
}

View file

@ -0,0 +1,24 @@
type SearchAlbumResult {
rows: [Album]
count: Int
}
type SearchAnimResult {
rows: [Animation]
count: Int
}
type SearchStudioResult {
rows: [Studio]
count: Int
}
type SearchGameResult {
rows: [Game]
count: Int
}
type SearchSeriesResult {
rows: [Series]
count: Int
}

View file

@ -0,0 +1,22 @@
scalar Upload
scalar JSON
scalar JSONObject
type Config {
name: String!
value: String!
}
type Query {
config(name: String): Config
banners: [String]!
}
type Mutation {
uploadBanner(banner: Upload!): Int
selectBanner(name: String!): Int
config(
name: String!
value: String!
): Config!
}

View file

@ -0,0 +1,57 @@
type User {
username: String!
roles: [Role]!
permissions: [String]!
pages: [Page]!
createdAt: Float!
placeholder: String!
imgUrl: String!
}
type UserMe {
email: String!
username: String!
roles: [Role]!
permissions: [String]!
pages: [Page]!
createdAt: Float!
placeholder: String!
imgUrl: String!
}
type Page {
url: String!
perms: [String!]!
}
type Role {
name: String!
permissions: [String]!
}
type Query {
me: UserMe
roles: [Role]!
permissions: [String]!
users(search: String): [User]!
user(username: String!): User
login(username: String!, password: String!): Int!
}
type Mutation {
login(username: String!, password: String!): Int!
logout: Int!
registerUser(email: String!, username: String!, pfp: Upload): Boolean!
updateUserRoles(username: String!, roles: [String]!): Boolean!
deleteUser(username: String!): Int
createForgorLink(key: String!): Boolean!
updatePass(key: String!, pass:String!): Boolean!
updateUser(username: String, password: String, email: String, pfp: Upload): Boolean!
createRole(name: String!, permissions: [String]!): Role
updateRole(key:String!, name: String!, permissions: [String]!): Role
deleteRole(name: String!): String
}

View file

@ -0,0 +1,19 @@
type VgmResult {
title: String
subTitle: String
releaseDate: String
coverUrl: String
artists: [String]!
categories: [String]!
classifications: [String]!
trackList: [VGMDBDisc]!
}
type VGMDBDisc {
number: Int
tracks: [String!]
}
type Query {
vgmdb(url: String!): VgmResult
}

View file

@ -1,3 +1,11 @@
{
"extends": "astro/tsconfigs/strict"
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@/*": [
"*"
]
}
}
}