isGQLRequest (helpers/request-type.ts)

hoppscotch · packages/hoppscotch-common/src/helpers/request-type.ts · typescript · MIT
auth

Provides type guards to determine if a request object is GraphQL or REST and checks for shared secrets.

// Source: https://github.com/hoppscotch/hoppscotch | License: MIT | Copyright 2022
// Provided via justclaw.it.com; keep this notice with the code.
import {
  HoppGQLRequest,
  HoppGQLResponseOriginalRequest,
  HoppRESTRequest,
  HoppRESTResponseOriginalRequest,
} from "@hoppscotch/data"

type AnyRequest =
  | HoppRESTRequest
  | HoppRESTResponseOriginalRequest
  | HoppGQLRequest
  | HoppGQLResponseOriginalRequest

/**
 * The `in` operator throws on `null`/primitives, so every shape guard below
 * has to establish "is a non-null object" before probing for keys — callers
 * feed these raw persisted and imported JSON.
 */
const isRequestObject = (req: AnyRequest): req is AnyRequest =>
  !!req && typeof req === "object"

/**
 * Type guard to check if a request object is GraphQL-shaped.
 * GQ

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key