Skip to main content

Command Palette

Search for a command to run...

Syncloop - GraphQL Use Case

Published
•4 min read•View as Markdown
S

Revolutionize your API development with Syncloop's drag-and-drop UI and one-click deployment. Try it for free and save up to 65% of development time.

This documentation provides a guide on how to use Syncloop's GraphQL interface to interact with the Syncloop platform.

To create an API, follow these steps:

  1. Right-click on the "Packages" directory ↦ New ↦ Packages.

  2. Create a new folder under Packages and name it GraphQL.

  3. Within the GraphQL folder, select Services ↦ API.

Creating a MAP

To create a MAP, follow these steps:

  • Navigate to the Workspace ↦ Right-click within the Workspace.

From the context menu that appears, select the option labeled Map.

Output Schema

To define the output schema, we need to create two string values: URL and method.

URL: The URL should be set to the external API URL from which we intend to retrieve data. As an example for this tutorial, we will use "https://restcountries.com/v3.1/name/india" as the URL.

Method: The method value should be set to "GET" to specify the type of request we will be making to the API.

Creating an HTTP Request Service

To create a new HTTP Request Service, follow these steps:

  1. Right-click in the workspace and select Service from the context menu.

  2. Navigate to the Packages section and search "request" and select it.

Mapping the Request Service

  1. Map the URL to the url field and the method to the method field.

  2. In the output schema, create a respPayload (response) field. Please ensure that you map the desired response payload to this existing respPayload field.

By following these guidelines, you can accurately define the URL and method in the API request, as well as map the desired response payload to the existing respPayload the field in the output schema.

Creating a fromJson Service

To create a new fromJson Service, follow these steps:

  • Right-click in the workspace and select Service from the context menu.

  • Navigate to the Packages section and search "fromJson" and select it.

Mapping the fromJson Service

  • Map the respPayload (Response Payload )to the jsonString field.

  • Under the output section, create a new document called jsonDoc. Additionally, create another document under the OUTPUT SCHEMA section called countries.

  • Map the content of jsonDoc to the countries document.

    Document Types

    Both jsonDoc and countries should be of type Array.

Creating a JSON Form

To create a JSON Form, follow these steps:

  1. Navigate to the Output Parameters section on the left side of the Workspace.

  2. Right-click in the Output Parameters section and select FORM from the context menu, then choose JSON.

  3. Copy the desired payload into the form. For example, you can use the payload from the following API endpoint: https://restcountries.com/v3.1/name/india

Setting up the GraphQL

Enabling the GraphQL

To enable GraphQL, navigate to the configuration settings and check the "Enable GraphQL" option.

Service Endpoint and Bearer Token

  • Select Configuration ↦ Service Endpoint.

  • Copy the Service Endpoint.

  • Click on API Token in the left navigation bar. ↦ Bearer Token

  • Copy the Bearer Token

Congratulations on successfully setting up the external API implementation of GraphQL in the Syncloop Platform!

Now, let's move on to using Postman to test our workflow.

Testing Workflow

To Test the Workflow:

  1. Paste the Service Endpoint URL and ensure that the HTTP method is set to POST.

  2. Navigate to the AUTHORIZATION section and locate the BEARER TOKEN field and paste the TOKEN.

  3. Finally, click on the SEND button to initiate the request and observe the workflow execution.

You will be presented with the following output:

To test the GraphQL functionality, please follow the steps below:

  1. Navigate to the "BODY" section of the API request.

  2. Locate the "GRAPHQL" field and click on it.

  3. Paste the GraphQL query into the designated area. (In this query, we will be searching for the capital)

{
    countries {
        capital
    }
}

Now, click on the SEND button to initiate the request.

You will be presented with the following output:

Congratulations! You have successfully tested GraphQL by implementing an external API.

We hope you find this documentation helpful and user-friendly.

More from this blog

Untitled Publication

27 posts