App Connect

 View Only

Using imported GraphQL APIs in IBM® App Connect

By Deepak Ayilliath posted Wed August 07, 2024 04:28 PM

  

What is GraphQL?

GraphQL is a query language for API’s and a runtime for fulfilling those queries with existing data. GraphQL provides a complete and understandable description of your API's data, giving clients the power to ask for exactly what they need and nothing more.  When sending queries to your API, GraphQL returns a very predictable result, without any over-fetching or under-fetching, ensuring that apps using GraphQL are fast, stable, and scalable.

Integrating IBM App Connect with GraphQL

IBM App Connect simplifies the process of building flows that integrate with GraphQL and other applications. 
The GraphQL connector when uploaded, is displayed with the name the user provides on the App Connect User Interface (UI) with the default GraphQL icon. This integration allows you to perform operations with the imported GraphQL connector and other business applications.
For detailed information about using App Connect with imported GraphQL APIs, see How to use IBM App Connect with imported GraphQL APIs on the IBM documentation webpage.

Supported operations with GraphQL Connector

The objects can be dependent on the GraphQL schema that you are using. You can use App Connect to perform actions on these objects. The operations supported for the GraphQL schema objects will be modeled into the operations in App Connect.

Objects Supported operations Comments
Basic GraphQL connector objects Create, Retrieve, Update, Delete, and other operations

Operations like create, update, delete, and retrieve all are performed on the object as per the support in the GraphQL schema.

Custom GraphQL query object Custom GraphQL queries and mutations can be run independently of the object You will be able to execute the custom queries and see the response in the StepZen server. This allows running custom queries and mutations, providing the flexibility to fetch or modify data beyond the predefined operations in the schema.

Use case: Connecting Star Wars database with StepZen (IBM API Connect Essentials)

Customers can use StepZen's powerful introspection capabilities to create GraphQL APIs for their data sources. The StepZen SDL, which specifies the GraphQL schema, can be imported into the App Connect Designer to create a connector, enabling smooth interaction with the StepZen GraphQL API endpoint.

How it works

Image representing how GraphQL and App Connect work together
The data source we are using here is a database for Star Wars. Star Wars is a highly influential and popular science fiction franchise created by George Lucas. If Star Wars were represented as a database schema, the entities would encapsulate the major elements of the universe, such as Planets, Starships, Species, Events, Droids, weapons, and so on.
To achieve our goal, we need to retrieve specific details about a planet in the Star Wars universe by filtering it using the planet's ID and name.
The first step is to import the StepZen SDL schema into the App Connect.

Setting up the Star Wars database connection

1. Importing the StepZen SDL Schema

  1. In App Connect, click on the + button to navigate to the import schema screen.
    App Connect UI 'Add connector or API button'
  2. Select Import a connector file or API document, and then click Next.
    App Connect UI 'Import or discover' page
  3. Set the document type to GraphQL.
    App Connect provides an option for importing the GraphQL SDL. We import the SDL for the Star Wars schema.
    Selecting GraphQL API as the document type and uploading the .graphql file
  4. Click Next.

2. Validating the schema:

  1. Provide a name and description for the connector (for example, StarwarsConnector), which will be added to the App Connect.
    Star Wars connector containing list of supported objects
  2. Click Import connector.
    App Connect validates the schema and displays metadata, listing supported objects and actions. You can see a GraphQL connector with the name StarwarsConnector listed on the App Connect Catalog page.

3. Connecting to the endpoint:

  1. Provide the GraphQL server URL and API key for authentication.
    GraphQL connector connection fields
  2. After entering your credentials, you will see that an account has been added.

4. Creating a flow to search for a planet:

  • Now, imagine that you need to gather details about the planet using its ID and name. To do this, we will start by going to the App Connect dashboard and creating a new flow. We have named this new flow 'starwars-planet-search'. 
  • Then, we go to the Planets object and click on the Planet by ID and name action.
  • A planet ID and name are provided in the fields.
  • After clicking Test action we will receive the following response:
    GraphQL connector action and results

5. Running custom GraphQL queries:

  • We can perform the same action using user-written queries as well. For that, we have to choose the Custom GraphQL query object from the list of objects for the StarwarsConnector, and select Run custom GraphQL query.
  • After clicking Test action on Run custom GraphQL query action we can obtain the same results as the previous action by explicitly providing the GraphQL query in the Custom GraphQL query field.
    Run custom GraphQL query action and results


Video explaining the GraphQL file import process and the use case in App Connect

Useful resources

  • Get started with a free IBM App Connect Enterprise as a Service trial for 30 days to try out these features, visit https://ibm.biz/app-trial.
  • Visit the IBM Automation Explorer page to discover and access various integration assets, including connectors and templates.

#AppConnect#graphql #stepzen

0 comments
29 views

Permalink