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

    Class NationResourceStatsQuery<F, I>

    Query builder for fetching nation resource statistics from the Politics & War API.

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

    Nation resource stats provide historical data on resource holdings for a specific nation.

    Features:

    • Type-safe field selection and filtering
    • Date range filtering (before/after)
    • Sorting support with orderBy
    • Pagination support with optional paginatorInfo

    Return types:

    • execute() → Returns array of resource stats
    • execute(true) → Returns { data: NationResourceStats[], paginatorInfo: {...} }
    // Basic query with field selection
    const stats = await pnwkit.queries.nationResourceStats()
    .select('date', 'money', 'food', 'steel')
    .where({
    after: '2025-01-01',
    orderBy: { column: Enum('DATE'), order: Enum('DESC') }
    })
    .first(50)
    .execute();
    // Type: { date: string, money: string, food: string, steel: string }[]

    // Query all resources with date filtering
    const allStats = await pnwkit.queries.nationResourceStats()
    .select('date', 'money', 'food', 'steel', 'aluminum', 'gasoline')
    .where({
    before: '2025-12-31',
    after: '2025-01-01'
    })
    .execute();

    // With pagination info
    const result = await pnwkit.queries.nationResourceStats()
    .select('date', 'money', 'food')
    .first(100)
    .execute(true);
    console.log(result.data); // Resource stats array
    console.log(result.paginatorInfo); // Pagination metadata

    Type Parameters

    • F extends readonly Exclude<keyof NationResourceStatsFields, "__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<NationResourceStatsFields, NationResourceStatsQueryParams>
      • NationResourceStatsQuery
    Index
    apiKeyOverride?: string

    Per-call API key override, set via apiKey.

    filters: NationResourceStatsQueryParams = ...
    queryName: string = 'nation_resource_stats'
    selectedFields: (
        | "date"
        | "money"
        | "coal"
        | "oil"
        | "uranium"
        | "iron"
        | "bauxite"
        | "lead"
        | "gasoline"
        | "munitions"
        | "steel"
        | "aluminum"
        | "food"
    )[] = []
    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 nation resource stats query and return results.

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns array of resource stats
      • 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<NationResourceStatsFields, F, I>[]>

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

      Error if the query fails or returns no data

      // Returns array directly
      const stats = await query.execute();
      // Type: { date: string, money: string, food: string }[]
      stats.forEach(stat => console.log(stat.date, stat.money));

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

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns array of resource stats
      • 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<NationResourceStatsFields, F, I>[];
              paginatorInfo: paginatorInfo;
          },
      >

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

      Error if the query fails or returns no data

      // Returns array directly
      const stats = await query.execute();
      // Type: { date: string, money: string, food: string }[]
      stats.forEach(stat => console.log(stat.date, stat.money));

      // Returns object with pagination info
      const result = await query.execute(true);
      // Type: { data: {...}[], paginatorInfo: {...} }
      console.log(result.data); // Resource stats 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<
            NationResourceStatsRelations[K],
            GetRelationsFor<NationResourceStatsRelations[K]>,
            GetQueryParamsFor<NationResourceStatsRelations[K]>,
        >
      • TNestedResult = InferSubqueryType<ReturnType<TConfig>>
      • TWrappedResult = NationResourceStatsRelations[K] extends any[] ? TNestedResult[] : TNestedResult

      Parameters

      • relation: K

        The relation name to include

      • config: TConfig

        A builder function for configuring the subquery

      Returns NationResourceStatsQuery<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 nation resource stats

      Type Parameters

      • const Fields extends readonly (
            | "date"
            | "money"
            | "coal"
            | "oil"
            | "uranium"
            | "iron"
            | "bauxite"
            | "lead"
            | "gasoline"
            | "munitions"
            | "steel"
            | "aluminum"
            | "food"
        )[]

      Parameters

      • ...fields: Fields

        Field names to select

      Returns NationResourceStatsQuery<Fields>

      New query instance with selected fields

      Error if no fields are provided

      .select('date', 'money', 'food', 'steel', 'aluminum')
      
    • 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: NationResourceStatsQueryParams

        Query parameters for filtering results

      Returns this

      This query instance for method chaining

      .where({ 
      before: '2025-12-31',
      after: '2025-01-01',
      orderBy: { column: Enum('DATE'), order: Enum('DESC') }
      })