From 1bb9aed70cae005537bb645999086d245a1a7930 Mon Sep 17 00:00:00 2001 From: Shikhar Shetty Date: Wed, 1 Oct 2025 11:36:22 +0530 Subject: [PATCH] feat(Incident-GraphQL-Resolver): polish README, update schema and TypeScript types with examples --- .../GraphQL schema.js | 29 ---------- .../GraphQL schema.ts | 29 ++++++++++ .../Incident GraphQL resolvers/README.md | 58 +++++++++++++++++++ .../Incident GraphQL resolvers/schema.graphql | 40 +++++++++++++ 4 files changed, 127 insertions(+), 29 deletions(-) delete mode 100644 Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.js create mode 100644 Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.ts create mode 100644 Integration/GraphQL Integration API/Incident GraphQL resolvers/schema.graphql diff --git a/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.js b/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.js deleted file mode 100644 index d4ca5459a3..0000000000 --- a/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.js +++ /dev/null @@ -1,29 +0,0 @@ -schema { - query: Query -} - -type Query { - EntersysId(sys_id:ID!):incident // Entery point of data, you can define your own as per your requirement. -} -type incident{ - sys_id:DisplayableString // This is the type of data. - number:DisplayableString - short_description:DisplayableString - caller_id:User @source(value:"caller_id.value") // @source is used for extended tables, here caller_id extends to sys_user table. - cmdb_ci:CI @source(value:"cmdb_ci.value") //@source is used for extended tables, here configuration item extends to cmdb_ci table. -} -type User{ - sys_id:DisplayableString - user_name:DisplayableString // This will return the information of user (caller_id). - first_name:DisplayableString - last_name:DisplayableString -} -type CI{ - sys_id:DisplayableString - install_status:DisplayableString // This will return the information of configuration item (CI). - name:DisplayableString -} -type DisplayableString{ - value:String \\ This will return the value. - display_value:String \\This will return the display value. -} diff --git a/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.ts b/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.ts new file mode 100644 index 0000000000..4f3cd0eac4 --- /dev/null +++ b/Integration/GraphQL Integration API/Incident GraphQL resolvers/GraphQL schema.ts @@ -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 +} diff --git a/Integration/GraphQL Integration API/Incident GraphQL resolvers/README.md b/Integration/GraphQL Integration API/Incident GraphQL resolvers/README.md index c9aada77c6..b174129eca 100644 --- a/Integration/GraphQL Integration API/Incident GraphQL resolvers/README.md +++ b/Integration/GraphQL Integration API/Incident GraphQL resolvers/README.md @@ -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 +``` \ No newline at end of file diff --git a/Integration/GraphQL Integration API/Incident GraphQL resolvers/schema.graphql b/Integration/GraphQL Integration API/Incident GraphQL resolvers/schema.graphql new file mode 100644 index 0000000000..c4107cb7b0 --- /dev/null +++ b/Integration/GraphQL Integration API/Incident GraphQL resolvers/schema.graphql @@ -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 +}