How to: Query Data Model Records Data

Estimated Reading Time:  7 minutes

Overview

There are various methods for querying A query lets you retrieve, access, manipulate, and delete data in a database. Data Model records data in Unqork. For example, authenticating and using Postman to retrieve your records data. These querying tools help test API APIs (application programming interfaces) are a set of protocols and definitions developers use to build and integrate application software. APIs act as the connective tissue between products and services. calls and confirm records data are complete and accurate. To make it easier to query data on the Unqork Designer Platform, each environment includes a GraphQL Sandbox to query and perform SQL SQL (Structured Query Language) is language used in programming and designed for managing data contained in a relational database system.-like filtering commands on your Data Model's records. How you filter your data depends on the commands you configure in a remote execute API module.

Before querying data, there are three steps to follow to set up and authenticate your GraphQL Sandbox:

1. Locate the Data Model's model ID.
2. Configure an API module to query the records data.
3. Authenticate the GraphQL Sandbox to query your data.

What You'll Learn

In this article, you'll learn how to use your environment's GraphQL sandbox to query Data Model records.

Locate Your Model ID

Remember, Unqork workspaces, applications, and modules are assigned a unique identifier at creation. The same applies to Data Models. A Data Model's unique identifier is referred to as the model ID. To locate the model ID:

1. In Workspaces view, navigate to and select your Workspace.
2. To the left of the page, click  Data Models.
3. Click the Data Model tile of the records data you want to query.

Your browser window displays the following URL format: https://{your-env}.unqork.io/workspaces/{workspaceId}/data-model/{modelId}.

Highlight the model ID and copy it for use in configuring your API module. The following image is an example of a model ID in the browser:

Create an API Module to Query Records Data

To save you time, we've created an API module that lets you query records data, as well as perform SQL-like count and filtering commands. You can find this remote execute API module in the Training environment here: https://training.unqork.io/#/form/63c94f7d9b81f136267efaf0/edit.

To take advantage of this preconfigured API module, copy and paste its module definition to a new module in your environment.

Confirm your new module exists in the same workspace as your Data Model.

Add Your Model ID

Now that you have your new API module, open it and add your model ID.

To add and connect your model ID to your new API module:

1. Open your new, preconfigured API module.
2. In the Module Builder, hover over the modelId iconHidden component.

A 5-button toolbar displays above the component on hover-over.

3. Using the toolbar, click the (Settings) button.
4. In the Default Value field, replace the model ID with the model ID you copied in the Locate Your Model ID section.
5. Click Save & Close.
6. Save your module.

Explore the Preconfigured API Module

The various components in this module let you query Data Model records and count, filter, or skip records using logic components. Here are a few highlights on how the configuration works:

Component Description

method iconHidden

This API module performs a POST request method so the GraphQL Sandbox can accept the data.

calcCleanVars  Calculator

This component applies a Lodash Lodash is a JavaScript library that lets you perform functions for common programming tasks. rule for the skip and limit arguments you can specify in the GraphQL Sandbox.

dwfFormatModelRecords Data Workflow Icon Data Workflow

This component maps the key/value pairs of the data and outputs the records data.

plugGetModelRecords Plug-In

This component inputs the model ID and records data, mapping it to the GraphQL Sandbox. It also inputs arguments to filter, limit, or skip queried records. Then, it outputs the records in a new data structure.

calcClean Vars Calculator Component:

A static image displaying the infrastructure of AWS PrivateLink.

plugGetModelRecords Plug-In Component:

A static image displaying the layout of Azure PrivateLink Infrastructure.

Because this preconfigured API module is just a blueprint, you can adjust and reconfigure as you see fit.

Authenticate Your GraphQL Sandbox

Now that your API module is set up, it's time to access and authenticate your GraphQL Sandbox.

Locate the Authentication Token

To use your environment's GraphQL Sandbox, you first need to find your environment's unqorkio authentication token.

To locate the authentication token:

