Overview
GraphQL is an open-source data query and manipulation language for APIs. GraphQL offers many benefits over REST API’s, including:
- Fetching data across multiple sources from a single API call
- Returns only the data that is requested
- Supports validation and type checking
- Autogenerating API documentation
In this video, I’ll show you how to construct a sample GraphQL query to fetch data in ServiceNow and then how we can use GraphQL inside of a ServicePortal widget.
GraphiQL
To start, I would recommend you download GraphiQL, a GUI for editing and testing GraphQL queries and mutations. You can download it here: https://www.electronjs.org/apps/graphiql
The GraphQL Endpoint is: https://instance-name.service-now.com/api/now/graphql
Documentation
In order to use the documentation and auto-completion, you’ll need to enable the glide.graphql.introspection_enabled system property.
Service Portal Widget
You can download the widget update set here:
It’s compressed as a ZIP file, so remember to uncompress before uploading.
Example GraphQL Query
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | { GlideRecord_Query { incident(queryConditions: "active=true") { _results { number { value } short_description { value } caller_id { ...user } opened_by { ...user } } } } } fragment user on GlideRecord_ReferenceFieldType_sys_user { _reference { name { displayValue } sys_id { value } } } |
Further Reading
- https://graphql.org/
- https://www.howtographql.com/
- https://docs.servicenow.com/bundle/paris-application-development/page/integrate/graphql/concept/scripted-graph-ql.html
If you have any questions or comments, please don’t hesitate to comment below.
Hi Nathan, great video.
“glide.graphql.introspection_enabled” is no longer a maint-only property and can now be enabled by admins as well.
That’s great, thanks for the update!
Hi Nathan.
1. I tried to import the widget XML but it’s not importing. (Unzipped and imported but no luck).
2. I cant able to connect my instance with the GraphQL tool (https://www.electronjs.org/apps/graphiql).
3. Can you explain in detail how can we use the GraphQL Query on the service portal widget. (I can’t able to connect with GraphQL API)
Awesome video & content Nathan.!
I’m trying to do this, except with an external graphQL endpoint instead of a ServiceNow one. Is there anything else I have to do besides update the url in the $htttp.post? I did this and it doesn’t work.
Hi Nathan,
Thank you very much for this ultra useful resource!
Might you please provide an example for a mutation (INSERT, UPDATE and DELETE)?
This would helps us a lot to adopt GraphQL.
With the WashingtonDC upgrade, GraphQL Explorer is available OOB by activating a plugin: com.glide.graphql.framework.demo