wallet.andert.me/.wundergraph/wundergraph.config.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-08-25 07:45:46 +00:00
import { configureWunderGraphApplication, cors, EnvironmentVariable, introspect, templates } from '@wundergraph/sdk';
import server from './wundergraph.server';
import operations from './wundergraph.operations';
import fs from 'fs';
import path from 'path';
2023-08-25 10:31:15 +00:00
import dotenv from 'dotenv';
dotenv.config();
2023-08-25 07:45:46 +00:00
const directusSchema = fs.readFileSync(path.join(path.resolve(), './schemas/directus.graphql'), 'utf8');
const directusSystemSchema = fs.readFileSync(path.join(path.resolve(), './schemas/directus_system.graphql'), 'utf8');
2023-08-25 07:45:46 +00:00
const db = introspect.graphql({
apiNamespace: 'db',
2023-08-25 07:45:46 +00:00
loadSchemaFromString: directusSchema,
url: 'https://directus.andert.me/graphql',
2023-08-25 09:50:36 +00:00
headers: (builder) => builder
2023-08-25 10:31:15 +00:00
.addStaticHeader('Authorization', new EnvironmentVariable('DIRECTUS', process.env.DIRECTUS))
2023-08-25 07:45:46 +00:00
});
2023-09-20 11:10:16 +00:00
const placeholder = introspect.openApiV2({
apiNamespace: 'placeholder',
source: {
kind: "file",
filePath: "./schemas/placeholder.json"
},
baseURL: 'https://jsonplaceholder.typicode.com',
});
const system_db = introspect.graphql({
apiNamespace: 'system_db',
loadSchemaFromString: directusSystemSchema,
url: 'https://directus.andert.me/graphql/system',
headers: (builder) => builder
.addStaticHeader('Authorization', new EnvironmentVariable('DIRECTUS', process.env.DIRECTUS))
});
2023-08-25 07:45:46 +00:00
// configureWunderGraph emits the configuration
configureWunderGraphApplication({
2023-09-20 18:56:27 +00:00
apis: [db, system_db, placeholder],
2023-08-25 07:45:46 +00:00
server,
operations,
generate: {
codeGenerators: [
{
templates: [
// use all the typescript react templates to generate a client
...templates.typescript.all,
],
path: '../src/lib/.wundergraph/generated',
},
],
},
cors: {
...cors.allowAll,
allowedOrigins:
process.env.NODE_ENV === 'production'
? [
// change this before deploying to production to the actual domain where you're deploying your app
'http://localhost:3000',
]
: ['http://localhost:3000', new EnvironmentVariable('WG_ALLOWED_ORIGIN')],
},
security: {
enableGraphQLEndpoint: process.env.NODE_ENV !== 'production' || process.env.GITPOD_WORKSPACE_ID !== undefined,
},
2023-08-25 12:59:02 +00:00
authentication: {
tokenBased: {
providers: [
{
userInfoEndpoint: 'http://localhost:3000/server/wundergraph',
2023-08-25 12:59:02 +00:00
},
],
},
},
authorization: {
roles: ['owner'],
},
2023-08-25 07:45:46 +00:00
});