Appfarm Documentation
Getting startedDocumentationCommunityAppfarm Create
  • Overview
  • Getting Started
    • What is Appfarm?
    • Key concepts
    • Quickstart
      • Speed intro
      • Step-by-step guide
    • Appfarm Showroom
    • FAQ
  • Appcademy
    • Learning paths
    • Appfarm Fundamentals
      • Intro Course
        • 1. Intro to No-Code and Appfarm
        • 2. Navigation in Appfarm Create
        • 3. What is Apps?
        • 4. Intro to UI Editor
        • 5. Data Model
        • 6. App Data
        • 7. Actions
        • 8. Tips and Tricks
        • 9. Intro to practical walkthrough
        • 10. Create a details view of a Project
        • 11. Create a Custom List
        • 12. Swipe and Delete
        • 13. Functionality for simple Create of Data
        • 14. Upload and Download Photos
        • 15. Input Dialog with Validation and Save
        • 16. Dashboard
        • 17. Summary
        • Quiz
      • User Interface Fundamentals
        • Container - Sectioning, Styling and Repeating
        • Conditional Styles
        • Motions
        • Responsive Design
        • Step-by-step workflow
        • Featured UI Components
        • Quiz
      • App Data Fundamentals
        • Data Source Filtering
        • App Variables and Runtime Properties
        • URL Parameters
        • Quiz
      • Actions & Logic Fundamentals
        • Event Handlers
        • Featured Action Nodes
        • Context Parameters
        • Quiz
      • Services Fundamentals
        • Introduction to Services
        • Setting up a Service
        • Scheduling a Service
      • Integration Fundamentals
        • The web request action node
        • Fetch data from an endpoint
        • Map data to a data source
        • Modify the response
        • Nested data mapping
        • Path parameters
        • Authentication
        • Send data to an endpoint
        • Quiz
      • User handling and permissions
        • Users and roles
        • Permissions
        • Creating users
        • Extending the User object class
        • Updating and deleting users
        • Unauthenticated access
        • Quiz
    • Appfarm Professional
      • User Interfaces
        • Featured UI Components
        • Concepts and Use Cases
      • Data Structures & Data Handling
        • Data Features
        • Search & Filters
        • Featured Action Nodes
        • GraphQL
      • Logic & Flow
        • Logical Concepts
        • Date and Time Handling
        • Featured Action Nodes
        • Exception Handling
      • Login & Configuration
        • Login and Authentication
        • Settings, Configuration and Languages
      • Security & Operations
        • Security and Permissions
        • Deployment
        • Schedules and Logs
        • Debugging and App Health
      • Performance & Optimization
        • Optimizing Performance
        • Enhancing Functionality
    • Appfarm Sales Representative
    • Appfarm Developer Forum
      • Session 1: Data Modeling in Appfarm Create
      • Session 2: App Data in Appfarm Create
      • Session 3: Services in Appfarm Create
      • Session 4: Optimizing Performance
    • Background
      • Databases
        • Data modeling 101
        • Database normalization
  • Library
    • UI components
      • Advanced bar chart
      • Advanced bubble chart
      • Advanced combined chart
      • Advanced gantt chart
      • Advanced heatmap chart
      • Advanced line/area chart
      • Advanced pie chart
      • Advanced scatter plot chart
      • Advanced solid gauge chart
      • Animated component
      • Avatar
      • Avatar group
      • Basic bar chart
      • Basic gauge chart
      • Basic line chart
      • Basic pie chart
      • Bottom navigation
      • Button
      • Checkbox
      • Chip group
      • Circular progress
      • Coded component
      • Container
      • Date & time picker
      • Drawable canvas
      • Floating action button
      • Icon
      • Icon button
      • Iframe
      • Image
      • Linear progress
      • List
      • Map
      • Menu list
      • Multi select
      • PDF reader
      • Popover
      • Radio buttons
      • Rich text editor
      • Rich text
      • Select
      • Slider
      • Speed dial
      • Switch
      • Table
      • Tabs
      • Text
      • Text edit
      • View container
      • Visibility group
    • Action nodes
      • Aggregate data
      • Advanced search
      • Auth operations
      • Block
      • Catch exception
      • Copy to clipboard
      • Create file archive
      • Create file object
      • Create object
      • Create user account
      • Delete objects
      • Delete user account
      • Duplicate objects
      • End execution
      • Exit block
      • Exit loop
      • Export data
      • Foreach
      • Generate document
      • If
      • Import data
      • Invalidate cache
      • Log in
      • Log to console
      • Log out
      • Next iteration
      • Navigate
      • Open/close popover
      • Open confirm dialog
      • Open print dialog
      • Open snackbar
      • Open Unsplash dialog
      • Open URL
      • Persist objects
      • Push notifications
      • Read objects
      • Request permissions
      • Run code
      • Run other action
      • Run service
      • Scan barcode/QR code
      • Send email
      • Send SMS
      • Set client language
      • Set data source attributes
      • Set selection
      • Set theme
      • Set user account image
      • Show install app prompt
      • Sleep
      • Sort objects
      • Throw exception
      • Toggle drawer
      • Update object
      • Update secret
      • Update user account
      • Web request
      • While
  • Reference
    • Appfarm Create
      • Appfarm Commander
      • Blue dots
      • Copy & Paste
      • Farmer's Market
      • Find references
      • Find usage
      • Keyboard shortcuts
      • Undo/Redo
      • User preferences
    • Platform concepts
      • Conditions
      • Data bindings
      • Date and time
      • Event handlers
      • Filters
      • Functions
      • Markdown
      • Objects
      • Operators
      • Value processor
    • Dashboard
    • Apps
      • UI
        • Views
          • Dialog
          • Drawer
        • Layout designer
        • Component properties
        • Shareable UI components
      • Data
        • App variables
        • Data sources
        • Calendar data sources
      • Actions
      • App settings
      • App size
      • App health
    • Services
      • Service Endpoints
      • Service settings
      • Service health
      • API explorer
    • Data model
      • Object classes
      • Object class properties
      • Enumerated types
      • GraphQL
        • Queries
        • Mutations
      • Data Extract API
      • Time series data
    • Operations
      • Deploy
      • Schedules
      • Logs
    • Resources
      • Themes
      • Files
      • Fonts
      • Internationalization
    • Configuration
      • Environments
      • Login
        • Custom auth providers
    • Security
      • Users
      • Service accounts
      • Roles
      • Secrets
      • Permissions
        • Conditional Permissions
    • Appfarm Client
      • Developer tools for Apps
      • Developer tools for Services
      • Warnings and errors
  • How to
    • Data modeling
      • Many-to-many relationships
      • Use naming conventions
      • Offline data handling
      • Data silos and White labelling
    • User interface
      • Manage a many-to-many relationship with a Chip group
      • Configure drag and drop
      • Build a drag-and-drop calendar
      • Design a responsive layout
      • Work with flexbox
      • Use Mapbox as a map layer
      • Understand charts
    • Logic and flow
      • Event Log Design
      • Configure advanced search
    • Themes and styling
      • Change the active theme
      • Add custom email templates
    • Enhance your app
      • Add deep links
      • Add keyboard shortcuts
      • Add link previews for social media
      • Apply SEO best practices
      • Change the active language
      • Generate a PDF from a Container
    • Integrations
      • Integrate with external systems
      • Integrate with OpenAI
      • Integrate with Google Analytics (GA4)
      • Configure a custom email account
      • Integrate with a payment provider
      • Integrate with Signicat
      • Integrate directly with an external database
      • Retrieve a Bearer token from Google Cloud
      • Fetch data from BigQuery
      • Retrieve access token from Microsoft Entra ID
    • Workflow automation
      • Update an OAuth 2.0 access token from a service
    • Authentication and access control
      • Add users and assign roles
      • Configure unauthenticated access
      • Implement third-party authentication
    • Security, testing and deployment
      • Add a custom domain
      • Install an app on a device
      • Get ready for Production
      • Optimize performance
      • Security checklist
      • Test and debug
    • Example apps
      • Create an Instagram clone
        • The end result
        • Designing the feed
        • Create new post
        • Add a like-button
        • Add comment-functionality
  • Solution administration
    • Subscription and billing
    • Dedicated tier benefits
    • Guide to GDPR
      • Key principles
      • How Appfarm protects personal data
      • How you can protect your clients’ data
      • Glossary
    • Appfarm and the EU AI Act
  • Policies
    • Appfarm Policies
    • Data Processors
    • Privacy Policy
