Given this table:
CREATE聽TABLE聽accounts聽(
聽聽聽聽id聽INT聽GENERATED聽BY聽DEFAULT聽AS聽IDENTITY,
聽聽聽聽name聽VARCHAR(100)聽NOT NULL,
聽聽聽聽balance聽DEC(15,2)聽NOT NULL,
聽聽聽聽PRIMARY聽KEY(id)
);
With somethings
INSERT聽INTO聽accounts(name, balance) VALUES ('Bob', 10000);
INSERT聽INTO聽accounts(name, balance) VALUES ('Alice', 10000);
I've created a stored procedure:
CREATE聽OR聽REPLACE聽PROCEDURE聽transfer(INT,聽INT,聽DEC)
LANGUAGE聽plpgsql
AS聽$$
BEGIN
聽聽聽聽-- subtracting the amount from the sender's account
聽聽聽聽UPDATE聽accounts
聽聽聽聽SET聽balance聽=聽balance聽-聽$3
聽聽聽聽WHERE聽id聽=聽$1;
聽聽聽聽聽-- adding the amount to the receiver's account
聽聽聽聽UPDATE聽accounts
聽聽聽聽SET聽balance聽=聽balance聽+聽$3
聽聽聽聽WHERE聽id聽=聽$2;
COMMIT;
END;
$$;
I want expose this procedure as a graphql mutation.
I know is possible made with functions, but I thinks if the SQL view is exposed by Graphql query why not expose procedures as mutation?
Maybe create a pattern to turn possible create and expose a stored procedure.
Yes please there's ton of use cases where simple CRUD is not enough
Closing this as a duplicate of https://github.com/hasura/graphql-engine/issues/1514.
Most helpful comment
Yes please there's ton of use cases where simple CRUD is not enough