feat: graphql client with fetches for initial pages

This commit is contained in:
Simon Emanuelsson
2024-02-01 16:19:16 +01:00
parent a91781137a
commit 5e974aa3da
56 changed files with 2580 additions and 1512 deletions
+36
View File
@@ -0,0 +1,36 @@
// @ts-check
import { clientEnv, clientSchema } from './schema.mjs'
const _clientEnv = clientSchema.safeParse(clientEnv)
export const formatErrors = (
/** @type {import('zod').ZodFormattedError<Map<string,string>,string>} */
errors
) =>
Object.entries(errors)
.map(([name, value]) => {
if (value && '_errors' in value) {
return `${name}: ${value._errors.join(', ')}\n`
}
return null
})
.filter(Boolean)
if (!_clientEnv.success) {
const msg = [
'❌ Invalid environment variables [Client]:\n',
...formatErrors(_clientEnv.error.format()),
].join('')
console.error(msg)
throw new Error(msg)
}
for (let key of Object.keys(_clientEnv.data)) {
if (!key.startsWith('NEXT_PUBLIC_')) {
const msg = `❌ Invalid public environment variable name: ${key}. It must begin with 'NEXT_PUBLIC_'`
console.warn(msg)
throw new Error(msg)
}
}
export const env = _clientEnv.data