Skip to main content

I am in the process of working on an integration between Cityworks and ArcGIS Urban. While I am well-versed in using the HTTPCaller transformer for REST APIs in FME Desktop, after s few hours of working with an HTTPCaller, the only way I was able to make a GraphQL API call was using a PythonCaller with some custom code using the requests library.

 

For now, the PythonCaller route will work well enough, but I would rather lean on the HTTPCaller for when others have to take over this integration who are not Pythonistas.

Having never used or heard of GraphQL, and after having a 2 minute look through thier documentation, i'm going to say maybe? This document (https://graphql.org/learn/serving-over-http/) talks about setting up a GraphQL server and then being able to make calls to it. The setting up of the server will likely have to be external to FME but once thats setup it seems like you should be able to use the httpcaller to make calls to the server


Having never used or heard of GraphQL, and after having a 2 minute look through thier documentation, i'm going to say maybe? This document (https://graphql.org/learn/serving-over-http/) talks about setting up a GraphQL server and then being able to make calls to it. The setting up of the server will likely have to be external to FME but once thats setup it seems like you should be able to use the httpcaller to make calls to the server

Hello, did you ever figure this out without Python and using httpcaller? We are looking at implementing graphql and I wouldn’t want to make things more difficult for ourselves if httpcaller doesn't work with it!


I just wanted to update this post with a solution, in case others are interested in GraphQL. With a bit of formatting, GraphQL can be used with the HTTPCaller.

 

The following example requests are all made to the Github GraphQL, since it's free and has pretty good documentation. I followed the example from the Mutation from Forming calls with GraphQL doc:

query FindIssueID {
  repository(owner:"octocat", name:"Hello-World") {
    issue(number:349) {
      id
    }
  }
}
 
mutation AddReactionToIssue {
  addReaction(input:{subjectId:"MDU6SXNzdWUyMzEzOTE1NTE=",content:HOORAY}) {
    reaction {
      content
    }
    subject {
      id
    }
  }
}

 

Using Serving over HTTP as somewhat of a guide, I used the POST body with Content Type set to application/json. Any GraphQL statement will need to be reconfigured as JSON, with the statements inside their key-values:

{
 "query": "...",
 "operationName": "...",
 "variables": { "myVariable": "someValue", ... }
}
 

That article doesn't mention escape characters, but we will need them to send GraphQL requests by HTTP (otherwise we run into JSON parsing errors).

 

You might format this in FME using the AttributeEscaper or StringReplacer. But I used Postman to automatically apply escape characters to the GraphQL statement. In Postman, just set up a POST request, change the body to GraphQL, paste the statement as-is, then select "Code Snippet" with HTTP. Copy the formatted request body to the HTTPCaller upload data. Here's a quick demo: 

Finally, I set up the example request like this and it worked: 

httpcallerI've attached an example workspace. The queries will need to be updated for your own Github account, if you want to try this example out. 


Hi there sanaeatsafe - is this sample workspace still available? I cannot see the attachement?

 

Thanks


Hi @ian_1spatial, thanks for reporting the broken attachment. I’ve re-uploaded it to Sanae’s answer above. 


Many thanks @LizAtSafe . I am currently working on a project using Monday.com’s Graph QL api with an HTTP caller and will respond properly with my thoughts when it is completed. 

The good news is that I was successfully able to connect :D


Reply