Jump to content
  • Building a GraphQL App with Flogo


    Hugo Peters

    Table of Contents

    What is Flogo ?

    Project Flogo is a resource efficient, Go-based open source ecosystem for building event-driven integration apps. Flogo flows can be visually configured to implement integration applications very quickly, hence reducing time to market. For more information on Flogo and getting started with it's development have a look at this article:

     

    TIBCO Cloud Integration Getting Started with Develop

    What is GraphQL ?

    GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. For more information see:

     

    GraphQL.Org

     

    Creating the Application

    Now we know what Flogo and GraphQL is, let's get started. First we will create a new Empty Flogo Application:

     

    1_EmptyApp.thumb.png.152a5ae2bd3f7735cca0d337b4bac299.png

     

    You can provide a name for your application in the left top. In the next step we will create new Flogo flows based on the GraphQL Schema:

     

    2_Schema.thumb.png.dddde1c9fdb7d781b06d1eccc7b90317.png

     

    You can Drag and Drop the schema onto the canvas to get started. I used this example schema:

     

    https://github.com/project-flogo/graphql/blob/master/samples/Example2.gql

     

    Now all the flows will automatically be generated:

     

    3_GeneratedProcesses.thumb.png.cbdf0a9af6d4e53b551b8d0660af07e3.png

     

    Now we need to create the implementation of these processes, in this application we make use of shared data to store the added post to the Application Scope. Therefore it is important to select application scope on the shared data activity:

     

    4_sharedScope.png.7e1032f8cf363866bd9e46d8e5b07d5f.png

     

    Now we can deploy the application and test it with queries. You can download the Flogo Json Attached to this Article

     

    Testing the Application with Various Queries

    For this we will use PostMan to test but if you don't have PostMan you can also test your queries online, by using this website for example:

     

    https://www.graphqlbin.com/v2/new

     

    When the app is deployed we need to get the endpoint URL, which we can copy in the UI:

     

    5_GraphQLEndpoint.thumb.png.0b920d143d63164ab51e5b0554e5f7d4.png

     

    Now in PostMan we create a new Request and it is important to add the endpoint of the trigger to the copied endpoint. We can get the trigger endpoint at the trigger configuration:

     

    6_TriggerEndpoint.thumb.png.cc3ce6e2f8b0a96c01cdb926bb9e24a8.png

     

    So the endpoint we use in PostMan is for example:

     

    https://eu-west-1.integration.cloud.tibcoapps.com/xyz/graphql

     

    Now we can use the following Mutation to add a post:

      mutation {      CreatePost (postObj: {          title: "My First Post"          body: "This is my first post"          userId: 123      })  {postId} } 

    The result will look like this:

     

    7_CallMutation.png.d5da7e08cbc8ddbc449991d71613aeb1.png

     

    And after we have created some posts, we can query the created posts with the following query:
      {     GetPosts(userId: 123) {         title,         body,         postId,     } }

    The result will look somewhat like this:

     

    8_GraphQLQuery.png.d92b4a0ed94816aa2ba901dce425d7c7.png

     

    Congratulations you have now created a Flogo App that does GraphQL Queries and Mutations !

     

    Hugo Peters - Product Management

     

    FlogGraphQLDemo1.json


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...