@doswiftly/storefront-operations 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +195 -0
- package/fragments.graphql +1152 -0
- package/index.js +15 -0
- package/mutations.graphql +433 -0
- package/package.json +35 -0
- package/queries.graphql +355 -0
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# @doswiftly/storefront-operations
|
|
2
|
+
|
|
3
|
+
Pre-built GraphQL operations for DoSwiftly e-commerce storefronts. Contains ready-to-use queries, mutations, and fragments for products, collections, cart, checkout, and customer management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @doswiftly/storefront-operations
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @doswiftly/storefront-operations
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Install dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @doswiftly/storefront-operations @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typed-document-node
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Create `codegen.ts`
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { CodegenConfig } from "@graphql-codegen/cli";
|
|
25
|
+
|
|
26
|
+
const config: CodegenConfig = {
|
|
27
|
+
schema: {
|
|
28
|
+
[process.env.NEXT_PUBLIC_STOREFRONT_API_URL!]: {
|
|
29
|
+
headers: {
|
|
30
|
+
"X-Shop-Slug": process.env.NEXT_PUBLIC_SHOP_SLUG!,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
documents: [
|
|
35
|
+
"node_modules/@doswiftly/storefront-operations/**/*.graphql",
|
|
36
|
+
"src/**/*.{ts,tsx}", // Your custom operations (optional)
|
|
37
|
+
],
|
|
38
|
+
generates: {
|
|
39
|
+
"src/generated/graphql.ts": {
|
|
40
|
+
plugins: ["typescript", "typescript-operations", "typed-document-node"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default config;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Add script to `package.json`
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"scripts": {
|
|
53
|
+
"codegen": "graphql-codegen --config codegen.ts"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 4. Run codegen
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm run codegen
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 5. Use in your components
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { useQuery } from '@tanstack/react-query';
|
|
68
|
+
import { graphqlClient } from '@/lib/graphql-client';
|
|
69
|
+
import { ProductsDocument } from '@/generated/graphql';
|
|
70
|
+
|
|
71
|
+
export function ProductList() {
|
|
72
|
+
const { data, isLoading } = useQuery({
|
|
73
|
+
queryKey: ['products'],
|
|
74
|
+
queryFn: () => graphqlClient.request(ProductsDocument, { first: 12 }),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (isLoading) return <div>Loading...</div>;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className="grid grid-cols-3 gap-4">
|
|
81
|
+
{data?.products.edges.map(({ node }) => (
|
|
82
|
+
<ProductCard key={node.id} product={node} />
|
|
83
|
+
))}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Available Operations
|
|
90
|
+
|
|
91
|
+
### Queries
|
|
92
|
+
|
|
93
|
+
| Operation | Description |
|
|
94
|
+
| ------------------- | ---------------------------------------- |
|
|
95
|
+
| `Shop` | Shop configuration, currencies, settings |
|
|
96
|
+
| `Product` | Single product by ID or handle |
|
|
97
|
+
| `Products` | Product list with pagination and filters |
|
|
98
|
+
| `ProductSearch` | Full-text product search |
|
|
99
|
+
| `Collection` | Collection with its products |
|
|
100
|
+
| `Collections` | All collections |
|
|
101
|
+
| `Category` | Category with hierarchy |
|
|
102
|
+
| `Categories` | Category tree |
|
|
103
|
+
| `Cart` | Cart contents by ID |
|
|
104
|
+
| `Customer` | Logged-in customer data |
|
|
105
|
+
| `CustomerOrders` | Customer order history |
|
|
106
|
+
| `CustomerAddresses` | Customer saved addresses |
|
|
107
|
+
|
|
108
|
+
### Mutations
|
|
109
|
+
|
|
110
|
+
**Cart**
|
|
111
|
+
|
|
112
|
+
- `CartCreate` - Create a new cart
|
|
113
|
+
- `CartLinesAdd` - Add items to cart
|
|
114
|
+
- `CartLinesUpdate` - Update item quantities
|
|
115
|
+
- `CartLinesRemove` - Remove items from cart
|
|
116
|
+
- `CartDiscountCodesUpdate` - Apply/remove discount codes
|
|
117
|
+
- `CartBuyerIdentityUpdate` - Set customer info on cart
|
|
118
|
+
- `CartNoteUpdate` - Add note to cart
|
|
119
|
+
|
|
120
|
+
**Authentication**
|
|
121
|
+
|
|
122
|
+
- `CustomerCreate` - Register new customer
|
|
123
|
+
- `CustomerLogin` - Login and get token
|
|
124
|
+
- `CustomerLogout` - Logout
|
|
125
|
+
- `CustomerTokenRenew` - Refresh auth token
|
|
126
|
+
|
|
127
|
+
**Customer Profile**
|
|
128
|
+
|
|
129
|
+
- `CustomerUpdate` - Update profile info
|
|
130
|
+
- `CustomerAddressCreate` - Add new address
|
|
131
|
+
- `CustomerAddressUpdate` - Update address
|
|
132
|
+
- `CustomerAddressDelete` - Delete address
|
|
133
|
+
- `CustomerDefaultAddressUpdate` - Set default address
|
|
134
|
+
|
|
135
|
+
**Password**
|
|
136
|
+
|
|
137
|
+
- `CustomerPasswordRecover` - Request password reset email
|
|
138
|
+
- `CustomerPasswordReset` - Reset password with token
|
|
139
|
+
|
|
140
|
+
## Environment Variables
|
|
141
|
+
|
|
142
|
+
```env
|
|
143
|
+
NEXT_PUBLIC_STOREFRONT_API_URL=https://api.doswiftly.pl/storefront/graphql
|
|
144
|
+
NEXT_PUBLIC_SHOP_SLUG=your-shop-slug
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## TypeScript Support
|
|
148
|
+
|
|
149
|
+
All operations are fully typed. After running codegen, you get:
|
|
150
|
+
|
|
151
|
+
- Document nodes for each operation
|
|
152
|
+
- Input types for variables
|
|
153
|
+
- Response types for results
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import {
|
|
157
|
+
ProductDocument,
|
|
158
|
+
ProductQuery,
|
|
159
|
+
ProductQueryVariables,
|
|
160
|
+
} from "@/generated/graphql";
|
|
161
|
+
|
|
162
|
+
// Full type safety
|
|
163
|
+
const variables: ProductQueryVariables = {
|
|
164
|
+
handle: "awesome-product",
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Custom Operations
|
|
169
|
+
|
|
170
|
+
You can add your own GraphQL operations alongside the package operations:
|
|
171
|
+
|
|
172
|
+
```graphql
|
|
173
|
+
# src/graphql/custom-queries.graphql
|
|
174
|
+
query FeaturedProducts {
|
|
175
|
+
products(first: 4, filters: { tag: "featured" }) {
|
|
176
|
+
edges {
|
|
177
|
+
node {
|
|
178
|
+
...ProductCard
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Re-run `npm run codegen` to generate types for your custom operations.
|
|
186
|
+
|
|
187
|
+
## Links
|
|
188
|
+
|
|
189
|
+
- [DoSwiftly Website](https://doswiftly.pl)
|
|
190
|
+
- [DoSwiftly Documentation](https://doswiftly.pl/docs)
|
|
191
|
+
- [GraphQL API Reference](https://doswiftly.pl/docs/api/graphql)
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|