pnwkit 3.0 - v4.3.0
    Preparing search index...

    Class ApiKeyDetailsQuery<F, I>

    Query builder for fetching API key details from the Politics & War API.

    Create new instances using the factory method: pnwkit.queries.apiKeyDetails() Each call creates a fresh instance with no shared state.

    Important differences from other queries:

    • Returns a single object, not an array
    • Does not support pagination (no first/page methods)
    • Does not accept filter parameters (where clause is empty)
    • Only has one relation: nation (the nation associated with the API key)

    Features:

    • Type-safe field selection
    • Nested relation support (unlimited depth through nation)
    • Automatic cardinality detection

    Return type:

    • execute() → Returns single API key details object (NOT an array)
    // Basic query - returns single object
    const apiKey = await pnwkit.queries.apiKeyDetails()
    .select('key', 'requests', 'max_requests', 'permissions')
    .execute();
    // Type: { key: string, requests: number, max_requests: number, permissions: string }
    console.log(apiKey.key); // Direct access - NOT apiKey[0].key

    // With nested nation data (singular relation)
    const apiKey = await pnwkit.queries.apiKeyDetails()
    .select('key', 'requests')
    .include('nation', builder => builder // Singular: returns single object
    .select('id', 'nation_name', 'score')
    )
    .execute();
    // Type: {
    // key: string,
    // requests: number,
    // nation: { id: number, nation_name: string, score: number }
    // }
    console.log(apiKey.nation.nation_name); // Direct access to nested object

    // Deep nesting through nation relation
    const apiKey = await pnwkit.queries.apiKeyDetails()
    .select('key')
    .include('nation', b1 => b1
    .select('id', 'nation_name')
    .include('alliance', b2 => b2 // Nest through nation's relations
    .select('id', 'name')
    .include('nations', b3 => b3 // Unlimited depth!
    .select('id', 'nation_name')
    )
    )
    )
    .execute();

    Type Parameters

    • F extends readonly Exclude<keyof ApiKeyDetailsFields, "__typename">[] = []

      Selected field names (tracked through chaining for precise autocomplete)

    • I extends Record<string, any> = {}

      Included relations (tracked through chaining with proper cardinality)

    Hierarchy

    • QueryBuilder<ApiKeyDetailsFields, ApiKeyDetailsQueryParams>
      • ApiKeyDetailsQuery
    Index
    apiKeyOverride?: string

    Per-call API key override, set via apiKey.

    filters: ApiKeyDetailsQueryParams = ...
    queryName: string = 'me'
    selectedFields: (
        "key"
        | "requests"
        | "max_requests"
        | "permissions"
        | "permission_bits"
    )[] = []
    skipCacheFlag: boolean = false

    When true, this call bypasses the response cache. Set via skipCache.

    subqueries: Map<string, SubqueryConfig<any, {}, Record<string, any>>> = ...
    MAX_ARRAY_SIZE: 1000
    MAX_FIELD_NAME_LENGTH: 100
    MAX_FIELDS_PER_LEVEL: 100
    MAX_NESTING_DEPTH: 10
    MAX_QUERY_SIZE: 50000
    MAX_STRING_LENGTH: 10000
    QUERIES_WITHOUT_DATA_WRAPPER: Set<string> = ...

    Queries that return data directly without wrapping in a 'data' object. These queries follow a different GraphQL schema structure.

    • Use a specific API key for this call instead of the client's default key.

      Parameters

      • key: string

        The Politics & War API key to authenticate this query with.

      Returns this

      This query builder instance for method chaining.

      await pnwkit.queries.nations()
      .select('id', 'nation_name')
      .apiKey('another-api-key')
      .execute();
    • Build the final GraphQL query string with comprehensive validation.

      Constructs a complete GraphQL query including:

      • Main fields and subqueries with proper formatting
      • Pagination variables (first, page)
      • Filter parameters with type-safe serialization
      • Optional paginator info fields

      Validation includes:

      • Field count limits (max 100 per level)
      • Field name format and length validation (max 100 chars)
      • Query size validation (max 50KB)
      • All filter values properly sanitized and escaped

      Parameters

      • includePaginator: boolean

        Whether to include pagination info in response

      Returns string

      Complete GraphQL query string ready for execution

      Error if field count/name/size limits exceeded or filters contain invalid values

    • Execute the API key details query and return a single object.

      Important: Unlike nations/alliances queries, this returns a single object, not an array. There is no pagination support.

      Results only include selected fields and included relations. All other fields are excluded from the response.

      Returns Promise<SelectFields<ApiKeyDetailsFields, F, I>>

      Single API key details object with selected fields and included relations

      Error if the query fails or returns no data

      // Returns single object (NOT an array)
      const apiKey = await query.execute();
      // Type: { key: string, requests: number }
      console.log(apiKey.key); // Direct access - no [0] needed

      // With nested data
      const apiKey = await pnwkit.queries.apiKeyDetails()
      .select('key')
      .include('nation', b => b.select('id', 'nation_name'))
      .execute();
      console.log(apiKey.nation.nation_name); // Direct nested access
    • Include related data in the query results

      Supports unlimited recursive nesting with full type inference at every level. Each nested builder receives complete type safety for fields, relations, and query parameters.

      Type Parameters

      • K extends "nation"
      • TConfig extends SubqueryConfig<
            ApiKeyDetailsRelations[K],
            GetRelationsFor<ApiKeyDetailsRelations[K]>,
            GetQueryParamsFor<ApiKeyDetailsRelations[K]>,
        >
      • TNestedResult = InferSubqueryType<ReturnType<TConfig>>
      • TWrappedResult = ApiKeyDetailsRelations[K] extends any[] ? TNestedResult[] : TNestedResult

      Parameters

      • relation: K

        The relation name to include

      • config: TConfig

        A builder function for configuring the subquery

      Returns ApiKeyDetailsQuery<F, I & Record<K, TWrappedResult>>

      New query instance with included relation

      // Basic subquery - include nation data
      .include('nation', builder => builder
      .select('id', 'nation_name', 'score')
      )

      // Deeply nested query with unlimited depth
      .include('nation', builder => builder
      .select('id', 'nation_name')
      .include('alliance', builder2 => builder2
      .select('id', 'name', 'score')
      .include('nations', builder3 => builder3
      .select('id', 'nation_name')
      )
      )
      )

      // Important: Always select at least one scalar field at each level
      // GraphQL requires this - you cannot query an object without selecting fields
    • Sanitize and escape a string value for safe GraphQL usage.

      Validates input type and length, checks for null bytes, and escapes special characters including backslashes, quotes, newlines, carriage returns, tabs, form feeds, and backspaces.

      Parameters

      • str: string

        The string to sanitize

      Returns string

      Sanitized string with all special characters properly escaped

      Error if input is not a string, exceeds maximum length (10KB), or contains null bytes

    • Select specific fields to retrieve from API key details

      Type Parameters

      • const Fields extends readonly (
            "key"
            | "requests"
            | "max_requests"
            | "permissions"
            | "permission_bits"
        )[]

      Parameters

      • ...fields: Fields

        Field names to select

      Returns ApiKeyDetailsQuery<Fields>

      New query instance with selected fields

      Error if no fields are provided

      .select('key', 'requests', 'max_requests', 'permissions')
      
    • Serialize an object to GraphQL format (enum values without quotes).

      Validates object structure and prevents prototype pollution by:

      • Using own properties only (not inherited)
      • Blocking dangerous keys (proto, constructor, prototype)
      • Validating GraphQL field name format
      • Validating enum value format (uppercase with underscores)
      • Ensuring numbers are finite (rejecting NaN, Infinity)

      Parameters

      • obj: Record<string, any>

        Plain object to serialize (not arrays)

      Returns string

      GraphQL-formatted object string in format {key:value, ...}

      Error if object is null/undefined/array, contains invalid field names, or has unsafe values

    • Bypass the response cache for this call.

      Only meaningful when caching is enabled on the client (cache.enabled). The result is fetched fresh from the API and is neither read from nor written to the cache. No effect when caching is disabled.

      Returns this

      This query builder instance for method chaining.

      await pnwkit.queries.nations()
      .select('id', 'nation_name')
      .skipCache()
      .execute();
    • Apply filters to the query (not supported for API key details)

      Parameters

      • filters: ApiKeyDetailsQueryParams

        Query parameters (empty for this query)

      Returns this

      This query instance for method chaining

      .where({})  // No filters available for API key details