Examples for GraphQL-Queries and Mutations

Here you can find examples for GraphQL-Queries and mutations to try out with one click. The database of the GraphQL service is reset periodically, so you can change the data with mutations as you like.

1. Queries

1.1. Return all Objects of a Type

The query below returns a list of products with their names. You can use the methods categories , customers , vendors and orders as well.

Query returning all products

{ products { name } }


1.2. Searching by ID

Use one of the methods mentioned above but with an id as argument.

Query returning product with id 7

{ products(id: "7") { name } }


1.3. Selection of Subfields

The returned objects are JSON-objects that can be quite complex. The fields of an object can itself be a JSON-object with fields of its own and so on. In a query you can specify which of these fields and subfields you want to return. If a field has subfields you have to make a selection of these subfields in order for the query to work.

Query returning price and name of a product

{ products(id: "8") { price name } }


Query returning category and vendor of a product

{ products(id: "7") { name price category { name } vendor { name } } }


1.4. Multiple Levels of nested Subfields

By selecting subfields you can build queries that have deep levels of subfield nesting. You can even include circles of subfields.

Query with nesting categories -> products -> vendor -> products

{ categories(id: "1") { name products { name vendor { products { name } } } } }


1.5. Filtering Fields

Besides the id you can give query methods additional arguments. The methods then only return objects which have in their fields values corresponding to the values of those arguments.

Query returning all vendors who sell a certain product

{ vendors(productname: "Coconut") { name } }


Query returning all products with price 3.4

{ products(price: 3.4) { name } }


Query returning products with price 1.1 and category 1

{ products(price: 1.1, categoryID: 1) { name price category { name } vendor { name } } }


2. Mutations

For the queries shown so far GraphiQL automatically started the query after a click on "Send Query". For the following mutations "Send Query" just opens GraphiQL and you have to send the Query yourself by clicking on the arrow symbol.

2.1. Add Mutations

You can add new objects of the main types with the corresponding add mutations. If you do this you have to provide all attributes for the object.

Query adding a category products 8, 2, 3

mutation { addCategory(id: 6, name: "Green Fruits", products: [8, 2, 3]) { name products { name } } }


2.2. Update Mutations

Changes an object of a type specified by the provided id. You can change all or just certain attributes depending on which attributes you provide. The state of the object after the modification is returned as well.

Query changing name und products of the category with id 1

mutation { updateCategory(id: 1, name: "Juicy Fruits", products: [7]) { name products { name } } }


2.3. Delete Mutations

Deletes object with provided id. The deleted object gets returned.

Query deleting a category

mutation { deleteCategory(id: 2) { name }