Check out this easy step by step flow to integrate GraphQL with Outsystems.
Learn more about GraphQL
https://medium.com/@joshuasalema/introduction-to-graphql-integration-with-outsystems-11-f46d1d8f25ae
Integration of GraphQL API’s with Outsystems 11
Outsystems provides support for REST and SOAP based API’s. There is no native support to integrate complex GraphQL API’s in Outsystems. Let us see how we can achieve this using the steps below:
For this example lets use Shopify GraphQL Storefront API’s and integrate it with Outsystems using the steps below:
1. Integrating GraphQL queries
Let us use the query below to obtain the checkoutURL for a particular cart id.
To the left is a GraphQL named query titled “checkoutUrl” which takes an id as an input and returns the checkoutUrl and id as the response. Outsystems supports payloads in JSON formats and will immediately throw an error if we try to supply payload as a named query. Hence our only option is to supply the request as a string instead of JSON. However, since the checkoutUrl is a string and by default it will result in errors due to conflicting quotation symbols.
Transform the named query into JSON format
Let us use the format below and transform the query into JSON format. The payload below is in JSON format (supported by Outsystems) and it expects an input parameter named id which is supplied through the variables section. The operation name indicated the name of the query.
After executing the above transformed JSON GraphQL query we get the below response :
2. Integrating GraphQL mutations
Let us use the query below to create a cart on the Shopify store via a mutation:
Since mutations are not in JSON format Outsystems will not support it by default. However, we can transform the mutation to use the query and variable approach in JSON format. Although, we are transforming the mutation into a query , GraphQL would still treat it as a mutation and execute it appropriately without any errors.
In the above example $cartInput is a variable and it consists of 3 properties i.e lines, buyerIdentity and attributes. By default Outsystems will not accept a mutation in the payload as it is not in JSON format. Hence we need to transform the mutation and use variables to avoid passing parameter values like buyerIdentity as string values. We can pass these parameters using variables.
Create Server Actions and consume both these API’s
We transformed the GraphQL query and mutation in JSON format using variables . While consuming these after dropping the API server actions on screens Outsystems treats the GraphQL payload as a JSON payload and generates the request structure in JSON format. All that we need to do is expand the JSON structure and supply the necessary input parameters to get our API working. Thats It ! By following these simple steps we can easily integrate GraphQL API’s easily with Outsystems without any external tools.
Very noice!
Thank's @Anderson! hope it help you speed up development.
Hi @Joshua Salema
Thank you for explaining step by step integration with GraphQL Api.
Although I am stuck with one step which is of converting mutation query into JSON format. I am not able to convert it due to which getting errors. I needed help in understanding how to convert the mutation query into JSON format.
Did you convert using some kind of a format or is there any tool where we can convert it. Please guide.