Powered by GitBook
On this page
  • Simple queries
  • Reference objects
  • Advanced queries
  • Limit
  • Skip
  • Sort
  • Filter
  • Count
  • Aggregate and grouping
  • Group by multiple properties
  • Run GraphQL Queries from Appfarm

Was this helpful?

Export as PDF
  1. Reference
  2. Data model
  3. GraphQL

Queries

A GraphQL query is used for fetching data. This can be useful for verifying which data is stored for a given object class, or for a third-party to export data from your solution.

Simple queries

The simplest query you can run is to specify the object class (known as an object type in GraphQL). For example, if you wanted to list all Projects in the database, you could write:

{
	project
}

Note that the name of the object class is specified under Endpoint Name in the object class properties in Appfarm Create.

Click the Play button (or Cmd/Ctrl + Enter) to execute the query. The response will be displayed to the right.

The query editor will also edit your query to contain all the properties (fields in GraphQL) that are available to query:

{
  project {
    _id
    title
    description
    createdDate
    createdBy
    status
    projectNumber
    projectDisplayName
    af_createdDate
    af_updatedDate
  }
}

You can use these fields in your query to customize the response that you receive. For example, the following query will only return the id and title properties of each project:

{
  project {
    _id
    title
  }
}

To further refine your query you can include arguments, see advanced queries.

