Skip to content

Commit

Permalink
Chore: upgrade deps (#483)
Browse files Browse the repository at this point in the history
Co-authored-by: Avior <[email protected]>
  • Loading branch information
Aviortheking and Aviortheking authored May 7, 2024
1 parent c7b3267 commit df154e6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
6 changes: 3 additions & 3 deletions meta/definitions/graphql.gql
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ 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
): Card

"""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
Expand Down
Binary file modified server/bun.lockb
100644 → 100755
Binary file not shown.
5 changes: 2 additions & 3 deletions server/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -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']

Expand Down
16 changes: 10 additions & 6 deletions server/compiler/utils/util.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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]
Expand All @@ -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]
}
Expand Down
16 changes: 6 additions & 10 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
40 changes: 30 additions & 10 deletions server/src/V2/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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, '-')

Expand All @@ -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

0 comments on commit df154e6

Please sign in to comment.