mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-04-23 19:32:11 +00:00
parent
c7b3267ca2
commit
df154e6b9b
@ -27,7 +27,7 @@ type Query {
|
||||
|
||||
"""Find one card (using the id and set is deprecated)"""
|
||||
card(
|
||||
id: ID!,
|
||||
id: ID,
|
||||
set: String,
|
||||
"""The new way to filter"""
|
||||
filters: CardsFilters
|
||||
@ -35,14 +35,14 @@ type Query {
|
||||
|
||||
"""Find one set (using the id is deprecated)"""
|
||||
set(
|
||||
id: ID!,
|
||||
id: ID,
|
||||
"""The new way to filter"""
|
||||
filters: SetFilters
|
||||
): Set
|
||||
|
||||
"""Find one serie (using the id is deprecated)"""
|
||||
serie(
|
||||
id: ID!,
|
||||
id: ID,
|
||||
"""The new way to filter"""
|
||||
filters: SerieFilters
|
||||
): Serie
|
||||
|
BIN
server/bun.lockb
Normal file → Executable file
BIN
server/bun.lockb
Normal file → Executable file
Binary file not shown.
@ -1,9 +1,8 @@
|
||||
/* eslint-disable max-statements */
|
||||
import { FileFunction } from './compilerInterfaces'
|
||||
import { promises as fs } from 'fs'
|
||||
import { fetchRemoteFile } from './utils/util'
|
||||
import { objectValues } from '@dzeio/object-util'
|
||||
import { SupportedLanguages } from '../../interfaces'
|
||||
import { FileFunction } from './compilerInterfaces'
|
||||
import { fetchRemoteFile } from './utils/util'
|
||||
|
||||
const LANGS: Array<SupportedLanguages> = ['en', 'fr', 'es', 'it', 'pt', 'de']
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { glob } from 'glob'
|
||||
import { Card, Set } from '../../../interfaces'
|
||||
import glob from 'glob'
|
||||
import fetch from 'node-fetch'
|
||||
import * as legals from '../../../meta/legals'
|
||||
|
||||
interface fileCacheInterface {
|
||||
@ -18,9 +17,16 @@ const fileCache: fileCacheInterface = {}
|
||||
*/
|
||||
export async function fetchRemoteFile<T = any>(url: string): Promise<T> {
|
||||
if (!fileCache[url]) {
|
||||
const signal = new AbortController()
|
||||
|
||||
const finished = setTimeout(() => {
|
||||
signal.abort()
|
||||
}, 60 * 1000);
|
||||
|
||||
const resp = await fetch(url, {
|
||||
timeout: 60 * 1000
|
||||
signal: signal.signal
|
||||
})
|
||||
clearTimeout(finished)
|
||||
fileCache[url] = resp.json()
|
||||
}
|
||||
return fileCache[url]
|
||||
@ -30,9 +36,7 @@ const globCache: Record<string, Array<string>> = {}
|
||||
|
||||
export async function smartGlob(query: string): Promise<Array<string>> {
|
||||
if (!globCache[query]) {
|
||||
globCache[query] = await new Promise((res) => {
|
||||
glob(query, (_, matches) => res(matches))
|
||||
})
|
||||
globCache[query] = await glob(query)
|
||||
}
|
||||
return globCache[query]
|
||||
}
|
||||
|
@ -16,19 +16,15 @@
|
||||
"@tcgdex/sdk": "^2",
|
||||
"apicache": "^1",
|
||||
"express": "^4",
|
||||
"express-graphql": "^0.12.0",
|
||||
"graphql": "^15"
|
||||
"graphql": "^15",
|
||||
"graphql-http": "^1.22.1",
|
||||
"ruru": "^2.0.0-beta.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/apicache": "^1",
|
||||
"@types/express": "^4",
|
||||
"@types/glob": "^8",
|
||||
"@types/node": "^18",
|
||||
"@types/node-fetch": "^2",
|
||||
"glob": "^8",
|
||||
"node-fetch": "^2",
|
||||
"ts-node": "^10",
|
||||
"ts-node-dev": "^2",
|
||||
"typescript": "^4"
|
||||
"@types/node": "^20",
|
||||
"glob": "^10",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import express from 'express'
|
||||
import { graphqlHTTP } from 'express-graphql'
|
||||
import fs from 'fs'
|
||||
import { buildSchema, formatError, GraphQLError } from 'graphql'
|
||||
import { buildSchema, GraphQLError } from 'graphql'
|
||||
import { createHandler } from 'graphql-http/lib/use/express'
|
||||
import { type ruruHTML as RuruHTML } from 'ruru/dist/server'
|
||||
/** @ts-expect-error typing is not correctly mapped (real type at ruru/dist/server.d.ts) */
|
||||
import { makeHTMLParts, ruruHTML as tmp } from 'ruru/server'
|
||||
import resolver from './resolver'
|
||||
|
||||
|
||||
const ruruHTML: typeof RuruHTML = tmp
|
||||
|
||||
// Init Express Router
|
||||
const router = express.Router()
|
||||
|
||||
@ -14,11 +20,19 @@ const router = express.Router()
|
||||
const schema = buildSchema(fs.readFileSync('./public/v2/graphql.gql', 'utf-8'))
|
||||
|
||||
// Error Logging for debugging
|
||||
function graphQLErrorHandle(error: GraphQLError) {
|
||||
function graphQLErrorHandle(error: Readonly<GraphQLError | Error>) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error(error)
|
||||
}
|
||||
if (error.source) {
|
||||
if (!('source' in error)) {
|
||||
const columns = (process?.stdout?.columns ?? 32) - 7
|
||||
const dashes = ''.padEnd(columns / 2, '-')
|
||||
|
||||
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
|
||||
console.error('GraphQL Error')
|
||||
console.error(error.message)
|
||||
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
|
||||
} else if (error.source) {
|
||||
const columns = (process?.stdout?.columns ?? 32) - 7
|
||||
const dashes = ''.padEnd(columns / 2, '-')
|
||||
|
||||
@ -28,18 +42,24 @@ function graphQLErrorHandle(error: GraphQLError) {
|
||||
console.error(error.source?.body)
|
||||
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
|
||||
}
|
||||
return formatError(error)
|
||||
return error
|
||||
}
|
||||
|
||||
const graphql = graphqlHTTP({
|
||||
schema,
|
||||
const graphql = createHandler({
|
||||
schema: schema,
|
||||
rootValue: resolver,
|
||||
graphiql: true,
|
||||
customFormatErrorFn: graphQLErrorHandle
|
||||
formatError: graphQLErrorHandle
|
||||
})
|
||||
|
||||
// Add graphql to the route
|
||||
router.get('/', graphql)
|
||||
router.get('/', (_, res) => {
|
||||
res.type('html')
|
||||
|
||||
res.end(ruruHTML({ endpoint: '/v2/graphql' }, {
|
||||
...makeHTMLParts(),
|
||||
titleTag: '<title>GraphiQL - TCGdex API V2</title>'
|
||||
}))
|
||||
})
|
||||
router.post('/', graphql)
|
||||
|
||||
export default router
|
||||
|
Loading…
x
Reference in New Issue
Block a user