@zeroin.earth/appwrite-graphql 0.14.1 → 0.14.3
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.d.mts +84 -40
- package/dist/index.d.ts +84 -40
- package/dist/index.js +102 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -320,6 +320,15 @@ function useCreateEmailToken() {
|
|
|
320
320
|
return { ...queryResult };
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
// src/useSuspenseQuery.ts
|
|
324
|
+
import {
|
|
325
|
+
useSuspenseQuery as useSuspenseReactQuery
|
|
326
|
+
} from "@tanstack/react-query";
|
|
327
|
+
function useSuspenseQuery(options) {
|
|
328
|
+
const queryClient2 = useQueryClient();
|
|
329
|
+
return useSuspenseReactQuery(options, queryClient2);
|
|
330
|
+
}
|
|
331
|
+
|
|
323
332
|
// src/account/useCreateJWT.ts
|
|
324
333
|
var accountCreateJWT = gql(
|
|
325
334
|
/* GraphQL */
|
|
@@ -331,9 +340,12 @@ var accountCreateJWT = gql(
|
|
|
331
340
|
}
|
|
332
341
|
`
|
|
333
342
|
);
|
|
334
|
-
function useCreateJWT() {
|
|
343
|
+
function useCreateJWT({ gcTime = 6e5 } = {}) {
|
|
335
344
|
const { graphql: graphql2 } = useAppwrite();
|
|
345
|
+
const queryClient2 = useQueryClient();
|
|
336
346
|
const queryResult = useMutation({
|
|
347
|
+
gcTime,
|
|
348
|
+
mutationKey: ["appwrite", "jwt"],
|
|
337
349
|
mutationFn: async () => {
|
|
338
350
|
const { data, errors } = await graphql2.mutation({
|
|
339
351
|
query: accountCreateJWT
|
|
@@ -342,6 +354,28 @@ function useCreateJWT() {
|
|
|
342
354
|
throw errors;
|
|
343
355
|
}
|
|
344
356
|
return data.accountCreateJWT;
|
|
357
|
+
},
|
|
358
|
+
onSuccess: (data) => {
|
|
359
|
+
graphql2.client.setJWT(data.jwt);
|
|
360
|
+
queryClient2.setQueryData(["appwrite", "jwt"], data.jwt, { updatedAt: Date.now() });
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return { ...queryResult };
|
|
364
|
+
}
|
|
365
|
+
function useSuspenseCreateJWT({ gcTime = 6e5 } = {}) {
|
|
366
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
367
|
+
const queryResult = useSuspenseQuery({
|
|
368
|
+
gcTime,
|
|
369
|
+
queryKey: ["appwrite", "jwt"],
|
|
370
|
+
queryFn: async () => {
|
|
371
|
+
const { data, errors } = await graphql2.mutation({
|
|
372
|
+
query: accountCreateJWT
|
|
373
|
+
});
|
|
374
|
+
if (errors) {
|
|
375
|
+
throw errors;
|
|
376
|
+
}
|
|
377
|
+
graphql2.client.setJWT(data.accountCreateJWT.jwt);
|
|
378
|
+
return data.accountCreateJWT;
|
|
345
379
|
}
|
|
346
380
|
});
|
|
347
381
|
return { ...queryResult };
|
|
@@ -934,8 +968,9 @@ function useLogout() {
|
|
|
934
968
|
return data?.accountDeleteSession;
|
|
935
969
|
},
|
|
936
970
|
onSuccess: async () => {
|
|
937
|
-
queryClient2.setQueryData(["appwrite"
|
|
938
|
-
queryClient2.removeQueries({ queryKey: ["appwrite"
|
|
971
|
+
queryClient2.setQueryData(["appwrite"], null);
|
|
972
|
+
queryClient2.removeQueries({ queryKey: ["appwrite"] });
|
|
973
|
+
queryClient2.clear();
|
|
939
974
|
}
|
|
940
975
|
});
|
|
941
976
|
return { ...queryResult, mutate: queryResult.mutate };
|
|
@@ -1654,6 +1689,67 @@ function useCollection({
|
|
|
1654
1689
|
total: collection.data?.total
|
|
1655
1690
|
};
|
|
1656
1691
|
}
|
|
1692
|
+
function useSuspenseCollection({
|
|
1693
|
+
databaseId,
|
|
1694
|
+
collectionId,
|
|
1695
|
+
queries
|
|
1696
|
+
}) {
|
|
1697
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
1698
|
+
const queryClient2 = useQueryClient();
|
|
1699
|
+
const collection = useSuspenseQuery({
|
|
1700
|
+
queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
|
|
1701
|
+
queryFn: async () => {
|
|
1702
|
+
const { data, errors } = await graphql2.query({
|
|
1703
|
+
query: listDocuments,
|
|
1704
|
+
variables: {
|
|
1705
|
+
databaseId,
|
|
1706
|
+
collectionId,
|
|
1707
|
+
queries
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
if (errors) {
|
|
1711
|
+
throw errors;
|
|
1712
|
+
}
|
|
1713
|
+
const documents2 = data.databasesListDocuments?.documents?.map((document) => ({
|
|
1714
|
+
...document,
|
|
1715
|
+
...document ? JSON.parse(document.data) : {}
|
|
1716
|
+
})) ?? [];
|
|
1717
|
+
return {
|
|
1718
|
+
total: data.databasesListDocuments?.total ?? 0,
|
|
1719
|
+
documents: documents2
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
useEffect2(() => {
|
|
1724
|
+
const unsubscribe = graphql2.client.subscribe(
|
|
1725
|
+
`databases.${databaseId}.collections.${collectionId}.documents`,
|
|
1726
|
+
(response) => {
|
|
1727
|
+
const [, operation] = response.events[0].match(/\.(\w+)$/);
|
|
1728
|
+
const document = response.payload;
|
|
1729
|
+
switch (operation) {
|
|
1730
|
+
case "create":
|
|
1731
|
+
case "update":
|
|
1732
|
+
case "delete":
|
|
1733
|
+
queryClient2.setQueryData(
|
|
1734
|
+
["appwrite", "databases", databaseId, collectionId, "documents", document.$id],
|
|
1735
|
+
document
|
|
1736
|
+
);
|
|
1737
|
+
queryClient2.invalidateQueries({
|
|
1738
|
+
queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
|
|
1739
|
+
exact: true
|
|
1740
|
+
});
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
);
|
|
1745
|
+
return unsubscribe;
|
|
1746
|
+
}, [databaseId, collectionId, graphql2.client, queryClient2, queries]);
|
|
1747
|
+
return {
|
|
1748
|
+
...collection,
|
|
1749
|
+
documents: collection.data?.documents,
|
|
1750
|
+
total: collection.data?.total
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1657
1753
|
|
|
1658
1754
|
// src/databases/useCreateDocument.ts
|
|
1659
1755
|
var createDocument = gql(
|
|
@@ -1925,7 +2021,7 @@ function useFunction() {
|
|
|
1925
2021
|
const [currentExecution, setCurrentExecution] = useState(null);
|
|
1926
2022
|
const [currentFunction, setCurrentFunction] = useState(null);
|
|
1927
2023
|
const executeFunction = useMutation({
|
|
1928
|
-
mutationFn: async ({ functionId, body, async, path, method, headers }) => {
|
|
2024
|
+
mutationFn: async ({ functionId, body = {}, async, path, method, headers }) => {
|
|
1929
2025
|
setCurrentFunction(functionId);
|
|
1930
2026
|
const { data } = await graphql2.mutation({
|
|
1931
2027
|
query: createExecution,
|
|
@@ -2055,6 +2151,8 @@ export {
|
|
|
2055
2151
|
useQueryClient,
|
|
2056
2152
|
useResetPassword,
|
|
2057
2153
|
useSignUp,
|
|
2154
|
+
useSuspenseCollection,
|
|
2155
|
+
useSuspenseCreateJWT,
|
|
2058
2156
|
useUpdateDocument,
|
|
2059
2157
|
useUpdateEmail,
|
|
2060
2158
|
useUpdateMagicURLSession,
|