Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// A wrapper for fields that return both a raw value and a display value
export type DisplayableString = {
value: string // Raw value (e.g., sys_id, code)
display_value: string // Human-readable value (e.g., "John Doe")
}

// Represents a User record in ServiceNow
export type User = {
sys_id: DisplayableString // Unique system identifier of the user
user_name: DisplayableString // Username (login name)
first_name: DisplayableString // User's first name
last_name: DisplayableString // User's last name
}

// Represents a Configuration Item (CI) record
export type CI = {
sys_id: DisplayableString // Unique system identifier of the CI
install_status: DisplayableString // Installation status (e.g., installed, pending)
name: DisplayableString // Display name of the CI
}

// Represents an Incident record in ServiceNow
export type Incident = {
sys_id: DisplayableString // Unique system identifier of the incident
number: DisplayableString // Incident number
short_description: DisplayableString // Brief description of the incident
caller_id: User // Linked User record (caller)
cmdb_ci: CI // Linked Configuration Item record
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,61 @@ I have created a graphql API, which helps to get the details of incident record
User Resolver: It will help to get the details of caller_id like (sys_id, first_name, last_name etc.) from the server.
CI Resolver: It will help to get the details of configuration item like (sys_id, operational_status etc.)from the server .
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 .

### Folder Structure

- `schema.graphql`
Contains the GraphQL schema defining queries and types (Incident, User, CI, DisplayableString).

- `types.ts`
TypeScript type aliases matching the schema for type safety and IDE autocompletion.

### How It Works

1. Client queries the API using `EntersysId(sys_id: ID!)`.
2. Incident Resolver fetches the main incident record.
3. User Resolver fetches the caller details for `caller_id`.
4. CI Resolver fetches the configuration item details for `cmdb_ci`.
5. API returns a nested object containing Incident, User, and CI information.

### Example Query

```graphql
query {
EntersysId(sys_id: "12345") {
number {
value
display_value
}
short_description {
value
}
caller_id {
first_name {
value
}
last_name {
value
}
}
cmdb_ci {
name {
value
}
install_status {
value
}
}
}
}
```

### Notes / Contribution

```
- The schema and types help developers understand the API structure.
- Contributions are welcome, such as:
- Adding more example queries
- Adding error handling
- Improving documentation for nested fields
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Entry point of the GraphQL schema
schema {
query: Query
}

# Root query type - defines the queries clients can run
type Query {
# Fetch an Incident by sys_id (unique identifier)
EntersysId(sys_id: ID!): Incident
}

# Incident type - represents an Incident record in ServiceNow
type Incident {
sys_id: DisplayableString # Unique system identifier of the incident
number: DisplayableString # Incident number
short_description: DisplayableString # Brief description of the incident
caller_id: User @source(value: "caller_id.value") # Linked user (caller) record
cmdb_ci: CI @source(value: "cmdb_ci.value") # Linked configuration item (CI) record
}

# User type - represents a caller or user record
type User {
sys_id: DisplayableString # Unique system identifier of the user
user_name: DisplayableString # Username (login name)
first_name: DisplayableString # User's first name
last_name: DisplayableString # User's last name
}

# CI type - represents a configuration item (e.g., server, application, device)
type CI {
sys_id: DisplayableString # Unique system identifier of the CI
install_status: DisplayableString # Installation status of the CI
name: DisplayableString # Display name of the CI
}

# DisplayableString type - wrapper for both raw and display values in ServiceNow
type DisplayableString {
value: String # Raw value (e.g., sys_id or code)
display_value: String # Human-readable label for the value
}
Loading