Stryke Docs - 1.9.0

Stryke Docs - 1.9.0

›API

Overview

  • Overview
  • Quick Start Guide
  • The Playground app

Changelog

  • Stryke Changelog

Developing an App

  • Users Overview
  • Create a new App
  • Entity Definition
  • Actions Definition

    • Actions Definition
    • Scripts and source code
    • Triggers
    • Templates and views
  • Where is your app's data stored?
  • Synchronising app instances

Using an App

  • Stryke App UI
  • Working with your app's data
  • End users
  • Access Control
  • Files

API

  • Stryke API
  • Stryke queries

Developer Tools

  • Tools

Stryke Library

  • Stryke Library Reference

Stryke queries

Stryke has advanced query capabilities to let you query the data in your apps. Queries in Stryke are written following the GraphQL standard. Stryke generates query definitions automatically for every entity in an app. This allows users to perform custom queries on their data from the moment in which an entity is created.

By following the GraphQL standard, Stryke allows clients to create their own queires and be able to retrieve only the fields they require, even on related entities. For more information on the GraphQL standard and how to use it, check the official documentation.

Currently queries can be executed via the Stryke API or from your scripts.

GraphQL available to your app

Stryke automatically generates the following query definitions for your app:

  • Query by ID
  • Query by IDs
  • Query all records of an entity
  • Query by filter

This means that 3 query definitions will be created for each entity in your app with the following formats:

Query by ID

entity_name (id : record_id ) { fields_to_query }

Will query for the record belonging to entity with name: [ entity name ], with the specified id

Example

Query

{
  Receipt(id: "c07a84dc-312c-4c5b-beaa-1677e500cb16") { 
    id 
    alias 
    amount 
  }
}

Response

{
  "data": {
    "Receipt": [
      {
        "id": "c07a84dc-312c-4c5b-beaa-1677e500cb16",
        "alias": "RECEIPT-00004",
        "amount": 80
      }
    ]
  }
}

Query by IDs

entity_name (id : [ record1_id, record2_id, record3_id, ... ]) { fields_to_query }

Will query for records belonging to entity with name: [ entity name ], with the specified list of ids

Example

Query

{
  Receipt(ids: ["c07a84dc-312c-4c5b-beaa-1677e500cb16", "3c0f8f84-8892-4ed4-86b9-560eacbb75dc"]) { 
    id 
    alias 
    amount 
  }
}

Response

{
  "data": {
    "Receipt": [
      {
        "id": "c07a84dc-312c-4c5b-beaa-1677e500cb16",
        "alias": "RECEIPT-00004",
        "amount": 80
      },
      {
        "id": "3c0f8f84-8892-4ed4-86b9-560eacbb75dc",
        "alias": "RECEIPT-00006",
        "amount": 120
      }      
    ]
  }
}

Query All

entity_name { fields_to_query }

Will query for the all records belonging to entity with name: [ entity name ]. The number of records returned is the smallest one out of: all the records of that entity or the maximum allowed number of records that can be returned in a single request, as specified in the limits of your app.

Query all accepts the following optional arguments:

  • orderby - an optional parameter to order the results of the query by the values of a field. Ordering can be ascending (asc) or descending (desc). If orderby is not specified, the results will be orderd by the records' created date in descending order.
  • offset - an optional parameter to limit the number of records the query will return
  • limit - an optional parameter to skip a predefined number of records when building the query result.

Examples

Query all receipt records

{
  Receipt { 
    id 
    alias 
    amount 
  }
}

Response

{
  "data": {
    "Receipt": [
      {
        "id": "c07a84dc-312c-4c5b-beaa-1677e500cb16",
        "alias": "RECEIPT-00004",
        "amount": 80
      },
      {
        "id": "13f6da2b-de91-4d15-a350-fdebc6657fa2",
        "alias": "RECEIPT-00003",
        "amount": 90
      },
      {
        "id": "c44204e6-3dae-4131-ac11-f9e1a5706e6d",
        "alias": "RECEIPT-0001",
        "amount": 9.5
      },
      {
        "id": "b394e7e2-aa52-40b8-bd9c-8afaedffb52c",
        "alias": "RECEIPT-0002",
        "amount": 20
      },
      {
        "id": "60fa3cc8-20c9-4885-a860-03387b7d5d20",
        "alias": "RECEIPT-0005",
        "amount": 2.3
      }
    ]
  }
}

Query the first 3 receipt records ordered by alias

{
  Receipt ( orderby: { alias: asc }, limit: 3 ) { 
    id 
    alias 
    amount 
  }
}

Response

