-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocks.js.example
More file actions
66 lines (60 loc) · 2.09 KB
/
mocks.js.example
File metadata and controls
66 lines (60 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Centralized Mock Configuration
*
* This file defines mock resolvers for all subgraphs in the federated GraphQL setup.
*
* STRUCTURE:
* -----------
* The mocks object is organized into the following sections:
*
* 1. _globals: Default type resolvers that apply to ALL subgraphs
* - Used when a subgraph doesn't define a specific mock for a type
* - Provides consistent fallback values across all subgraphs
*
* 2. [subgraphName]: Subgraph-specific type resolvers
* - Each subgraph can override global mocks with its own implementations
* - Subgraph-specific types (e.g., Product, User, Order) are defined here
*
* PRECEDENCE RULES:
* -----------------
* When resolving a mock for a type in a specific subgraph:
* 1. First, check if subgraph has a specific mock for the type
* 2. If not found, fall back to _globals mock for that type
* 3. If still not found, use graphql-tools/mock default mock behavior
*
* Example:
* - Request to 'products' subgraph for an 'Int' → uses products.Int (if defined)
* - If products.Int doesn't exist → uses _globals.Int
* - Request for 'Product' type → uses products.Product (subgraph-specific)
*
*/
export const mocks = {
/**
* GLOBAL TYPE RESOLVERS
*
* These mocks apply to all subgraphs by default unless overridden.
* Common scalar types and standard patterns should be defined here.
*/
_globals: {
// Scalar Types
ID: () => `default-id-${Math.random().toString(36).substring(2, 9)}`,
DateTime: () => new Date().toISOString(),
},
/**
* PRODUCTS SUBGRAPH
*
* Mock resolvers for the products subgraph.
* Handles product catalog, inventory, and related operations.
*/
products: {
// Override global Int for products-specific IDs
Int: () => Math.floor(Math.random() * 10000),
// Override global String for product-specific text
String: () => 'Product Default String',
// Product entity - primary type for this subgraph
Product: () => ({
// id: `product-${Math.floor(Math.random() * 1000)}`,
name: () => `Product ${Math.floor(Math.random() * 1000)}`,
}),
},
};