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

    Class ColorsQuery<F, I>

    Query builder for fetching color trade bloc data from the Politics & War API.

    Create new instances using the factory method: pnwkit.queries.colors() Each call creates a fresh instance with no shared state, preventing filter pollution.

    Colors represent trade blocs in the game, each providing different bonuses and benefits.

    Features:

    • Type-safe field selection
    • Access to color names, bloc names, and turn bonuses
    • No filtering parameters (returns all colors)

    Return types:

    • execute() → Returns array of colors
    • execute(true) → Returns { data: Color[], paginatorInfo: {...} }
    // Basic query with field selection
    const colors = await pnwkit.queries.colors()
    .select('color', 'bloc_name', 'turn_bonus')
    .execute();
    // Type: { color: string, bloc_name: string, turn_bonus: number }[]

    // Query all available colors
    const allColors = await pnwkit.queries.colors()
    .select('color', 'bloc_name')
    .execute();
    console.log(allColors); // Array of all colors

    // With pagination info
    const result = await pnwkit.queries.colors()
    .select('color', 'bloc_name', 'turn_bonus')
    .execute(true);
    console.log(result.data); // Colors array
    console.log(result.paginatorInfo); // Pagination metadata

    Type Parameters

    • F extends readonly Exclude<keyof ColorFields, "__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<ColorFields, ColorQueryParams>
      • ColorsQuery
    Index
    apiKeyOverride?: string

    Per-call API key override, set via apiKey.

    filters: ColorQueryParams = ...
    queryName: string = 'colors'
    selectedFields: ("color" | "bloc_name" | "turn_bonus")[] = []
    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 colors query and return results.

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns array of colors
      • execute(true) → Returns object with data array and paginatorInfo

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

      Returns Promise<SelectFields<ColorFields, F, I>[]>

      Array of colors, or object with data and paginatorInfo if withPaginator is true

      Error if the query fails or returns no data

      // Returns array directly
      const colors = await query.execute();
      // Type: { color: string, bloc_name: string, turn_bonus: number }[]
      colors.forEach(color => console.log(color.color, color.bloc_name));

      // Returns object with pagination info
      const result = await query.execute(true);
      // Type: { data: {...}[], paginatorInfo: {...} }
      console.log(result.data); // Colors array
      console.log(result.paginatorInfo.total); // Total count
      console.log(result.paginatorInfo.currentPage); // Current page number
    • Execute the colors query and return results.

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns array of colors
      • execute(true) → Returns object with data array and paginatorInfo

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

      Parameters

      • withPaginator: true

      Returns Promise<
          {
              data: SelectFields<ColorFields, F, I>[];
              paginatorInfo: paginatorInfo;
          },
      >

      Array of colors, or object with data and paginatorInfo if withPaginator is true

      Error if the query fails or returns no data

      // Returns array directly
      const colors = await query.execute();
      // Type: { color: string, bloc_name: string, turn_bonus: number }[]
      colors.forEach(color => console.log(color.color, color.bloc_name));

      // Returns object with pagination info
      const result = await query.execute(true);
      // Type: { data: {...}[], paginatorInfo: {...} }
      console.log(result.data); // Colors array
      console.log(result.paginatorInfo.total); // Total count
      console.log(result.paginatorInfo.currentPage); // Current page number
    • 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 never
      • TConfig extends SubqueryConfig<
            ColorRelations[K],
            GetRelationsFor<ColorRelations[K]>,
            GetQueryParamsFor<ColorRelations[K]>,
        >
      • TNestedResult = InferSubqueryType<ReturnType<TConfig>>
      • TWrappedResult = ColorRelations[K] extends any[] ? TNestedResult[] : TNestedResult

      Parameters

      • relation: K

        The relation name to include

      • config: TConfig

        A builder function for configuring the subquery

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

      New query instance with included relation

      // Basic subquery with field selection
      .include('nation', builder => builder
      .select('id', 'nation_name', 'score')
      )

      // Subquery with filtering and nesting
      .include('nation', builder => builder
      .select('id', 'nation_name')
      .where({ min_score: 1000 })
      .include('alliance', builder2 => builder2 // Unlimited nesting!
      .select('id', 'name', 'score')
      )
      )

      // 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 colors

      Type Parameters

      • const Fields extends readonly ("color" | "bloc_name" | "turn_bonus")[]

      Parameters

      • ...fields: Fields

        Field names to select

      Returns ColorsQuery<Fields>

      New query instance with selected fields

      Error if no fields are provided

      .select('color', 'bloc_name', 'turn_bonus')
      
    • 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

      Parameters

      • filters: ColorQueryParams

        Query parameters for filtering results

      Returns this

      This query instance for method chaining

      Colors query does not support filtering parameters

      .where({})