Data Sources Reference

WunderGraph supports a variety of data sources. They can be configured in the wundergraph.config.ts file by adding introspections to the apis configuration.

Usage

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

All data sources are configured using the introspect function. The introspect function takes a configuration object as its only argument. The configuration object depends on the data source you want to configure.

Each introspection supports an apiNamespace property. This property is used to namespace the data source in the GraphQL schema, so that any naming collisions can be prevented.

Supported introspections

IntrospectionDescription
introspect.graphqlGraphQL API
introspect.postgresqlPostgreSQL database
introspect.mysqlMySQL database
introspect.planetscalePlanetscale database
introspect.sqliteSQLite database
introspect.sqlserverSQL Server database
introspect.mongodbMongoDB database
introspect.prismaPrisma database
introspect.federationGraphQL Federation API
introspect.openApiOpenAPI API
introspect.soapSOAP

GraphQL

1
2
3
4
5
const countries = introspect.graphql({
apiNamespace: 'countries',
url: 'https://countries.trevorblades.com/',
requestTimeoutSeconds: 10, // optional
});

Properties

PropertyDescription
urlThe URL of the GraphQL service
apiNamespaceThe namespace of the GraphQL service
headersThe headers to send with the request
requestTimeoutSecondsThe timeout for the request in seconds. Defaults to 10 seconds.
introspectionThe introspection query to use. Defaults to the introspection query from the graphql package
loadSchemaFromStringA function that returns the schema as a string. This is useful if you want to use a local schema file.
customFloatScalarsAn array of custom float scalars.
customIntScalarsAn array of custom int scalars.
customJSONScalarsAn array of custom JSON scalars.
internalWhether the GraphQL service is internal. Defaults to false
skipRenameRootFieldsAn array of root fields to skip renaming.
schemaExtensionA string that is appended to the schema. Useful for adding custom scalars.
replaceCustomScalarTypeFieldsAn array of custom scalar type fields to replace.
httpProxyUrlHTTP(S) proxy to use, overriding the default one (if any). Set to null to disable.

Note that if you are not replacing a custom JSON scalar using the replaceCustomScalarTypeFields array, any JSON scalars that do not appear in customJSONScalars will be inferred as a TypeScript string.

The JSON scalar types should be entered into this array without any namespacing (simply how they appear in the original GraphQL schema).

JSON scalars that you have defined to be replaced will be automatically inferred as a JSON object. Consequently, these replacement definitions do not need to be explicitly defined in the customJSONScalars array.

Databases

Properties

This configuration applies to the following databases:

  • PostgreSQL
  • MySQL
  • Planetscale
  • SQLite
  • SQL Server
  • MongoDB
1
2
3
4
5
6
7
8
9
10
11
12
13
// wundergraph.config.ts
const db = introspect.postgresql({
apiNamespace: 'wundergraph',
databaseURL: 'postgres://postgres:postgres@localhost:5432/wundergraph',
introspection: {
pollingIntervalSeconds: 5,
},
});
configureWunderGraphApplication({
apis: [db],
});
PropertyDescription
databaseURLThe connection string to the database
apiNamespaceThe namespace of the database
introspectionThe introspection configuration
schemaExtensionA string that is appended to the schema. Useful for adding custom scalars.
replaceCustomScalarTypeFieldsAn array of custom scalar type fields to replace.

Prisma

You can use the introspect.prisma function to configure a Prisma database.

1
2
3
4
5
6
7
8
9
10
// wundergraph.config.ts
const db = introspect.prisma({
apiNamespace: 'prisma',
prismaFilePath: 'path/to/prisma/schema.prisma',
});
configureWunderGraphApplication({
apis: [db],
});

Properties

PropertyDescription
prismaFilePathThe path to the Prisma schema file
apiNamespaceThe namespace of the database
schemaExtensionA string that is appended to the schema. Useful for adding custom scalars.
replaceCustomScalarTypeFieldsAn array of custom scalar type fields to replace.

OpenAPI

You can use the introspect.openApi function to configure an OpenAPI API.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// wundergraph.config.ts
const jsp = introspect.openApi({
apiNamespace: 'jsp',
source: {
kind: 'file',
filePath: '../json_placeholder.json',
},
introspection: {
pollingIntervalSeconds: 2,
},
requestTimeoutSeconds: 10, // optional
});
configureWunderGraphApplication({
apis: [jsp],
});

Properties

PropertyDescription
sourceThe source of the OpenAPI schema. Either a file or a URL.
apiNamespaceThe namespace of the OpenAPI API
introspectionThe introspection configuration
schemaExtensionA string that is appended to the schema. Useful for adding custom scalars.
replaceCustomScalarTypeFieldsAn array of custom scalar type fields to replace.
httpProxyUrlHTTP(S) proxy to use, overriding the default one (if any). Set to null to disable.

GraphQL Federation

You can use the introspect.federation function to configure a GraphQL Federation API.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// wundergraph.config.ts
const federatedApi = introspect.federation({
apiNamespace: 'federated',
upstreams: [
{
url: 'http://localhost:4001/graphql',
},
{
url: 'http://localhost:4002/graphql',
},
],
});
configureWunderGraphApplication({
apis: [federatedApi],
});

Properties

PropertyDescription
upstreamsAn array of upstreams to use for the federation.
apiNamespaceThe namespace of the GraphQL Federation API
introspectionThe introspection configuration
schemaExtensionA string that is appended to the schema. Useful for adding custom scalars.
replaceCustomScalarTypeFieldsAn array of custom scalar type fields to replace.
httpProxyUrlHTTP(S) proxy to use, overriding the default one (if any). Set to null to disable.

SOAP

You can use the introspect.soap function to configure a SOAP API.

1
2
3
4
5
6
7
8
9
10
11
12
13
// wundergraph.config.ts
const greeting = introspect.soap({
apiNamespace: 'greeting',
source: {
kind: 'file',
filePath: './greeting.wsdl',
},
headers: (builder) =>
builder.addClientRequestHeader('X-Authorization', 'Authorization').addStaticHeader('X-Static', 'Static'),
});
configureWunderGraphApplication({
apis: [greeting],
});

Properties

PropertyDescription
apiNamespaceThe namespace of the SOAP API
sourceThe source of the SOAP wsdl. File.
headersThe headers to send with the request
Previous
Overview

Was this article helpful to you?
Provide feedback

Edit this page