Skip to content

Commit 09c2b13

Browse files
authored
GraphQL INC Details (#1080)
* Create GetIncident_Details.js This code snippet helps with the basic details required to fetch the incident. * Create Incident Resolver.js Incident Resolver * Create User Resolver * Create CMDB Resolver.js CMDB Resolver * User Resolver.js * Create resolver mapping.js * Create README.md * GetIncident_Details.gql
1 parent 543b15b commit 09c2b13

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function process(/*ResolverEnvironment*/ env) {
2+
3+
var user= env.getSource();
4+
var CI = new GlideRecord("cmdb_ci");
5+
CI.addQuery("sys_id",CI);
6+
CI.query();
7+
return CI;
8+
9+
10+
})(env);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
type Query {
6+
EntersysID(sys_id:ID!):incident
7+
}
8+
9+
type incident{
10+
sys_id:DisplayableString
11+
number:DisplayableString
12+
short_description:DisplayableString
13+
caller_id: User @source(value:"caller_id.value")
14+
cmdb_ci: CI @source(value:"cmdb_ci.value")
15+
}
16+
17+
type User{
18+
sys_id:DisplayableString
19+
user_name:DisplayableString
20+
first_name:DisplayableString
21+
last_name:DisplayableString
22+
email:DisplayableString
23+
}
24+
25+
type CI{
26+
sys_id:DisplayableString
27+
install_status:DisplayableString
28+
name:DisplayableString
29+
}
30+
31+
type DisplayableString{
32+
value:String
33+
display_value:String
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function process(/*ResolverEnvironment*/ env) {
2+
3+
var sys_id=env.getArguments().sys_id;
4+
var INC = new GlideRecord("incident");
5+
INC.addQuery("sys_id",sys_id);
6+
INC.query();
7+
return INC;
8+
9+
10+
})(env);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Example of incident query for GraphQL API
2+
The code within this filder is just an example of working and basic implementation of sample incident details schema using GraphQL API in ServiceNow. It consist of:
3+
4+
1. schema (schema.gql)
5+
2. scripted resolvers (.js extension)
6+
3. json file representing the resolver mappings (key is Path, value is Resolver)
7+
This is just an example
8+
So read it, learn it and explore GraphQL 😊
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function process(/*ResolverEnvironment*/ env) {
2+
3+
var user= env.getSource();
4+
var User = new GlideRecord("sys_user");
5+
User.addQuery("sys_id",user);
6+
User.query();
7+
return User;
8+
9+
10+
})(env);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"incident:cmdb_ci": "CMDB Resolver",
3+
"incident:caller_id": "User Resolver",
4+
"Query:EntersysID":"Incident Resolver"
5+
}

0 commit comments

Comments
 (0)