Skip to Content

Manually Adding APIs

Published: 2022-05-23

You will not find all required APIs in the WunderHub from the start. Additionally, you don't always want to publish all of your APIs to the hub, e.g. if you're simply connecting to a database.

In this case, manually adding an API via introspection is the way to go. Let's have a look at a few examples.

Introspecting a GraphQL API#

const spaceX = introspect.graphql({
url: "https://api.spacex.land/graphql/",
});
const myApplication = new Application({
name: "app",
apis: [
spaceX,
],
});

To introspect a GraphQL API, you need to provide the URL of the API. Add the API to your application, then run wunderctl generate to introspect all APIs and generate your virtual Graph.

Introspecting a REST API#

REST APIs can be introspected by loading an OpenAPI Specification, either from a JSON or YAML file.

const fusionAuth = introspect.openApi({
apiNamespace: "auth",
source: {
kind: "file",
filePath: "fusionauth_v2.yml"
},
statusCodeUnions: true
})

Introspecting a Database#

It's also possible to introspect a database, e.g. PostgreSQL or MongoDB.

const airbnb = introspect.mongodb({
apiNamespace: "airbnb",
databaseURL: "mongodb+srv://admin:password@cluster0.8toev.mongodb.net/sample_airbnb?retryWrites=true&w=majority",
});
const postgres = introspect.postgresql({
apiNamespace: "postgres",
databaseURL: "postgresql://admin:admin@localhost:54322/example?schema=public",
});

More info on how to use introspection#

If you want to learn more on how to configure your WunderGraph Application and introspect APIs, have a look at the wundergraph.config.ts reference


Product

Comparisons

Subscribe to our newsletter!

Stay informed when great things happen! Get the latest news about APIs, GraphQL and more straight into your mailbox.

© 2022 WunderGraph