Skip to content

Developers · GraphQL

GraphQL Examples

Last updated 2 November 2026

To learn GraphQL fast, read the schema documentation on the right side of the GraphQL editor in the CLI’s browser interface. Open it with: . This documentation helps you see an overview as to what the functions and parameters you can use.

Having said that, there certainly is a limit to how much you can learn by reading the documentation - hands-on coding is still the best way to learn. A helpful tip while writing code: Maximize the auto-complete feature built-in on the graphQL GUI. While typing, press CTRL+Space on a PC or Option+Space in macOS. If nothing comes up on the selection, it means there’s something wrong on the previous line of code that needs to be changed.

Best Practices

  • Always paginate your data. There is no hard limit on Insites’ data records per page, however the more data there is, the slower querying and processing will be.
  • Utilise snake case for file names, form names, graphQL names, among others. Use dash-separated names for slugs or URLs.
  • Use an ‘alias’ on your graphQL queries as there are different graphQL function names which will be part of your return data. By using a standard alias (For example: ‘items’ on the sample below), you can standardize your data processing on the front-end (specially for ‘query’ graphQL). Aliasing also protects your code if you need to change the query later, for example after an Insites platform release with breaking changes.

Example:

query user_list (
  $page: Int = 1, ## Page number on the pagination
  $size: Int = 10, ## Items returned per page
  $id: ID,
  $email: String
) {
items: users (
  per_page: $size
  page: $page
  filter: {
    id: { value: $id }
    email: { value: $email }
  }
) {
  total_entries
  total_pages
per_page
  current_page
  results {
    id
    email
    first_name
    last_name
    email
  }
 }
}

The examples below pass table, profile and property names as variables, such as with the value . You can also write a name straight into the query as a string in double quotes.

Query Examples

The following examples demonstrate GraphQL queries for operations such as listing, searching, and sorting. They are largely analogous to 'GET' and 'SELECT' operations.

1. Single Source - User

query get_users ($page:Int = 1, $size:Int = 10) {
 items: users (
   per_page: $size
   page: $page
 ){
   total_pages
   total_entries
   per_page
   current_page
   results {
     id
     first_name
     last_name
  	 email
     profiles {
         profile_type
         properties
     }
   }
 }
}

2. Single Source - Record

query get_record_data (
  $page:Int = 1,
  $size:Int = 10,
  $table: String!, ## for example: sample_record
  $field_1: String!, ## for example: sample_field_1
  $field_2: String! ## for example: sample_field_2
) {
items: records (
  per_page: $size
  page: $page
  filter: {
     table: { value: $table }
  }
){
  total_pages
  total_entries
  per_page
  current_page
  results {
    id
    record_name: table
    properties # properties lists all fields that have data

    ## You can get specific field(s) by using property and passing the field name
    ## Use proper aliasing to know which data is which
 	field_1: property(name: $field_1)
    field_2: property(name: $field_2)
  }
 }
}

3. Filtering and Sorting - User

query get_users (
  $page:Int = 1,
  $size:Int = 10,
  $email: String,
  $keyword: String,
  $profile_type: String!, ## for example: sample_user_profile
  $field: String! ## for example: sample_field_1
) {
items: users (
 per_page: $size
 page: $page
 filter: {
  ## Filter / search users whose email equals $email
  email: { value: $email }
  profiles: {
    name: $profile_type
    properties: [
      ## Filter / search users with the $profile_type profile
      ## whose $field property matches $keyword exactly
      { name: $field, value: $keyword }
    ]
  }
}
## Sort by user email alphabetically
 sort: {
   email: { order: ASC }
 }
) {
 total_pages
 total_entries
 per_page
 current_page
 results {
     id
     first_name
     last_name
     email
     profiles {
         profile_type
         properties
     }
   }
  }
}

Important:

  • As you nest your graphQL, this will behave as an AND statement.
  • If you do not pass a parameter value, it will run the query and not consider the filter criteria the parameter was used (For example: In the example below, ‘email’ and ‘keyword’ can be used as independent or combined filter / search fields, or no filter at all if you don’t pass both fields)

4. Filtering and Sorting - Record