Reference objects

If a queried object references another object, or is referenced by another object, you can extract details about the other object.

For example, if you have projects with tasks, you might like to list out the tasks for a project, or obtain the project details for a given task.

// Return all projects, with their ID, title, and an array of associated tasks with each task's ID and title
{project {
  _id
  title
  taskList {
    _id
    title
  }
}}

// Return all tasks with their ID, title, and an object containing the title and description of the associated project
{task {
  _id
  title
  project_reference {
    title
    description
  }
}}

Advanced queries

More advanced query operators can be used to further customize the response. In the following examples, Book is queried in different ways.

Limit

Restrict the response to contain only n objects.

// Return a maximum of 2 books, and only return the title
{
  Book(limit: 2){
    title
  }
}

Skip

Skip the first n objects in the response.

// Return every book after the first 2, and only return the title
{
  Book(skip: 2){
    title
  }
}

Sort

Sort the response in ascending (ASC) or descending (DESC) order.

// Return all books, sorted in ascending order by number of pages
{
  Book(sort: {pages: ASC}){
    title
    pages
  }
}

Filter

Combine operators to filter the response.

// Return all books with more than 500 pages
{
  Book(filter: {
    pages: {gt: 500}
  }){
    title
    pages
  }
}

// Return all books with more than 500 pages, sorted by title
{
  Book(
    filter: {pages: {gt: 500}},
    sort: {title: ASC}
    ){
    title
    pages
  }
}

// Return all books with more than 500 pages but less than or equal to 1000 pages
{
  Book(filter: {
    and: [{pages: {gt: 500}}, {pages: {lte: 1000}}]
  }){
    title
    pages
  }
}