{
  "data": {
    "Receipt": [
     {
        "id": "c44204e6-3dae-4131-ac11-f9e1a5706e6d",
        "alias": "RECEIPT-0001",
        "amount": 9.5
      },
      {
        "id": "b394e7e2-aa52-40b8-bd9c-8afaedffb52c",
        "alias": "RECEIPT-0002",
        "amount": 20
      },
      {
        "id": "13f6da2b-de91-4d15-a350-fdebc6657fa2",
        "alias": "RECEIPT-00003",
        "amount": 90
      }
    ]
  }
}

Query by Filter

{
  entity_name(
      filter : { name_of_field_to_filter_by : { comparison_operator : field_value } },
      orderby: { name_of_field_to_order_by : [ asc OR desc ]},
      offset: number_of_records_to_skip_in_the_result ,
      limit: max_number_of_records_to_return
    ){ 
        id 
        alias 
        amount 
    }
}

Will query for records belonging to entity with name: [ entity name ] that match the filtering criteria specified in the filter parameter. The number of records returned can be limited using the limit parameter. If no limit parameter is specified, the number of records returned is the smallest one out of: all the records of that entity that match the criteria or the maximum allowed number of records that can be returned in a single request, as specified in the limits of your app.

Query by filter accepts the following arguments:

  • filter - represents the filter criteria for the query. This is explained in detail below.
  • orderby - an optional parameter to order the results of the query by the values of a field. Ordering can be ascending (asc) or descending (desc). If orderby is not specified, the results will be orderd by the records' created date in descending order.
  • offset - an optional parameter to limit the number of records the query will return
  • limit - an optional parameter to skip a predefined number of records when building the query result.

limit and offset can be used together to paginate the results of a large query. When using both parameters, the result of the query will first skip the number of records specified by the offset parameter and then it will start counting the number of records specified by the limit parameter.

Example

Query

