File tree Expand file tree Collapse file tree 6 files changed +77
-0
lines changed
GraphQL/Sample INC Details GraphQL Code Snippet Expand file tree Collapse file tree 6 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change
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 😊
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "incident:cmdb_ci" : "CMDB Resolver" ,
3
+ "incident:caller_id" : "User Resolver" ,
4
+ "Query:EntersysID" :"Incident Resolver"
5
+ }
You can’t perform that action at this time.
0 commit comments