
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
I stumbled across a new reason to love GraphQL API's. Up until now, I've been treating GraphQL Explorer the same as REST API Explorer: one query at a time. If I need to save a GraphQL query for later, I stash it in VS Code, notepad, or my digital notebook. So I am constantly swapping queries back and forth between external tools and GraphQL Explorer.
It never occurred to me that I could store multiple queries and execute them individually. For some of you, this may have been obvious but for everyone else, let's take a look at two ways to organize your queries in GraphQL Explorer.
Use Multiple Tabs
The first way to organize GraphQL queries in the explorer is to use multiple tabs. Clicking the Add Tab button on the right hand side of the screen will create a new tab just like in many of ServiceNow's newer editors like ServiceNow Studio.
Once you click the Add Tab button, a new tab is created and the button shifts over to the left hand side of the screen. Queries in additional tabs are saved across page refreshes in the same way as they are without tabs. The tab is given the same name as the first query on the tab or <untitled> if your queries are unnamed.
Name your queries
The next option is to put multiple queries in a single tab and name them. Technically, it will allow you to leave them unnamed. But the advantage of naming them is that when you click Execute query, it will allow you to select which query to execute by name. To name a query, just type it's name next to query or mutation before the first curly brace.
Here is what an unnamed query would look like:
query {
GlideRecord_Query {
incident(queryConditions: "active=true") {
_results {
sys_id {
value
}
}
}
}
}
And here is a named query:
query activeIncidents {
GlideRecord_Query {
incident(queryConditions: "active=true") {
_results {
sys_id {
value
}
}
}
}
}
And my apologies for naming the queries gr in the screenshots. I couldn't help myself.
- 998 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.