Build a Tool from Your Data Source
With watsonx.ai Flows Engine, you can turn any data source (REST APIs, GraphQL, Databases) into a tool you can use with an LLM. To build a tool, you need to have the watsonx.ai Flows Engine CLI installed and sign up for a free account.
Import Your Data Source
The data sources used as tools should be specified as a GraphQL schema. To generate a GraphQL schema for your data sources, you should use API Connect for GraphQL (formerly StepZen). With API Connect for GraphQL, you can either use the CLI or create GraphQL schemas from scratch.
Using the CLI
You can use the API Connect for GraphQL CLI to generate a GraphQL schema for the following data sources:
To use the CLI, you need to have Node.js and npm installed on your machine.
1. Install the CLI
npm i stepzen -g
2. Run the
stepzen import curl
stepzen import openapi
stepzen import graphql
stepzen import mysql
stepzen import postgresql
stepzen import snowflake
You can append the
3. Modify the generated files:
After importing your data source as a GraphQL file, you can make changes to the generated
4. Proceed to registering your tool(s):
Finally, go to the next section to learn how to register your tool(s) and make them available for use in your application.
In some cases, you may need to write the GraphQL schema manually. This is necessary when using data sources not supported by the CLI (like MSSQL, Presto, Singlestore, Trino, or SOAP/XML) or when importing your supported data source fails due to authorization constraints like self-signed certificates.
Write a GraphQL Schema
If you choose not to use the CLI, you can write the GraphQL schemas for your data sources manually. This requires using a custom directive to connect to the data source. You can find detailed information about creating schemas with custom directives here.
Below is an example of a GraphQL schema:
type Customer {
email: String
id: ID
name: String
}
type Query {
customerById(id: ID!): Customer
@rest(endpoint: "https://introspection.apis.stepzen.com/customers/$id")
}
In this schema, the
Any
schema
@sdl(files: ["custom/index.graphql"]) { # Add your file here
query: Query
}
The following custom directives are currently supported:
- @rest
- @graphql
- @dbquery
After writing the GraphQL schema, proceed to the next section to learn how to register your tool(s) and make them available for use in your application.