APIs

GraphQL

The GraphQL DataSource allows you to connect any compatible GraphQL Server. WunderGraph supports Queries, Mutations as well as Subscriptions.

Add a GraphQL DataSource

To add a GraphQL data source, edit .wundergraph/wundergraph.config.ts and introspect the GraphQL server like the config below.

1
2
3
4
5
6
7
8
9
10
import { configureWunderGraphApplication, introspect } from '@wundergraph/sdk';
const countries = introspect.graphql({
apiNamespace: 'countries',
url: 'https://countries.trevorblades.com/',
});
configureWunderGraphApplication({
apis: [countries],
});

The GraphQL data source is now added to your virtual graph and you can now write operations against it.

Write an operation

Create a new file Countries.graphql in the operations folder and add the following content:

1
2
3
4
5
query {
countries_countries {
name
}
}

Run the query

Queries are simply HTTP endpoints on your WunderGraph server.

1
2
3
npm run start
curl http://localhost:9991/operations/Countries

Learn more

Guides

How to write GraphQL and TypeScript operations.

Reference docs

All GraphQL introspection options.

Previous
Overview

Was this article helpful to you?
Provide feedback

Edit this page