Skip to main content

Service APIs

Paraflow tasks can interact with external services that expose a GraphQL interface. The on clause in a Paraflow task declaration specifies the default URL of the GraphQL service endpoint. This endpoint can be overridden for specific calls using the rpc statement.

Example: Calling a GraphQL Service

The following example demonstrates how to invoke a GraphQL service from a Paraflow task:

task !RegisterSeg($id) on "graphql:http://localhost:8000/graphql" {
let { $desc, $lat, $lon } = @getSegmentDetail($id);
insert segment($desc, $lat, $lon);
}

In this example, the task:

  • Queries a GraphQL service at http://localhost:8000/graphql.
  • Invokes @getSegmentDetail($id) to retrieve data, returning an object.
  • Unpacks the object into local variables ($desc, $lat, $lon) via destructuring.
  • Stores these variables in a segment entity.

GraphQL responses typically return objects, which can be assigned to local variables using destructuring. For details on this syntax, see the Variables section.