Boomi

Creating API Plan using GraphQL Mutation

Mutations in GraphQL API

In this blog, you will learn how mutations of GraphQL APIs will help us to modify the server-side data in API Management. In order to showcase the concept of mutations we will create one API Plan using GraphQL mutation.

What is a GraphQL API?

  • GraphQL is an open-source data query and manipulation language for APIs, as well as a runtime for fulfilling queries with existing data.
  • GraphQL APIs are built based on GraphQL code.
  • GraphQL is designed to address the issues of over-fetching and under-fetching of data, which are common challenges associated with traditional REST APIs.
  • GraphQL allows you to make multiple resource requests in a single query call. Saves time and bandwidth by reducing the number of requests to the server.

Mutations:

  • In GraphQL, mutations are operations used to modify or manipulate data on the server.
  • While queries are used for reading the data, mutations are used for creating, updating or deleting data.
  • Mutations allow clients to request changes to the data and receive a response to confirm the success or failure of those changes.

Here are some key components of mutations in GraphQL

Syntax:

Mutations have a syntax similar to queries but are defined using the mutation keyword. They

include a set of fields that represent the data to be modified.

Input Variables:

Mutations often include input variables to pass data from the client to the server. This allows for dynamic and reusable mutation operations.

Response:

Like queries, mutations specify the fields they want in the response. The server returns the requested data after applying the mutation.

Error Handling:

GraphQL mutations include error handling. If a mutation encounters an error, the server returns an error object that includes details about what went wrong.

 Overall mutations in GraphQL provide a flexible and efficient way to modify data on the server while allowing clients to precisely request the data they need in response to the mutation.

Now we will see the GraphQL API Management APIs in Boomi.

GraphQL API Management APIs:

  • The Boomi API Management GraphQL APIs expose many GraphQL queries and mutations to retrieve and update data.
  • It is a new implementation for API Management. You can make queries and mutations to the Gateway settings.
  • The GraphQL API Management APIs provides programmatic access to functionality that is normally accessed through the API Management service.
  • Programmatic access to GraphQL APIs is available through any applications like Altair, Postman, GraphQL Client.
  • There is also a service provided in Boomi to execute GraphQL Queries and mutations i.e., API Explorer.
  • To leverage the GraphQL APIs, we must first enable it for the API Gateway and runtime containers. When we enable API Metrics, it applies to all Gateways in your account.

Enabling API Metrics Data Collection

From the Boomi platform, go to Settings>Account Information and setup. From the left navigation select Features.

Switch the API Metrics and Dashboard Access to the ON position.

API Explorer:

  • API Explorer is a resource provided by Boomi which allows us to interact with GraphQL API endpoints and execute GraphQL code i.e., queries and mutations within the platform instead of from third-party tools such as Postman and Altair.
  • By default, API Explorer is disabled. We can enable it under Settings > User Information > Preferences tab.
  • After enabling, to launch API Explorer, select Resources>API Explorer from Boomi platform menu bar.
  • The UI of API Explorer will look as shown below.

The API Explorer screen has different parts. From the top-left, you will see the Actions Buttons. Below these, you will find the Editor. From the Top-Right you will find the Docs button. Below is the Output pane. Finally, at the very bottom of the screen, you will see the Query Variables pane.

Now we will execute a mutation which will help us to create a plan in API Management.

Follow the below steps for the successful creation of plan using GraphQL mutation.

Steps to create Plan

Step 1:

Refer to the below link in Boomi documentation to understand the syntax of mutation which is used to create a Plan.

https://help.boomi.com/docs/Atomsphere/API%20Management/Topics/api-deployed_api_plan_category_d0596786-3535-44b7-9a20-366109708add

Step 2:

Create a mutation as shown below.

mutation {
  deployedApiPlanCreate(

createPlan: {name: ” API_Plan”, maxMessageSize: “100000000000”, rateLimit: “9”, rateLimitPeriod: MIN, quotaLimit: “90”, quotaLimitPeriod: DAY}

  ){
    id
    name
    description
    maxMessageSize
    rateLimit
    rateLimitPeriod
    quotaLimit
    quotaLimitPeriod
    quotaLimitTimezone
    status
    applicationCount
}

}

Step 3:

Copy and paste the query in the query pane and click on execute.

Step 4:

The complete API Explorer will look as shown below. We can see the response in the output pane.

Step 5:

This is the response we can see in the output pane. We can see the status of the executed query. Our plan was created with a unique id and the status as “ENABLED”. This represents that the query got executed successfully.

Now we have to confirm by checking in API Management > Configure Server > Plans

Step 6: 

Go to Services and choose API Management.

Step 7:

Under Configure Server choose Plans.

Step 8:

Search for the plan which you have created just now. We can see that our “API_Plan”

got created.

Step 9: Expand the plan by clicking on the down arrow.

We can see all the plan details which we have configured in the query.

Step 10:

Click on Edit. We can see the plan Id in the browser search bar whose value is exactly same as the Id value which we got in the query response.

(For reference compare both the values)

 Conclusion:

This is how we can create Plan using GraphQL mutation.

For more information, please find the below reference links.

References:

Author

Sowjanya gurrala

Leave a comment

Your email address will not be published. Required fields are marked *