How vtex-apps/search-resolver works
1. What this repo is
This is a VTEX IO GraphQL resolver app that implements the VTEX search protocol described by search-graphql. Its job is not to serve a UI, but to expose GraphQL fields that translate search-related requests into VTEX backend API calls.
2. Primary runtime boundary
The main execution path starts in node/index.ts and is organized around GraphQL resolvers. The code is TypeScript-based, runs in the Node runtime, and is packaged as a VTEX app via manifest.json, node/service.json, and the .vtex deployment metadata.
3. API layer: resolvers
The node/resolvers folder is the GraphQL-facing boundary. It is split by domain:
- resolvers/search: product, SKU, category, brand, autocomplete, recommendation, breadcrumbs, pricing, metadata, URLs, and related search entities.
- resolvers/stats: search analytics/count-style endpoints.
- resolvers/benefits: benefit-related search data.
These resolvers shape the GraphQL response and delegate almost all data access to services.
4. Service layer: business orchestration
The node/services folder contains the main orchestration logic. This layer aggregates and normalizes data before it reaches resolvers. Key service areas are:
- product, productSearch, facets, autocomplete
- banners, settings, pdpConfig
This is where request-level composition happens, including combining search results, facet metadata, and product-related enrichment.
5. Client layer: external VTEX API access
The node/clients folder isolates calls to external VTEX services:
- search.ts for catalog/search API access
- checkout.ts for checkout/product pricing-related data
- rewriter.ts for URL/query rewriting behavior
- intelligent-search-api.ts and clients/intsch for Intelligent Search integrations
This boundary matters because most repository logic is about adapting these APIs into the search-graphql schema.
6. Intelligent Search integration
The node/clients/intsch submodule is a specialized adapter with its own types and utilities. It indicates the app supports VTEX Intelligent Search as a separate backend path, likely used by autocomplete, search queries, or metadata enrichment when configured.
7. GraphQL field modifiers
node/directives contains custom GraphQL directives such as withSegment and toVtexAssets. These are cross-cutting schema behaviors that alter resolution based on context or transform asset URLs/paths, rather than being part of the core search logic.
8. Shared utilities and domain transformations
node/utils holds reusable domain logic: category tree traversal, search state parsing, slug/string helpers, cookie handling, comparisons, fallback behavior, and VTEX-specific helpers like vbase. These utilities are used across services and resolvers to keep protocol translation consistent.
9. Compatibility and feature control
node/commons/compatibility-layer.ts and node/featureFlags.ts indicate the app supports legacy behavior and conditional paths. In an architecture diagram, these should be shown as a cross-cutting layer between resolvers/services and the lower-level clients, because they influence how requests are interpreted or which backend behavior is selected.
10. Data flow to draw
The most important flow is:
GraphQL request → resolver → service orchestration → VTEX client(s) → external VTEX APIs → normalized response back through resolver.
Some flows also incorporate directives, feature flags, and compatibility adjustments before the service/client call, plus tests and mocks around each layer to validate those transformations.
11. Testing and contract protection
The repository includes many colocated tests under node/resolvers, node/services, and node/utils, plus mocks under node/__mocks__ and node/mocks. This suggests the architecture is heavily contract-driven: tests validate the mapping from VTEX backend shapes to the GraphQL search schema.
12. Operational shape
The app is designed to be deployed as a VTEX service, not as a standalone server. The key operational dependencies are the VTEX catalog/search/checkout endpoints and, optionally, Intelligent Search. The repo’s structure makes the separation between schema, orchestration, external API adapters, and shared search-domain utilities very explicit.
Main entry points: search/index.ts Search resolvers · productSearch.ts Search service · product.ts Product service · resolvers/index.ts Resolvers
Components 21
Runtime
Node/VTEX app entrypoint and deployment boundary
- App entry · Bootstraps the Node runtime and wires the GraphQL service
node/index.ts
GraphQL API
Resolvers and directives exposed to GraphQL
- Resolvers · GraphQL boundary for search, stats, and benefits
node/resolvers/index.ts - Search resolvers · Search-facing query and field resolvers
node/resolvers/search/index.ts - Stats resolvers · Search count and analytics resolvers
node/resolvers/stats/index.ts - Benefits resolvers · Benefit-related search resolvers
node/resolvers/benefits/index.ts - Directives · Cross-cutting GraphQL behaviors and transforms
node/directives/index.ts
Services
Request orchestration and domain composition
- Product service · Product and SKU composition logic
node/services/product.ts - Search service · Search result normalization and request shaping
node/services/productSearch.ts - Facets service · Facet aggregation and search metadata assembly
node/services/facets.ts - Autocomplete · Autocomplete orchestration and suggestion shaping
node/services/autocomplete.ts - Settings · App and search configuration access
node/services/settings.ts - PDP config · Product detail page configuration helpers
node/services/pdpConfig.ts
Clients
Adapters for external VTEX APIs and Intelligent Search
- Search API · Catalog and search backend adapter
node/clients/search.ts - Checkout API · Checkout and pricing-related backend adapter
node/clients/checkout.ts - Rewriter · URL and query rewriting adapter
node/clients/rewriter.ts - Intelligent Search · Specialized Intelligent Search integration path
node/clients/intelligent-search-api.ts
Shared
Common utilities, compatibility, and feature control
- Compatibility · Legacy behavior and request compatibility handling
node/commons/compatibility-layer.ts - Feature flags · Conditional behavior and rollout control
node/featureFlags.ts - Utilities · Shared search, category, slug, cookie, and fallback helpers
node/utils/index.ts
Ops
Deployment, packaging, and test support
- Mocks & tests · Colocated tests and mock fixtures protecting contracts
node/mocks/contextFactory.ts - Deployment · App manifest, service config, and VTEX deployment metadata
manifest.json
Connections 33
- App entry → Resolvers: wires · Initializes resolver runtime
- Resolvers → Search resolvers: routes · Search schema fields
- Resolvers → Stats resolvers: routes · Stats schema fields
- Resolvers → Benefits resolvers: routes · Benefits schema fields
- Search resolvers → Product service: delegates · Product and SKU resolution
- Search resolvers → Search service: delegates · Search result resolution
- Search resolvers → Facets service: delegates · Facet and metadata resolution
- Search resolvers → Autocomplete: delegates · Autocomplete resolution
- Search resolvers → Settings: reads · Uses configured search behavior
- Search resolvers → PDP config: reads · Uses PDP-specific configuration
- Stats resolvers → Search service: reads · Counts and query stats
- Benefits resolvers → Product service: delegates · Benefit lookups use product context
- Product service → Search API: calls · Fetches catalog and search data
- Product service → Checkout API: calls · Enriches with pricing and checkout data
- Search service → Search API: calls · Queries search backend
- Search service → Rewriter: calls · Resolves rewritten URLs
- Search service → Intelligent Search: optionally uses · Uses Intelligent Search when enabled
- Facets service → Search API: calls · Builds facet trees from search data
- Autocomplete → Intelligent Search: optionally uses · Prefers Intelligent Search suggestions when configured
- Search resolvers → Directives: uses · Applies schema-level transforms
- Stats resolvers → Directives: uses · Applies schema-level transforms
- Product service → Compatibility: adapts · Maintains legacy request behavior
- Search service → Compatibility: adapts · Normalizes legacy search semantics
- Search service → Feature flags: checks · Selects conditional behavior paths
- Product service → Utilities: uses · Shared normalization helpers
- Search service → Utilities: uses · Shared search and string helpers
- Facets service → Utilities: uses · Category and search-state helpers
- Directives → Utilities: uses · URL and asset transforms
- Mocks & tests → Search resolvers: covers · Resolver contract tests and fixtures
- Mocks & tests → Product service: covers · Service behavior tests and mocks
- Mocks & tests → Utilities: covers · Utility-level contract tests
- Deployment → App entry: packages · Deploys the Node app as a VTEX service
- Deployment → Resolvers: exposes · Publishes the GraphQL surface