@zeroin.earth/appwrite-graphql 0.14.8 → 0.14.9

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/dist/index.mjs CHANGED
@@ -1,3 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
1
7
  // src/useAppwrite.ts
2
8
  import { useMemo } from "react";
3
9
  import { Account, Client, Databases, Functions, Graphql } from "appwrite";
@@ -2090,8 +2096,89 @@ function useFunction() {
2090
2096
  currentExecution: getExecution
2091
2097
  };
2092
2098
  }
2099
+ function useSuspenseFunction({
2100
+ functionId,
2101
+ body = {},
2102
+ async = false,
2103
+ path = "",
2104
+ method = "POST"
2105
+ }) {
2106
+ const { graphql: graphql2 } = useAppwrite();
2107
+ const [currentExecution, setCurrentExecution] = useState(null);
2108
+ const [currentFunction, setCurrentFunction] = useState(null);
2109
+ const executeFunction = useSuspenseQuery(
2110
+ {
2111
+ queryKey: ["appwrite", "functions", functionId],
2112
+ queryFn: async () => {
2113
+ setCurrentFunction(functionId);
2114
+ const { data } = await graphql2.mutation({
2115
+ query: createExecution,
2116
+ variables: {
2117
+ functionId,
2118
+ body: JSON.stringify(body),
2119
+ async,
2120
+ path,
2121
+ method
2122
+ // headers,
2123
+ }
2124
+ });
2125
+ let unsubscribe = null;
2126
+ const { _id, status, responseBody, errors } = data.functionsCreateExecution ?? {};
2127
+ if (status === "completed") {
2128
+ return JSON.parse(responseBody ?? "{}");
2129
+ }
2130
+ if (status === "failed" && errors) {
2131
+ throw new Error(errors);
2132
+ }
2133
+ setCurrentExecution(_id ?? null);
2134
+ const response = await new Promise((resolve, reject) => {
2135
+ unsubscribe = graphql2.client.subscribe(`executions.${_id}`, (event) => {
2136
+ switch (event.payload.status) {
2137
+ case "completed":
2138
+ setCurrentExecution(null);
2139
+ resolve(JSON.parse(event.payload.responseBody));
2140
+ break;
2141
+ case "failed":
2142
+ setCurrentExecution(null);
2143
+ reject(event.payload.errors);
2144
+ break;
2145
+ }
2146
+ return 1;
2147
+ });
2148
+ });
2149
+ unsubscribe?.();
2150
+ return response;
2151
+ }
2152
+ }
2153
+ );
2154
+ const getExecution = useQuery({
2155
+ queryKey: ["appwrite", "functions", currentFunction, currentExecution],
2156
+ queryFn: async () => {
2157
+ if (!currentExecution || !currentFunction) {
2158
+ return null;
2159
+ }
2160
+ const { data } = await graphql2.query({
2161
+ query: getFunctionExecution,
2162
+ variables: {
2163
+ functionId: currentFunction,
2164
+ executionId: currentExecution
2165
+ }
2166
+ });
2167
+ return data.functionsGetExecution ?? {};
2168
+ }
2169
+ });
2170
+ return {
2171
+ executeFunction,
2172
+ currentExecution: getExecution
2173
+ };
2174
+ }
2093
2175
 
2094
2176
  // src/account/fragments.ts
2177
+ var fragments_exports = {};
2178
+ __export(fragments_exports, {
2179
+ Account_UserFragment: () => Account_UserFragment,
2180
+ Identity_ProviderFragment: () => Identity_ProviderFragment
2181
+ });
2095
2182
  var Account_UserFragment = gql(
2096
2183
  /* GraphQL */
2097
2184
  `
@@ -2117,8 +2204,7 @@ var Identity_ProviderFragment = gql(
2117
2204
 
2118
2205
  // src/index.ts
2119
2206
  var fragments = {
2120
- Account_UserFragment,
2121
- Identity_ProviderFragment
2207
+ ...fragments_exports
2122
2208
  };
2123
2209
  export {
2124
2210
  fragments,
@@ -2161,6 +2247,7 @@ export {
2161
2247
  useSignUp,
2162
2248
  useSuspenseCollection,
2163
2249
  useSuspenseCreateJWT,
2250
+ useSuspenseFunction,
2164
2251
  useUpdateDocument,
2165
2252
  useUpdateEmail,
2166
2253
  useUpdateMagicURLSession,