The following query will return all records of entity receipt where the value of the amount field is greater than 50and less than 100. The results will contain theid,alias, andamountfields, they will be ordered by the values of theamount` fields and only 2 records will be returned.

{
  Receipt(
      filter: { amount : { gt: 50, lt:100 } },
      orderby: { amount: asc },
      limit: 2, 
    ) { 
    id 
    alias 
    amount 
  }
}

Response

{
  "data": {
    "Receipt": [
      {
        "id": "c07a84dc-312c-4c5b-beaa-1677e500cb16",
        "alias": "RECEIPT-00004",
        "amount": 80
      },
      {
        "id": "13f6da2b-de91-4d15-a350-fdebc6657fa2",
        "alias": "RECEIPT-00003",
        "amount": 90
      }
    ]
  }
}

Custom Filter Explained

The filter argument of the "query by filter" is not a GraphQL standard. It is specific to Stryke and is implemented on top of "Stryke's custom query" engine.

The filter argument represents the criteria of your query, and effectively how the query result will be filtered.

The filter argument is in JSON format and follows a readable structure. The value of the filter JSOn field is an object containing a comma separated list of fields with the corresponding logical operator and value to filter on.

Format:
{ [fieldName] : { [operator name]: [value] }}      

Example: 
{ "amount" : { "gt": 100 }}       

The types of operators and data type of the value match the data type of the field defined in your entity. A criteria for a single field can make use of multiple operators to construct its comparison.

Format:
{ [fieldName] : { [operator1]: [value], [operator2]: [value], ..., [operator3]: [value] }}     

Example: 
{ "amount" : { "gt": 100, "lt": 220 }}       

Supported operators

OperatorIdentifier
Equaleq
Not Equalne
Case Sensitive Likelike
Case Sensitive Not Likenlike
Case Insensitive Likeilike
Case Insensitive Not Likenilike
Greater Thangt
Greater Equal Thanegt
Less Thanlt
Less Equal Thanelt
Anyany
Not Anynany

Comparison operators

"Equals" and "not equals" operators check the exact equality of the values being compared, whether numerical, textual or boolean. "Greater than" and "Less than" (and their respective negations) also check the exact values being compared and will sort numerically for numbers and alphabetically for strings. For example, "apple" comes before "strawberry" when comparing string fields. When comparing numeric fields: 8 comes before 60, but when comparing string fields containing numeric values: "60" comes before "8".

Like operators

The like and nlike operators can be used with the '%' wildcard to filter by partial values. For example to retrieve all values starting with Stryke, the following can be used: Stryke%. If no wildcard is specified, the query will apply an exact match, similarly to the eq operator.

Any and Not Any operators

The any operator allows filtering for values in a list of items. Any operators can be used in regular fields as well as in lookup fields.

Example:

{
  Receipt(
      filter: { business : { alias: { any : ["shop","store","online retailer"] } } }      
    ) { 
    id 
    alias 
    amount 
  }
}

The query above will return all Receipts that have a lookup to businesses whose alias is either: "shop","store", or "online retailer".

The "Not Any" (nany) operator queries for all items that do NOT match any of the criteria in a list.

Example:

{
  Receipt(
      filter: { business : { alias: { nany : ["shop","store"] } } }      
    ) { 
    id 
    alias 
    amount 
  }
}

The query above will return all Receipts that have a lookup to businesses whose alias is: "online retailer", i.e. neither: "shop" nor "store".

Operators and Data Types

Below is a list showing which data types are supported by each operator.

OperatorStringIDDate TimeEmailNumberBoolean
Equal✅✅✅✅✅✅
Not Equal✅✅✅✅✅✅
Greater Than✅❌✅✅✅❌
Greater Equal Than✅❌✅✅✅❌
Less Than✅❌✅✅✅❌
Less Equal Than✅❌✅✅✅❌
Like✅❌✅✅❌❌
Not Like✅❌✅✅❌❌
Case-insensitive Like✅❌✅✅❌❌
Case-insensitive Not Like✅❌✅✅❌❌
Any✅✅✅✅❌❌
Not Any✅✅✅✅❌❌

Querying by values in a related record

A filter criteria can include lookup fields. More specifically, when an entity has a field which is a lookup to another record, that field can be used in a field criteria.

When using a lookup field in a filter parameter, the criteria can be set to either the id or alias fields of the related record. This is expressed as follows.

{
  Receipt(
      filter: { business : { alias: { like : "%shop%" } } }      
    ) { 
    id 
    alias 
    amount 
  }
}

The query above has a filter that instructs to retrieve all records where the alias field of the related record specified by the lookup field: business contains the work shop.

Similarly, the lookup criteria can point to ID field of the related record.

{
  Receipt(
      filter: { business : { id: { eq : "cca1f06a-985b-4f41-a27d-3df64aac1f50" } } }      
    ) { 
    id 
    alias 
    amount 
  }
}

The query above retrieves all receipt records that have a lookup to a business with ID cca1f06a-985b-4f41-a27d-3df64aac1f50.

Query by related users

When the lookup field contains a lookup to a user, the filtering can only be expressed using the ID field.

{
  Business(
      filter: { businessOwner : { id: { eq : "72da6a72-9a2f-4f53-bafc-096f28a50a58" } } }      
    ) { 
    id 
    alias 
  }
}

The query above retrieves all business records where the businessOwner field points to a user with ID 72da6a72-9a2f-4f53-bafc-096f28a50a58.

Logical Operators and Grouping

The query engine supports both AND and OR operators. By default, if no logical operator is specified explicitly, query operations are compiled together with AND operators.

Example
{ 
  name : {eq: "test"}, 
  size : {eq: 100}
}

Evaluates to:

name = "test" AND size = 100

Logical Operators

Optionally, logical operators can be incorporated in the criteria explicitly. Logical operators are written in the form of a JSON array as shown in the examples below. All criteria included under the array will be compiled together using that logical operator. This allows us to specify groups within a criteria, similarly to how we would use parenthesis in a DB query.

AND Operator
and : [
  { name : {eq: "test"}}, 
  { size : {eq: 100}}   
]

Evaluates to:

(name = "test" AND size = 100)
OR Operator
or : [
  { name : { eq : "test"}}, 
  { size : { eq : 100}}
]

Evaluates to:

(name = "test" OR size = 100)

As seen in the examples above, logical

Nesting

Logical operators can be nested by incorporating one inside the other as follows:

and: [
  { name : { eq : "test"}}, 
  { or : [
      { size: { eq: 100 }}, 
      { size: { eq: 200 }}
    ]}
]

Evaluates to:

(name = "test" AND ( size = 100 OR size = 200))

Criteria Example

Assuming a Stryke Entity with the following fields:

{
    "fields": {    
        "name": {
            "type": "string"
        },
        "size": {
            "type": "number"
        }
    }   
}  

The value of the filter argument for a query that will retrieve all records of name "test" and of size between 1000 and 1550 would be as follows:

{ 
    "name" : {"eq": "test"}, 
    "size" : {
            { "gt": 1000 },
            { "lt": 1550 }      
    }
}
← Stryke APITools →
  • GraphQL available to your app
    • Query by ID
    • Query by IDs
    • Query All
    • Query by Filter
    • Supported operators
    • Querying by values in a related record
    • Logical Operators and Grouping
Stryke Docs - 1.9.0
Docs
Docs HomeAPI DocsStryke Tools
Community
Stryke HomeTwitterGithub
Contact Us
support@stryke.io
Copyright © 2021 Viroppa