Skip to content

Commit 1bb9aed

Browse files
feat(Incident-GraphQL-Resolver): polish README, update schema and TypeScript types with examples
1 parent c4bf84d commit 1bb9aed

File tree

4 files changed

+127
-29
lines changed

4 files changed

+127
-29
lines changed

Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// A wrapper for fields that return both a raw value and a display value
2+
export type DisplayableString = {
3+
value: string // Raw value (e.g., sys_id, code)
4+
display_value: string // Human-readable value (e.g., "John Doe")
5+
}
6+
7+
// Represents a User record in ServiceNow
8+
export type User = {
9+
sys_id: DisplayableString // Unique system identifier of the user
10+
user_name: DisplayableString // Username (login name)
11+
first_name: DisplayableString // User's first name
12+
last_name: DisplayableString // User's last name
13+
}
14+
15+
// Represents a Configuration Item (CI) record
16+
export type CI = {
17+
sys_id: DisplayableString // Unique system identifier of the CI
18+
install_status: DisplayableString // Installation status (e.g., installed, pending)
19+
name: DisplayableString // Display name of the CI
20+
}
21+
22+
// Represents an Incident record in ServiceNow
23+
export type Incident = {
24+
sys_id: DisplayableString // Unique system identifier of the incident
25+
number: DisplayableString // Incident number
26+
short_description: DisplayableString // Brief description of the incident
27+
caller_id: User // Linked User record (caller)
28+
cmdb_ci: CI // Linked Configuration Item record
29+
}

Integration/GraphQL Integration API/Incident GraphQL resolvers/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,61 @@ I have created a graphql API, which helps to get the details of incident record
22
User Resolver: It will help to get the details of caller_id like (sys_id, first_name, last_name etc.) from the server.
33
CI Resolver: It will help to get the details of configuration item like (sys_id, operational_status etc.)from the server .
44
Incident Resolver: It will help to get the details of incident from the server (like short_description, description etc.) based on provided sys_id in schema .
5+
6+
### Folder Structure
7+
8+
- `schema.graphql`
9+
Contains the GraphQL schema defining queries and types (Incident, User, CI, DisplayableString).
10+
11+
- `types.ts`
12+
TypeScript type aliases matching the schema for type safety and IDE autocompletion.
13+
14+
### How It Works
15+
16+
1. Client queries the API using `EntersysId(sys_id: ID!)`.
17+
2. Incident Resolver fetches the main incident record.
18+
3. User Resolver fetches the caller details for `caller_id`.
19+
4. CI Resolver fetches the configuration item details for `cmdb_ci`.
20+
5. API returns a nested object containing Incident, User, and CI information.
21+
22+
### Example Query
23+
24+
```graphql
25+
query {
26+
EntersysId(sys_id: "12345") {
27+
number {
28+
value
29+
display_value
30+
}
31+
short_description {
32+
value
33+
}
34+
caller_id {
35+
first_name {
36+
value
37+
}
38+
last_name {
39+
value
40+
}
41+
}
42+
cmdb_ci {
43+
name {
44+
value
45+
}
46+
install_status {
47+
value
48+
}
49+
}
50+
}
51+
}
52+
```
53+
54+
### Notes / Contribution
55+
56+
```
57+
- The schema and types help developers understand the API structure.
58+
- Contributions are welcome, such as:
59+
- Adding more example queries
60+
- Adding error handling
61+
- Improving documentation for nested fields
62+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Entry point of the GraphQL schema
2+
schema {
3+
query: Query
4+
}
5+
6+
# Root query type - defines the queries clients can run
7+
type Query {
8+
# Fetch an Incident by sys_id (unique identifier)
9+
EntersysId(sys_id: ID!): Incident
10+
}
11+
12+
# Incident type - represents an Incident record in ServiceNow
13+
type Incident {
14+
sys_id: DisplayableString # Unique system identifier of the incident
15+
number: DisplayableString # Incident number
16+
short_description: DisplayableString # Brief description of the incident
17+
caller_id: User @source(value: "caller_id.value") # Linked user (caller) record
18+
cmdb_ci: CI @source(value: "cmdb_ci.value") # Linked configuration item (CI) record
19+
}
20+
21+
# User type - represents a caller or user record
22+
type User {
23+
sys_id: DisplayableString # Unique system identifier of the user
24+
user_name: DisplayableString # Username (login name)
25+
first_name: DisplayableString # User's first name
26+
last_name: DisplayableString # User's last name
27+
}
28+
29+
# CI type - represents a configuration item (e.g., server, application, device)
30+
type CI {
31+
sys_id: DisplayableString # Unique system identifier of the CI
32+
install_status: DisplayableString # Installation status of the CI
33+
name: DisplayableString # Display name of the CI
34+
}
35+
36+
# DisplayableString type - wrapper for both raw and display values in ServiceNow
37+
type DisplayableString {
38+
value: String # Raw value (e.g., sys_id or code)
39+
display_value: String # Human-readable label for the value
40+
}

0 commit comments

Comments
 (0)