This document covers how to query and get the required response in GraphQL Playground or Postman.
About SFO API Endpoints as per Schema.org Standards
Schema.org is a collaborative, community activity with a mission to create, maintain, and promote schemas for structured data response.
Based on the organization of schemas, the following new endpoints have been introduced under the Storefront Orchestration (SFO) microservice for GraphQL:
- getSchemaOrgCategoryById
- getSchemaOrgListOfProducts
- getSchemaOrgProductById
- getSchemaOrgProductList
- getSchemaOrgSearch
- getSchemaOrgProductByIdAndPromotion
For more information, see API Endpoints – SFO.
GraphQL Queries
Fields
Each field can contain zero or more arguments and each argument can contain a name and a type.
The following screen shows a simple query and the result after running the query.
In the above example, the query has the same structure as the result. This is essential to GraphQL, because you always get back what you expect, and the server knows exactly what fields the client is asking for.
Here, searchTerm and suggestion are fields.
Arguments
In GraphQL, every field and nested object can get its own set of arguments. For example, “searchTerm” and “storeID” are the arguments passed to the field ‘getSuggestion’ as shown in the screen below:
Object Types and Fields
The most basic components of a GraphQL schema are object types, which just represent a kind of object you can fetch from your service, and what fields it has. In the GraphQL schema language, we might represent it like this:
type Character { name: String! appearsIn: [Episode!]! } |
The language is pretty readable, but let’s go over it so that we can have a shared vocabulary:
- Character is a GraphQL object type, meaning it’s a type with some fields. Most of the types in your schema will be object types.
- name and appearsIn are fields on the Character type. That means that name and appearsIn are the only fields that can appear in any part of a GraphQL query that operates on the Character type.
- String is one of the built-in scalar types – these are types that resolve to a single scalar object and cannot have sub-selections in the query. We will go over scalar types more later.
- String! means that the field is non-nullable, meaning that the GraphQL service promises to always give you a value when you query this field. In the type language, we will represent those with an exclamation mark.
- [Episode!]! represents an array of Episode objects. Since it is also non-nullable, you can always expect an array (with zero or more items) when you query the appearsIn field. And, since Episode! is also non-nullable, you can always expect every item of the array to be an Episode object.
Querying GraphQL APIs and Fetching the Response
You can identify three sides in the screenshots given below:
LEFT SIDE (selecting the required fields & entering required arguments: Here, you can see you can simply select the desired fields and provide the correct arguments (by typing) for fetching the required response which can be seen on the right side.
The “*” means that it is a mandatory field.
RIGHT SIDE (Response Fetched): On the right side, you can see the response generated after running the query.
CENTER (Query Generated After Selection): The center part shows the query generated after selecting the required fields from the left side. The center panel shows the query which can be used, and you will be using the POSTMAN for executing and validating the same queries.
Querying getSchemaOrgCategoryById
Validation Using Postman
The Query
Here, you must provide the base URL with the POST method. Also, provide the query generated by GraphQL inside the Query box.
The Response
You can see that the response is the same as GraphQL.
Querying getSchemaOrgProductById
In the screenshot below, you can see that you can provide a key (marked in red) to display only the “altImage1”. Otherwise, there are three other alternate images named “altImage2” and “altImage3”.
Validation Using Postman
The Query
The Response
Querying getSchemaOrgProductList
Here, you get the product list after entering the desired values. In the screenshot below, you will see page: 1 and size: 5 (which implies 5 products will be shown on the page).
Validation Using Postman
The Query
The Response
Querying getSchemaOrgSearch
Here, you are providing the search term in the searchTerm argument, and the related products along with the selected fields like additional properties, IDs, brand names, etc. are generated in the response as shown below.
Here searchTerm (marked in red) used is “jean”.
Validation Using Postman
The Query
The Response
Querying getSuggestion
Here, you are generating search suggestions with searchTerm=: “shirt”. The SuggestionAPIResponse is selected, which gives suggestions for the searchTerm.
Validation Using Postman
The Query
The Response
Revision History
2023-06-14 | JP – Page added and content uploaded.