What is GraphQL?

GraphQL is a strongly typed API query language that provides an alternative to REST. It allows clients to define the structure of the data required, and exactly the same structure of the data is returned from the server. This avoids both the problems of over and under-fetching data while also allowing for a more powerful and flexible API.

By defining your own GraphQL query, you can get exactly what you need, nothing more and nothing less. This enables a fast, efficient, and, most of all, stable service.

Making a GraphQL API Request

In GraphQL, there are two possible invocation types; both are POST requests:

  • Query - the string you send to the server to process and request data.
  • Mutation - the argument used to modify server-side data.

Sample Query Request

query Example { # the type of request query/mutation organizationTrackedShipments{ # the name of the requested query id # a field that returns a scalar shipment{ # a field that returns a fragment containerNumber # a field that returns a scalar bol # a field that returns a scalar scac # a field that returns a scalar } } }

The request will return the following JSON response:

{ "data": { "organizationTrackedShipments": [ { "id": "62124e6220912bbfa2a21072", "shipment": { "containerNumber": "HMMU6089356", "bol": "OOLU2127093310", "scac": "HDMU" } } ] } }

Sample Mutation Request

mutation Example { # the type of request query/mutation deleteTrackedShipments( # the name of the requested mutation trackedShipments: [{ # the mutation input (argument) id: "61d6ae9d687bea0857451d86" }]) # the input field }

The request will return the following JSON response:

{ "data": { "deleteTrackedShipments": true } }