Calling GraphQL API using Mulesoft

Calling GraphQL API using Mulesoft

To call GraphQL API, we don't need to use any specific connector, we can use the Request operation from HTTP connector. GraphQL API's are consumed with HTTP POST request. For this demo we will be consuming https://api.spacex.land/graphql/

The payload body for POST Request should be JSON object containing properties - 'query' and 'variables'. The 'query' is your GraphQL query and variables are variables that are referenced in this 'query'.

Step 1: Create a New Mule project which listens to GET on /graphql

No alt text provided for this image

Step 2: Prepare the payload to the request component containing properties 'query' and 'variables'.

No alt text provided for this image

Step 3: Configure Request from HTTP connector for POST to your GraphQL API URL with payload set to payload prepared in Step 2.

No alt text provided for this image
No alt text provided for this image


No alt text provided for this image

Run your project and call your API through Postman. You will be able to see response -

No alt text provided for this image

To view or add a comment, sign in

More articles by Abhishek Bajpai

Insights from the community

Others also viewed

Explore topics