Skip to content

Commit 38a117b

Browse files
committed
Add support for bulk actions which accept params beyond just an ID
1 parent 5e45bcf commit 38a117b

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

packages/api-client-core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gadgetinc/api-client-core",
3-
"version": "0.15.6",
3+
"version": "0.15.7",
44
"files": [
55
"Readme.md",
66
"dist/**/*"
@@ -39,7 +39,7 @@
3939
"ws": "^8.13.0"
4040
},
4141
"devDependencies": {
42-
"tiny-graphql-query-compiler": "workspace:*",
42+
"tiny-graphql-query-compiler": "*",
4343
"@types/lodash.clonedeep": "^4.5.6",
4444
"@types/lodash.isequal": "^4.5.5",
4545
"@types/node": "^16.11.7",

packages/api-client-core/src/GadgetFunctions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ interface BulkActionWithIdsAndNoVariables<OptionsT> {
9090
<Options extends OptionsT>(ids: string[], options?: LimitToKnownKeys<Options, OptionsT>): AsyncRecord<any>;
9191
}
9292

93+
interface BulkActionWithInputs<OptionsT, VariablesT> {
94+
<Options extends OptionsT>(inputs: VariablesT, options?: LimitToKnownKeys<Options, OptionsT>): AsyncRecord<any>;
95+
}
96+
9397
interface ActionFunctionMetadata<OptionsT, VariablesT, SelectionT, SchemaT, DefaultsT, IsBulk> {
9498
type: "action";
9599
operationName: string;
@@ -134,7 +138,7 @@ export type BulkActionFunction<OptionsT, VariablesT, SelectionT, SchemaT, Defaul
134138
DefaultsT,
135139
true
136140
> &
137-
BulkActionWithIdsAndNoVariables<OptionsT>;
141+
(BulkActionWithIdsAndNoVariables<OptionsT> | BulkActionWithInputs<OptionsT, VariablesT>);
138142

139143
export interface GetFunction<OptionsT, SelectionT, SchemaT, DefaultsT> {
140144
<Options extends OptionsT>(options?: LimitToKnownKeys<Options, OptionsT>): AsyncRecord<GadgetRecord<any>>;

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gadgetinc/react",
3-
"version": "0.14.3",
3+
"version": "0.14.4",
44
"files": [
55
"README.md",
66
"dist/**/*"

packages/react/src/useBulkAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ export const useBulkAction = <
7777
return [
7878
transformedResult,
7979
useCallback(
80-
async (variables: F["variablesType"], context?: Partial<OperationContext>) => {
80+
async (inputs: F["variablesType"], context?: Partial<OperationContext>) => {
81+
// accept the old style of {ids: ["1", "2", "3"]} as well as the new style of [{id: 1, foo: "bar"}, {id: 2, foo: "baz"}]
82+
const variables = inputs && "ids" in inputs ? inputs : { inputs };
83+
8184
// Adding the model's additional typename ensures document cache will properly refresh, regardless of whether __typename was
8285
// selected (and sometimes we can't even select it, like delete actions!)
8386
const result = await runMutation(variables, {

0 commit comments

Comments
 (0)