1. Log in to your Unqork environment.
2. Right mouse click anywhere on your Workspaces page.
3. Click Inspect. The DevTools open as a panel to the right of your page.
4. At the top of the panel, select the Application tab.

If you’re using a Mac, Command + Option + i also opens the DevTools to the Application tab.

5. In the menu to the left, find the Storage section.
6. Under Cookies, select the environment web page address. For example, https://training.unqork.io.
7. In the right panel, find and select the unqorkioToken key.
8. At the bottom of the panel, copy the unqorkioToken cookie value.

Access Your Environment's API GraphQL Sandbox

To access your environment's API GraphQL Sandbox:

1. Open a new browser tab.
2. In the browser bar, insert https://{unqorkEnv}/api/graphql, where {unqorkEnv} is the name of your environment domain. For example: https://training.unqork.io/api/graphql.
3. Press Enter (Return). The GraphQL for the specified environment loads.

Authenticate Access to Your Environment

An authentication token is required to perform queries or mutations. On initial page load, the Unable to Reach Server modal A modal is a window that appears on top of the content you are currently viewing. displays. To gain access to the environment any perform functions, you must insert your unqorkio token into HTTP HTTP (Hypertext Transfer Protocol) is an application-layer protocol used to transmit hypermedia documents like HTML. Headers.

To authentic access to your environment:

1. At the bottom left of the GraphQL editor, click Headers.
2. Click + New Header.
3. In the Header Key field, enter unqork-auth-token. No quotes necessary.
4. In the Header Value field, paste the cookie value you obtained in the Locate the Authentication Token section of this article. No quotes necessary.

Successful authentication is denoted by the error message modals clearing from the Response panel.

Query Data Model Records Data

Now that your GraphQL Sandbox is authenticated, you can begin querying Data Model records.

To query your Data Model records data:

1. In the Operation panel of your GraphQL Sandbox, copy and paste the following code:
Copy
query GetDataModels($modelId: String!) {
ads {
modelRecord {
getModelRecords(modelId: "modelId") {
records {
data
}
}
}
}
}

This request calls the plugGetDataModels Plug-In component in your API module.

2. Replace the modelId in quotes with your Data Model's ID. Ensure the quotes remain.

To locate your Data Model ID, see the Locate Your Model ID section.

3. Click GetDataModels.

In the Response panel, all your Data Model's records display. During this course, you made a Data Model for an insurance application. The response you see is specific to the fields in the schema you created, and the values are those entered by the end-user End-users, also known as Express Users, are the individuals accessing an application through Express View. In most cases, end-users are the customers using the product..

Using the Preconfigured Filtering and Counting Options

You can also use the GraphQL to take advantage of the arguments preconfigured in your API module. In the top-left corner of the GraphQL Sandbox, click >> (expand). A new panel displays to the left of the Operation panel. In this Documentation panel, you can select options to count the total records, limit records that display, and skip a specified number of records in the response.

Arguments

Select and clear these options to add and remove arguments from the request.

Argument Description

modelId

Select this argument to request records data from a specified Data Model.

This is a required field and must be selected.

options

Select options to add additional filter, limit, and skip arguments to your query.

filter

Select this option to filter the data for JSON data only.

limit

Select this option to limit the number of records returned. Use the Variables tab below the Operation panel to enter a value you want to limit by. For example, replace "limit": null with "limit": 5 to return only the top five records in your Data Model.

skip

Select this option to skip a specified number of records in your query. Use the Variables tab below the Operation panel to enter the number of records you want to skip. For example, replace "skip": null with "skip": 2 to omit the top two records in your Data Model.

Fields

Select and clear these options to add and remove fields from the request.

Fields Description

records

Select this field to request all records and their schema data fields. For example, the record's ID, when it was created, who created it, and so on.

archived

Select this field to determine whether a record was archived. True if archived; false otherwise.

created

Select this field to display the date and time the record was created.

data

Select this field to display all data fields associated with the record in your Data Model schema.

id

Select this field to display the record's unique identifier.

owner

Select this field to display the user that created the record.

total

Select this field to return the total number of records in your Data Model.

Resources