SynthQL-compatible route handler function for use in Express.js server app.
// src/queryEngine.ts
import { QueryEngine } from '@synthql/backend';
export const queryEngine = new QueryEngine({
url: 'postgresql://user:password@localhost:5432/dbname',
});
// src/index.ts
import express from 'express';
import { createExpressSynthqlHandler } from '@synthql/handler-express';
import { queryEngine } from './queryEngine';
const app = express();
const expressSynthqlRequestHandler = createExpressSynthqlHandler(queryEngine);
app.post('/synthql', async (req, res) => {
return await expressSynthqlRequestHandler(req, res);
});
app.listen(3000);