Configure PostgreSQL DataSource
Published: 2022-05-23
To configure PostgreSQL as a DataSource, you have to use introspection.
Import the introspect
function from the @wundergraph/sdk
.
It should be available if you have initialized your project with wunderctl init
.
import {introspect,} from "@wundergraph/sdk";const db = introspect.postgresql({apiNamespace: "db",databaseURL: "postgresql://admin:admin@localhost:55555/example?schema=public",});
Pass a valid QueryString as an argument to introspect.postgresql
.
This gives you a Promise of an API object.
This db
object can now be passed to an Application.
This way, you're able to combine the generated GraphQL API of the database with other APIs,
e.g. a REST or another GraphQL API.
const myApplication = new Application({name: "app",apis: [db,],})
A complete example configuration can be found here.