query get_record_data (
  $page:Int = 1,
  $size:Int = 10,
  $keyword: String,
  $table: String!, ## for example: sample_record
  $field: String! ## for example: sample_field_1
) {
items: records (
  per_page: $size
  page: $page
  filter: {
       table: { value: $table }
  ## Search for a partial match of $keyword in the $field property
  ## For an exact match, use value instead of contains
       properties: [
       { name: $field, contains: $keyword }
     ]
 }
 ## Sort by the most recently updated first
 sort: [
   { updated_at: { order: DESC } }
 ]
){
  total_pages
  total_entries
  per_page
  current_page
  results {
    id
    record_name: table
    properties
  }
 }
}

Notes:

  • There are more filter options, including starts_with, ends_with, not_starts_with, not_ends_with, contains, not_contains, value and exists. The options vary depending on the function / data being considered.
  • Use the auto-complete feature and chose the best filter method as needed
  • contains, starts_with and ends_with ignore case unless you set case_sensitive: true (good for keyword search).
  • value looks for an exact match (search specific data).

Important:

  • As you nest your graphQL, this will behave as an AND statement.
  • The order ‘DESC/ASC’ here is not a string (wrapped in “ “), this is a current inconsistency with the platform code.

5. Multi / Related Data

Insites functionality with regards to data relation is constantly evolving. This section contains some available examples.

Note:

Fields defined in the ‘join_on_property’ and ‘foreign_property’ can be anything defined under the data point it is being related to (Users / Records).

User to Record Data Relation

query get_users (
 $page:Int = 1,
 $size:Int = 10,
 $email: String,
 $keyword: String,
 $profile_type: String!, ## for example: sample_user_profile
 $field: String!, ## for example: sample_field_1
 $related_table: [String]!, ## for example: sample_record
 $join_on: String!, ## for example: id (the user’s id)
 $foreign: String! ## for example: sample_record_field
) {
items: users (
  per_page: $size
  page: $page
  filter: {
   email: { value: $email }
   profiles: {
     name: $profile_type
     properties: [
       { name: $field, value: $keyword }
     ]
   }
 }
 sort: {
   email: {order: ASC }
 }
) {
  total_pages
  total_entries
  per_page
  current_page
  results {
    id
    first_name
    last_name
    email
    profiles {
        profile_type
        properties
    }

## Relate the user to $related_table records where the user’s $join_on = $foreign
    related_data: related_records(
       table: $related_table
       join_on_property: $join_on
       foreign_property: $foreign) {
     properties
   }
  }
 }
}

Record to Record Data Relation

query get_record_data (
  $page:Int = 1,
  $size:Int = 10,
  $keyword: String,
  $table: String!, ## for example: sample_record_1
  $field: String!, ## for example: sample_field_1
  $related_table: [String]!, ## for example: sample_record_2
  $join_on: String!, ## for example: record_1_field
  $foreign: String! ## for example: record_2_field
) {
items: records (
  per_page: $size
  page: $page
  filter: {
       table: { value: $table }
       properties: [
       { name: $field, contains: $keyword }
     ]
 }
 sort: [
   { updated_at: { order: DESC } }
 ]
){
  total_pages
  total_entries
  per_page
  current_page
  results {
    id
    record_name: table
    properties

## Relate $table to $related_table where $join_on = $foreign
    related_data: related_records(
      table: $related_table
      join_on_property: $join_on
      foreign_property: $foreign) {
     properties
    }
  }
 }
}

record to User Data Relation

query get_record_data (
  $page:Int = 1,
  $size:Int = 10,
  $keyword: String,
  $table: String!, ## for example: sample_record
  $field: String!, ## for example: sample_field_1
  $join_on: String!, ## for example: record_field
  $foreign: String! ## for example: email
) {
items: records (
  per_page: $size
  page: $page
  filter: {
       table: { value: $table }
       properties: [
       { name: $field, contains: $keyword }
     ]
 }
 sort: [
   { updated_at: { order: DESC } }
 ]
){
  total_pages
  total_entries
  per_page
  current_page
  results {
    id
    record_name: table
    properties


    ## Relate $table to the user whose $foreign (email) = $join_on
    related_user: related_users(join_on_property: $join_on foreign_property: $foreign) {
       id
     name
     email
     profiles {
       profile_type
       properties
     }
   }
  }
 }
}

6. Filtering by Related Data

Filter records or users by their related data with the and filters. Each entry has a that says how the two are linked and a for the related data. In , names the property on the current record (it defaults to ) and names the property on the related record.