// Return all books with more than 500 pages but less than or equal to 1000 pages and with the title "Jane Eyre"
{
  Book(filter: {
    or: [
      {and: [{pages: {gt: 500}}, {pages: {lte: 1000}}]},
      {title: {eq: "Jane Eyre"}}
    ]
  }){
    title
    pages
  }
}

// Return all books with the title "Jane Eyre" or "Wuthering Heights"
{
  Book(filter: {
    title: {in: ["Jane Eyre","Wuthering Heights"]}
  }){
    title
    pages
  }
}

The supported filter operators are and, or, not, nor, eq, ne, in, nin, gt, gte, lt, lte. Each filter operator will be explained by example:

and

Example:

{
  Book(filter: {
    and: [{pages: {gt: 500}}, {pages: {lte: 1000}}]
  }){
    title
    pages
  }
}

This query will return all books where

  • the pages field is greater than 500 and the pages field is less than or equal 1000

or

Example:

{
  Book(filter: {
      or: [
      {and: [{pages: {gt: 500}}, {pages: {lte: 1000}}]},
      {title: {eq: "Jane Eyre"}}
    ]
  }){
    title
    pages
  }
}

This query will return all books where

  • the pages field is greater than 500 and the pages field is less than or equal 1000

or

  • the title field equals Jane Eyre

not

Example:

{
  Book(filter: {
      pages: {not: {gt: 500}}
  }){
    title
    pages
  }
}

This query will return all books where

  • the pages field is not greater than 500 (in other words, 499 or less)

nor ("not or")

Example:

{
  Book(filter: {
      nor: [{price: {eq: 1.99}}, {sale: {eq: true}}]
  }){
    title
    price
    sale
  }
}

This query will return all books that

  • contain the price field whose value is not equal to 1.99 and contain the sale field whose value is not equal to true or

  • contain the price field whose value is not equal to 1.99 but do not contain the sale field or

  • do not contain the price field but contain the sale field whose value is not equal to true or

  • do not contain the price field and do not contain the sale field

eq ("equals")

This operator is used for comparison. Example:

{
  Book(filter: {
    title: {eq: "Jane Eyre"}
  }){
    title
    pages
  }
}

This query will return all books where

  • the title field equals Jane Eyre

ne ("not equals")

This operator is used for comparison. Example:

{
  Book(filter: {
    title: {ne: "Jane Eyre"}
  }){
    title
    pages
  }
}

This query will return all books where

  • the title field not equals Jane Eyre

in ("in the set" / "is any of")

This operator is used for comparison. Example:

{
  Book(filter: {
   title: {in: ["Jane Eyre","Wuthering Heights"]}
  }){
    title
    pages
  }
}

This query will return all books where

  • the title field is any ofJane Eyre or Wuthering Heights (or rephrased: the value of the title field is in the set of the values Jane Eyre and Wuthering Heights)

nin ("not in the set" / "none of")

This operator is used for comparison. Example:

{
  Book(filter: {
   title: {nin: ["Jane Eyre","Wuthering Heights"]}
  }){
    title
    pages
  }
}

This query will return all books where

  • the title field is none ofJane Eyre or Wuthering Heights (or rephrased: the value of the title field is not in the set of the values Jane Eyre and Wuthering Heights)

gt ("greater than")

This operator is used for comparison. Example:

{
  Book(filter: {
    pages: {gt: 500}
  }){
    title
    pages
  }
}

This query will return all books where

  • the pagesfield is greater than 500 (i.e. 501 pages or more)

gte ("greater than or equal")

This operator is used for comparison. Example:

{
  Book(filter: {
    pages: {gte: 500}
  }){
    title
    pages
  }
}

This query will return all books where

  • the pagesfield is greater than or equal 500 (i.e. 500 pages or more)

lt ("less than")

This operator is used for comparison. Example:

{
  Book(filter: {
    pages: {lt: 500}
  }){
    title
    pages
  }
}

This query will return all books where

  • the pagesfield is less than 500 (i.e. 499 pages or less)

