You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -33,12 +34,14 @@ The Angular Query mode will generate an implementation file with one injectable
33
34
For example, <ahref="https://github.com/orval-labs/orval/blob/master/samples/angular-query/petstore.yaml"target="_blank">this Swagger specification</a> will generate the following:
The generated `inject*` functions support Angular signals out of the box. Parameters can be passed as **getter functions**, enabling reactive query updates when signals change:
135
+
136
+
```ts
137
+
@Component({...})
138
+
exportclassPetDetailComponent {
139
+
// Signal-based parameter
140
+
petId =signal('1');
141
+
142
+
// Query automatically re-executes when petId() changes
143
+
pet =injectShowPetById(() =>this.petId());
144
+
145
+
// Also works with options for dynamic enabled/disabled
146
+
conditionalPet =injectShowPetById(
147
+
() =>this.petId(),
148
+
() => ({
149
+
query: { enabled: this.isEnabled() },
150
+
}),
151
+
);
152
+
}
153
+
```
154
+
155
+
This pattern works for all parameters including query params and options.
156
+
157
+
## Mutations
158
+
159
+
For POST, PUT, PATCH, and DELETE operations, Orval generates mutation functions:
**Param-based invalidation**: With `{ query: 'showPetById', params: ['petId'] }`, when `deletePet({ petId: '123' })` succeeds, only the query for pet `123` is invalidated—not all `showPetById` queries.
262
+
263
+
**Usage**: To get automatic invalidation, use the generated `inject*` mutation functions:
// Query - will be automatically invalidated after mutations
280
+
pets =injectListPets();
281
+
282
+
// Mutation - automatic invalidation is built into the generated options
283
+
deletePet =injectDeletePet();
284
+
285
+
onDelete(petId:string) {
286
+
// After success, listPets and showPetById(petId) are automatically invalidated
287
+
this.deletePet.mutate({ petId });
288
+
}
289
+
}
290
+
```
291
+
108
292
## How to Use Other Queries
109
293
110
294
Given the following configuration, Orval will generate query and infinite query functions with a `nextId` query parameter. It is also possible to override the config for every query with the `options` field.
With `{ query: 'showPetById', params: ['petId'] }`, the mutation's variables are used to determine which specific query to invalidate. When `deletePet({ petId: '123' })` succeeds, only `showPetById('123')` is invalidated—not all `showPetById` queries.
1304
+
1305
+
See the [Angular Query guide](../../guides/angular-query#automatic-mutation-invalidation-angular-query-only) for more details.
0 commit comments