query get_filtered_records (
  $page:Int = 1,
  $size:Int = 10,
  $table: String!, ## for example: sample_record_1
  $related_table: String!, ## for example: sample_record_2
  $join_on: PropertyName!, ## for example: record_1_field
  $foreign: PropertyName!, ## for example: record_2_field
  $field: String!, ## a property on the related records
  $keyword: String
) {
items: records (
  per_page: $size
  page: $page
  filter: {
    table: { value: $table }
    ## Keep only records whose related records match this filter
    related_records: [
      {
        join: { join_on_property: $join_on, foreign_property: $foreign }
        filter: {
          table: { value: $related_table }
          properties: [{ name: $field, value: $keyword }]
        }
      }
    ]
  }
){
  total_entries
  results {
    id
    properties
  }
 }
}

Mutation Examples

The following examples demonstrate GraphQL mutations for operations such as inserting, deleting, and updating data in the database.

1. Create User

mutation sample_create_user (
 $name: String,
 $email: String,
 $profile_type: String!, ## for example: sample_profile
 $field_1: String!, ## for example: profile_field_1
 $field_2: String!, ## for example: profile_field_2
 $value_1: String,
 $value_2: String
) {
user_create(
 user: {
   name: $name
   email: $email
   profiles: [
     {
       name: $profile_type, ## Creates / Binds the profile to the user
       values: {
         properties: [ ## These are your profile fields & values
           { name: $field_1, value: $value_1 }
           { name: $field_2, value: $value_2 }
         ]
       }
     }
   ]
 }
) {
   id
   created_at
   updated_at
   deleted_at
   name
   email
   profiles(profile_type: $profile_type) {
    properties
  }
 }
}

2. Create Record

mutation sample_create_record (
  $table: String!, ## for example: my_record_name
  $title_field: String!, ## for example: title
  $details_field: String!, ## for example: details
  $title: String,
  $details: String
) {
 record_create(
   record: {
     table: $table
     properties: [ ## These are your record fields & values
       { name: $title_field, value: $title }
       { name: $details_field, value: $details }
     ]
   }
 ) {
   id
   created_at
   updated_at
   deleted_at
   properties
 }
}

3. Update User

mutation sample_update_user (
 $id: ID!,
 $name: String,
 $email: String,
 $profile_type: String!, ## for example: sample_profile
 $field_1: String!, ## for example: profile_field_1
 $field_2: String!, ## for example: profile_field_2
 $value_1: String,
 $value_2: String
) {
user_update(
 id: $id, ## ID of user to be updated
 user: {
   name: $name
   email: $email
   profiles: [
     {
       name: $profile_type, ## Creates / Updates the profile
       values: {
         properties: [ ## These are your profile fields & values
           { name: $field_1, value: $value_1 }
           { name: $field_2, value: $value_2 }
         ]
       }
     }
   ]
 }
) {
   id
   created_at
   updated_at
   deleted_at
   name
   email
   profiles(profile_type: $profile_type) {
    properties
  }
 }
}

4. Update Record

mutation sample_update_record (
   $id: ID!,
   $title_field: String!, ## for example: title
   $details_field: String!, ## for example: details
   $title: String,
   $details: String
) {
 record_update (
   id: $id, ## ID of the data to be updated
   record: {
     properties: [ ## These are your record fields & values
       { name: $title_field, value: $title }
       { name: $details_field, value: $details }
     ]
   }
 ) {
   id
   created_at
   updated_at
   deleted_at
   properties
 }
}

5. Delete User

mutation sample_delete_user ($id: ID!, $profile_type: String!) {
user_delete(
 id: $id ## ID of the user to be deleted
) {
   id
   created_at
   updated_at
   deleted_at
   first_name
   last_name
   email
   profiles(profile_type: $profile_type) {
    properties
  }
 }
}

6. Delete Record

mutation sample_delete_record ($id: ID!, $table: String!) {
 record_delete(
   id: $id ## ID of the record to delete
   table: $table ## required: the instance refuses a delete without it
 ) {
   id
   created_at
   updated_at
   deleted_at
   properties
 }
}

Important:

  • A deleted record is kept for 30 days and then removed for good. Within those 30 days you can restore it with an update mutation that sets deleted_at to null. Deleting a record does not delete its related records.
  • If a user is deleted, all its associated profiles and data will be deleted as well.
  • Restoring a user does not restore associated profiles; restore each deleted profile on its own.