lte ("less than or equal")

This operator is used for comparison. Example:

{
  Book(filter: {
    pages: {lte: 500}
  }){
    title
    pages
  }
}

This query will return all books where

  • the pagesfield is less than or equal 500 (i.e. 500 pages or less)

Count

You can query the total number of objects in a response by using the Count query type. This needs to be enabled per object class by selecting Enable Aggregate and granting the Aggregate permission to the appropriate role.

When enabled, a new query type is added to your available queries. Using the object class Order as an example, we would get access to countOrder. This is separate to the order query type for reading data.

// Return a count of all orders
{
  countOrder {
    count
  }
}
// Return a count of all orders made on or after the 1st of September 2022
{
  countOrder(filter: {orderDate: {gte: "2022-09-01"}}){
    count
  }
}

Aggregate and grouping

You can summarize or find average, min/max or standard deviation using GraphQL aggregates. You may also group the records. For example, you may find the total order amount from OrderLines per Product:

{aggregateOrderLine( 
  filter: {product: {ne: null}},  
  sort: {productNumber:DESC}, 
  group: product,  
) { 
    product
    productNumber
    sum: amount_sum
    _count
  }
}

Given the above example with an OrderLine object class, you may perform the following:

  • Filter, Sort or Group on any property (optional)

  • In the list of properties to be returned, you may select the first or last entry. For example, we might return customer_first or customer_last for in the above expression for returning the first or last customer of the grouped list of order lines.

  • In the list of properties to be returned, we may select the following aggregates of numbers (with amount as example):

    • amount_sum (sum of the amount of orderLines)

    • amount_avg (average of the amount of orderLines)

    • amount_max (maximum of the amount of orderLines)

    • amount_min (minimum of the amount of orderLines)

    • amount_stdDevPop (standard deviation of the amount of all orderLines / the whole population)

    • amount_stdDevSamp (standard deviation of the amount of orderLines in the returned sample)

    • amount_first (amount of the first orderLine)

    • amount_last (amount of the last orderLine)

  • You may select to return an alias for a property, as in the above example sum: amount_sum (sum is an alias for amount_sum)

Group by multiple properties

Following the example above, records can also be grouped by multiple properties. For instance, finding the total order amount from OrderLines per product and size. This will return one aggregation per unique pair of values for product and size:

{aggregateOrderLine( 
  filter: {product: {ne: null}},  
  sort: {productNumber:DESC}, 
  groupList: [product, size]  
) { 
    product
    size
    productNumber
    sum: amount_sum
    _count
  }
}

Run GraphQL Queries from Appfarm

GraphQL aggregations may be handy in applications with large amounts of data. With aggregation in GraphQL you may aggregate data on database level before it is returned to the client.

It is pretty straight forward.

  1. Create an API Key in Appfarm Create. Go to Service Accounts in Appfarm Create, and locate (or create) a Service Account that is member of a Role with Read and Aggregate Permissions to the Object Classes to be queried in GraphQL

  2. Use the Web Request to run the Query:

    • URL: https://<HOSTNAME>/api/graphql

    • Query Parameters: 1 parameter named query. Paste the query itself (e.g. {aggregateOrderLine(filter: ...)} as value

    • Result mapping: Map the properties returned from the GraphQL aggregation

Example setup, with mapping of the Sum to existing Product objects

In the above example, we add the graphQL query as a Query Parameter of a GET request. If the graphQL query is too large, you might encounter 431 (Request Header Fields Too Large) error. GraphQL also supports POST requests. You may add the query as the body of a POST request instead, e.g. the body of the above example would be {"query":"{aggregateOrderLine(filter: ...)}"}

PreviousGraphQLNextMutations

Last updated 3 months ago

Was this helpful?

As with , this needs to be enabled per object class by selecting Enable Aggregate and granting the Aggregate permission to the appropriate role.

Count
Web Request setup for aggregating using GraphQL