Fluent Commerce Logo
Docs

GraphQL Operations

Essential knowledge

Author:

Fluent Commerce

Changed on:

16 Oct 2024

Overview

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. It provides a complete and easy-to-understand description of the data in your API. Its ability to return select fields enables it to be used with powerful developer tools and ensures that APIs are easily scalable.Fluent's GraphQL API has two operations:
  • Queries 
  • Mutations
Queries include predefined Queries and Custom Queries, both of which will be covered below.

Key points

  • Operations
  • Queries
  • Mutations
  • Custom Queries

Operations

No alt provided


Queries

Query operations are used for retrieving data. Fluent's GraphQL API has two types of query operations:
  • Get Operations
  • Search Operations
Get Operations
Get operations always return a single result. These operations should be used when a unique identifier for the object to be retrieved is known. This can be an ID, ref (reference), or both in conjunction. In some cases, it can also be defined by something else. Refer to the GraphQL Queries page for more details.
Examples
Search Operations
Search operations filter out objects of a given type. They should be used when searching for objects that meet one or more criteria. An example of such an operation would be to search for and get all Orders of type "HD." Search operations are also great for reporting on particular types.
Example
Additional Information
To pass schema complexity validation, all GraphQL API operation queries must meet the following standards:
  • Search queries should be supplied with a first or last argument. The query will only return the first 10 records if these arguments are not provided.
  • Values of first and last must be within 1 - 5,000. If the value exceeds 5000, it is replaced by 5000.
  • Queries must have a complexity value of under 11,111, as those that exceed it will not be executed.


Mutations

GraphQL operations used to create or update data are called Mutations. The Fluent GraphQL API provides three types of mutations: Create, Update, and Remove.Mutations return an object type. The user can specify which fields they want to be returned.
Examples


Custom Queries

Custom queries are special queries available through the Fluent GraphQL API. With custom queries, the server processes the input and applies some logic to it before returning the output. This logic can be either queries or mutations.Although it is preferred to keep the Fluent GraphQL servers simple and let Orchestration handle any complex logic, there are times when custom queries are necessary to improve performance and reduce overall complexity.The Fluent GraphQL API now supports two custom queries- SearchVirtualInventory and ArticlesByLocation.
Example - SearchVirtualInventory
This query returns up to 10 of the nearest locations that can entirely fulfill a set of items based on available-to-sell stock in a given Virtual Catalog. Targeted use cases include fulfilling an order with no splits (as locations that require a split will not be returned) or showing a list of stocked pickup options to a customer in a product page or checkout scenario.
Example - ArticlesByLocation
This query returns the articles currently en route to or awaiting collection from a given location or set of locations. Either 'fromLocation' or 'toLocation' should be provided.