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

    Class TopTradeInfoQuery<F, I>

    Query builder for fetching top trade information from the Politics & War API.

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

    Top trade info provides current market data including market index and resource-specific trade information with best buy/sell offers.

    Features:

    • Type-safe field selection
    • Access to real-time market index and resource prices
    • Best buy/sell offer data per resource

    Return types:

    • execute() → Returns top trade info object
    • execute(true) → Returns { data: TopTradeInfo, paginatorInfo: {...} }
    // Basic query with fields
    const tradeInfo = await pnwkit.queries.topTradeInfo()
    .select('market_index')
    .include('resources', builder => builder
    .select('resource', 'average_price')
    )
    .execute();
    // Type: { market_index: number, resources: { resource: string, average_price: number }[] }

    // Access the data
    console.log(tradeInfo.market_index);
    console.log(tradeInfo.resources[0].resource); // "FOOD"
    console.log(tradeInfo.resources[0].average_price); // Current avg price

    // With pagination info
    const result = await pnwkit.queries.topTradeInfo()
    .select('market_index')
    .include('resources', builder => builder
    .select('resource', 'average_price')
    )
    .execute(true);
    console.log(result.data); // Trade info object
    console.log(result.paginatorInfo); // Pagination metadata

    Type Parameters

    • F extends readonly Exclude<keyof TopTradeInfoFields, "__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<TopTradeInfoFields, TopTradeInfoQueryParams>
      • TopTradeInfoQuery
    Index
    apiKeyOverride?: string

    Per-call API key override, set via apiKey.

    filters: TopTradeInfoQueryParams = ...
    queryName: string = 'top_trade_info'
    selectedFields: "market_index"[] = []
    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 top trade info query and return results.

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns single top trade info object
      • execute(true) → Returns object with data and paginatorInfo

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

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

      Single top trade info object, or object with data and paginatorInfo if withPaginator is true

      Error if the query fails or returns no data

      // Returns single object directly
      const tradeInfo = await query.execute();
      // Type: { market_index: number, resources: TopTradeResourceInfo[] }
      console.log(tradeInfo.market_index);
      console.log(tradeInfo.resources[0].average_price);

      // Returns object with pagination info
      const result = await query.execute(true);
      // Type: { data: {...}, paginatorInfo: {...} }
      console.log(result.data); // Trade info object
      console.log(result.paginatorInfo.total); // Total count
    • Execute the top trade info query and return results.

      Return type changes based on withPaginator parameter:

      • execute() or execute(false) → Returns single top trade info object
      • execute(true) → Returns object with data and paginatorInfo

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

      Parameters

      • withPaginator: true

      Returns Promise<
          {
              data: SelectFields<TopTradeInfoFields, F, I>;
              paginatorInfo: paginatorInfo;
          },
      >

      Single top trade info object, or object with data and paginatorInfo if withPaginator is true

      Error if the query fails or returns no data

      // Returns single object directly
      const tradeInfo = await query.execute();
      // Type: { market_index: number, resources: TopTradeResourceInfo[] }
      console.log(tradeInfo.market_index);
      console.log(tradeInfo.resources[0].average_price);

      // Returns object with pagination info
      const result = await query.execute(true);
      // Type: { data: {...}, paginatorInfo: {...} }
      console.log(result.data); // Trade info object
      console.log(result.paginatorInfo.total); // Total count
    • Include related data in the query results

      Type Parameters

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

      Parameters

      • relation: K

        The relation name to include

      • config: TConfig

        A builder function for configuring the subquery

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

      New query instance with included relation

      // Include resources with specific fields
      .include('resources', builder => builder
      .select('resource', 'average_price')
      )
    • 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

    • 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: TopTradeInfoQueryParams

        Query parameters for filtering results

      Returns this

      This query instance for method chaining

      .where({ resources: [Resources.FOOD, Resources.COAL] })