@zeroin.earth/appwrite-graphql 0.13.0
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/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/index.d.mts +349 -0
- package/dist/index.d.ts +349 -0
- package/dist/index.js +808 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +770 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
// src/useAppwrite.ts
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { Account, Client, Graphql } from "appwrite";
|
|
4
|
+
import { print } from "graphql";
|
|
5
|
+
import { atom, useAtom } from "jotai";
|
|
6
|
+
var client = new Client();
|
|
7
|
+
var endpoint = process.env.APPWRITE_ENDPOINT ?? process.env.NEXT_PUBLIC_APPWRITE_URL ?? "http://localhost/v1";
|
|
8
|
+
var projectId = process.env.APPWRITE_PROJECT_ID ?? process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? "[PROJECT_ID]";
|
|
9
|
+
client.setEndpoint(endpoint).setProject(projectId);
|
|
10
|
+
var account = new Account(client);
|
|
11
|
+
var graphql = new Graphql(client);
|
|
12
|
+
var AccountAtom = atom(account);
|
|
13
|
+
var GraphqlAtom = atom(graphql);
|
|
14
|
+
function useAppwrite() {
|
|
15
|
+
const [account2] = useAtom(AccountAtom);
|
|
16
|
+
const [graphqlAppwrite] = useAtom(GraphqlAtom);
|
|
17
|
+
const graphql2 = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
client: graphqlAppwrite.client,
|
|
20
|
+
query: async ({
|
|
21
|
+
query,
|
|
22
|
+
variables
|
|
23
|
+
}) => {
|
|
24
|
+
const { data, errors } = await graphqlAppwrite.query({
|
|
25
|
+
query: print(query),
|
|
26
|
+
variables
|
|
27
|
+
});
|
|
28
|
+
return { data, errors };
|
|
29
|
+
},
|
|
30
|
+
mutation: async ({
|
|
31
|
+
query,
|
|
32
|
+
variables
|
|
33
|
+
}) => {
|
|
34
|
+
const { data, errors } = await graphqlAppwrite.mutation({
|
|
35
|
+
query: print(query),
|
|
36
|
+
variables
|
|
37
|
+
});
|
|
38
|
+
return { data, errors };
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
[graphqlAppwrite]
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
account: account2,
|
|
45
|
+
graphql: graphql2
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/useMutation.ts
|
|
50
|
+
import {
|
|
51
|
+
useMutation as useReactMutation
|
|
52
|
+
} from "@tanstack/react-query";
|
|
53
|
+
|
|
54
|
+
// src/useQueryClient.ts
|
|
55
|
+
import { useAtom as useAtom2 } from "jotai";
|
|
56
|
+
|
|
57
|
+
// src/states/query.ts
|
|
58
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
59
|
+
import { atom as atom2 } from "jotai";
|
|
60
|
+
var queryClient = new QueryClient();
|
|
61
|
+
var QueryAtom = atom2(queryClient);
|
|
62
|
+
|
|
63
|
+
// src/useQueryClient.ts
|
|
64
|
+
function useQueryClient() {
|
|
65
|
+
const [queryClient2] = useAtom2(QueryAtom);
|
|
66
|
+
return queryClient2;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/useMutation.ts
|
|
70
|
+
function useMutation(options) {
|
|
71
|
+
const queryClient2 = useQueryClient();
|
|
72
|
+
return useReactMutation(options, queryClient2);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/useQuery.ts
|
|
76
|
+
import {
|
|
77
|
+
useQuery as useReactQuery
|
|
78
|
+
} from "@tanstack/react-query";
|
|
79
|
+
function useQuery(options) {
|
|
80
|
+
const queryClient2 = useQueryClient();
|
|
81
|
+
return useReactQuery(options, queryClient2);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/account/useAccount.ts
|
|
85
|
+
import { useEffect } from "react";
|
|
86
|
+
import { castDraft, produce } from "immer";
|
|
87
|
+
|
|
88
|
+
// src/__generated__/graphql.ts
|
|
89
|
+
var Account_UserFragmentFragmentDoc = { "kind": "Document", "definitions": [{ "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "Account_UserFragment" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "User" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }, { "kind": "Field", "name": { "kind": "Name", "value": "prefs" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
|
|
90
|
+
var AccountGetDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "AccountGet" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountGet" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "FragmentSpread", "name": { "kind": "Name", "value": "Account_UserFragment" } }] } }] } }, { "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "Account_UserFragment" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "User" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }, { "kind": "Field", "name": { "kind": "Name", "value": "prefs" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
|
|
91
|
+
var CreateEmailSessionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateEmailSession" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateEmailSession" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "expire" } }, { "kind": "Field", "name": { "kind": "Name", "value": "current" } }] } }] } }] };
|
|
92
|
+
var DeleteSessionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeleteSession" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "sessionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountDeleteSession" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "sessionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "sessionId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" } }] } }] } }] };
|
|
93
|
+
var CreateRecoveryDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateRecovery" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateRecovery" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "url" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
|
|
94
|
+
var UpdateRecoveryDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateRecovery" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "passwordAgain" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountUpdateRecovery" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "secret" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "passwordAgain" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "passwordAgain" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
|
|
95
|
+
var CreateAccountDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateAccount" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "name" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreate" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "name" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "name" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "email" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "email" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "password" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "password" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "email" } }] } }] } }] };
|
|
96
|
+
var VerifyEmailDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "VerifyEmail" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountCreateVerification" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "url" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "url" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
|
|
97
|
+
var UpdateVerificationDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateVerification" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "accountUpdateVerification" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "userId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "userId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "secret" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "secret" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "expire" } }] } }] } }] };
|
|
98
|
+
var ListDocumentsDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "ListDocuments" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "queries" } }, "type": { "kind": "ListType", "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesListDocuments" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "queries" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "queries" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "total" } }, { "kind": "Field", "name": { "kind": "Name", "value": "documents" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] } }] };
|
|
99
|
+
var CreateDocumentDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateDocument" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "JSON" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "permissions" } }, "type": { "kind": "ListType", "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesCreateDocument" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "documentId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "data" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "permissions" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "permissions" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }] } }] } }] };
|
|
100
|
+
var GetDocumentDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetDocument" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "databasesGetDocument" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "databaseId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "databaseId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "collectionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "collectionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "documentId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "documentId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "data" } }] } }] } }] };
|
|
101
|
+
var CreateExecutionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateExecution" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "body" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "async" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "Boolean" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "path" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "method" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "headers" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "JSON" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "functionsCreateExecution" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "functionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "body" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "body" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "async" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "async" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "path" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "path" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "method" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "method" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "headers" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "headers" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "_id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "status" } }, { "kind": "Field", "name": { "kind": "Name", "value": "responseStatusCode" } }, { "kind": "Field", "name": { "kind": "Name", "value": "responseBody" } }, { "kind": "Field", "name": { "kind": "Name", "value": "errors" } }, { "kind": "Field", "name": { "kind": "Name", "value": "duration" } }] } }] } }] };
|
|
102
|
+
var GetFunctionExecutionDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetFunctionExecution" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "executionId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "String" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "functionsGetExecution" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "functionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "functionId" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "executionId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "executionId" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" } }, { "kind": "Field", "name": { "kind": "Name", "value": "errors" } }, { "kind": "Field", "name": { "kind": "Name", "value": "duration" } }] } }] } }] };
|
|
103
|
+
|
|
104
|
+
// src/__generated__/gql.ts
|
|
105
|
+
var documents = {
|
|
106
|
+
"\n fragment Account_UserFragment on User {\n name\n email\n prefs {\n data\n }\n }\n": Account_UserFragmentFragmentDoc,
|
|
107
|
+
"\n query AccountGet {\n accountGet {\n ...Account_UserFragment\n }\n }\n": AccountGetDocument,
|
|
108
|
+
"\n mutation CreateEmailSession($email: String!, $password: String!) {\n accountCreateEmailSession(email: $email, password: $password) {\n userId\n expire\n current\n }\n }\n": CreateEmailSessionDocument,
|
|
109
|
+
"\n mutation DeleteSession($sessionId: String!) {\n accountDeleteSession(sessionId: $sessionId) {\n status\n }\n }\n": DeleteSessionDocument,
|
|
110
|
+
"\n mutation CreateRecovery($email: String!, $url: String!) {\n accountCreateRecovery(email: $email, url: $url) {\n expire\n }\n }\n": CreateRecoveryDocument,
|
|
111
|
+
"\n mutation UpdateRecovery(\n $userId: String!\n $secret: String!\n $password: String!\n $passwordAgain: String!\n ) {\n accountUpdateRecovery(\n userId: $userId\n secret: $secret\n password: $password\n passwordAgain: $passwordAgain\n ) {\n expire\n }\n }\n": UpdateRecoveryDocument,
|
|
112
|
+
"\n mutation CreateAccount($userId: String!, $name: String, $email: String!, $password: String!) {\n accountCreate(userId: $userId, name: $name, email: $email, password: $password) {\n name\n email\n }\n }\n": CreateAccountDocument,
|
|
113
|
+
"\n mutation VerifyEmail($url: String!) {\n accountCreateVerification(url: $url) {\n expire\n }\n }\n": VerifyEmailDocument,
|
|
114
|
+
"\n mutation UpdateVerification($userId: String!, $secret: String!) {\n accountUpdateVerification(userId: $userId, secret: $secret) {\n expire\n }\n }\n": UpdateVerificationDocument,
|
|
115
|
+
"\n query ListDocuments($databaseId: String!, $collectionId: String!, $queries: [String!]) {\n databasesListDocuments(\n databaseId: $databaseId\n collectionId: $collectionId\n queries: $queries\n ) {\n total\n documents {\n _id\n data\n }\n }\n }\n": ListDocumentsDocument,
|
|
116
|
+
"\n mutation CreateDocument(\n $databaseId: String!\n $collectionId: String!\n $documentId: String!\n $data: JSON!\n $permissions: [String!]\n ) {\n databasesCreateDocument(\n databaseId: $databaseId\n collectionId: $collectionId\n documentId: $documentId\n data: $data\n permissions: $permissions\n ) {\n _id\n }\n }\n": CreateDocumentDocument,
|
|
117
|
+
"\n query GetDocument($databaseId: String!, $collectionId: String!, $documentId: String!) {\n databasesGetDocument(\n databaseId: $databaseId\n collectionId: $collectionId\n documentId: $documentId\n ) {\n _id\n data\n }\n }\n": GetDocumentDocument,
|
|
118
|
+
"\n mutation CreateExecution(\n $functionId: String!\n $body: String\n $async: Boolean\n $path: String\n $method: String\n $headers: JSON\n ) {\n functionsCreateExecution(\n functionId: $functionId\n body: $body\n async: $async\n path: $path\n method: $method\n headers: $headers\n ) {\n _id\n status\n responseStatusCode\n responseBody\n errors\n duration\n }\n }\n": CreateExecutionDocument,
|
|
119
|
+
"\n query GetFunctionExecution($functionId: String!, $executionId: String!) {\n functionsGetExecution(functionId: $functionId, executionId: $executionId) {\n status\n errors\n duration\n }\n }\n": GetFunctionExecutionDocument
|
|
120
|
+
};
|
|
121
|
+
function gql(source) {
|
|
122
|
+
return documents[source] ?? {};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/account/useAccount.ts
|
|
126
|
+
var getAccount = gql(
|
|
127
|
+
/* GraphQL */
|
|
128
|
+
`
|
|
129
|
+
query AccountGet {
|
|
130
|
+
accountGet {
|
|
131
|
+
...Account_UserFragment
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`
|
|
135
|
+
);
|
|
136
|
+
function useAccount({
|
|
137
|
+
options
|
|
138
|
+
}) {
|
|
139
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
140
|
+
const queryClient2 = useQueryClient();
|
|
141
|
+
const queryResult = useQuery({
|
|
142
|
+
queryKey: ["appwrite", "account"],
|
|
143
|
+
queryFn: async () => {
|
|
144
|
+
const { data, errors } = await graphql2.query({
|
|
145
|
+
query: getAccount
|
|
146
|
+
});
|
|
147
|
+
if (errors) {
|
|
148
|
+
throw errors;
|
|
149
|
+
}
|
|
150
|
+
return data.accountGet;
|
|
151
|
+
},
|
|
152
|
+
retry: false,
|
|
153
|
+
...options
|
|
154
|
+
});
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
const unsubscribe = graphql2.client.subscribe(
|
|
157
|
+
"account",
|
|
158
|
+
(response) => {
|
|
159
|
+
const isUpdatingPreferences = response.events.some((event) => event.endsWith("prefs"));
|
|
160
|
+
if (isUpdatingPreferences) {
|
|
161
|
+
queryClient2.setQueryData(
|
|
162
|
+
["appwrite", "account"],
|
|
163
|
+
(account2) => produce(account2, (draft) => {
|
|
164
|
+
if (draft) {
|
|
165
|
+
draft.prefs = castDraft(response.payload.prefs);
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
queryClient2.setQueryData(
|
|
172
|
+
["appwrite", "account"],
|
|
173
|
+
response.payload
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
return unsubscribe;
|
|
178
|
+
}, [graphql2.client, queryClient2]);
|
|
179
|
+
return queryResult;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/account/useLogin.ts
|
|
183
|
+
var createEmailSession = gql(
|
|
184
|
+
/* GraphQL */
|
|
185
|
+
`
|
|
186
|
+
mutation CreateEmailSession($email: String!, $password: String!) {
|
|
187
|
+
accountCreateEmailSession(email: $email, password: $password) {
|
|
188
|
+
userId
|
|
189
|
+
expire
|
|
190
|
+
current
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
`
|
|
194
|
+
);
|
|
195
|
+
function useLogin() {
|
|
196
|
+
const { account: account2, graphql: graphql2 } = useAppwrite();
|
|
197
|
+
const login = useMutation({
|
|
198
|
+
mutationFn: async ({ email, password }) => {
|
|
199
|
+
const { data, errors } = await graphql2.mutation({
|
|
200
|
+
query: createEmailSession,
|
|
201
|
+
variables: {
|
|
202
|
+
email,
|
|
203
|
+
password
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
if (errors) {
|
|
207
|
+
throw errors;
|
|
208
|
+
}
|
|
209
|
+
return data.accountCreateEmailSession ?? {};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const oAuthLogin = useMutation({
|
|
213
|
+
mutationFn: async ({ provider, success, failure }) => {
|
|
214
|
+
return account2.createOAuth2Session(provider, success, failure);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
login,
|
|
219
|
+
oAuthLogin
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/__generated__/fragment-masking.ts
|
|
224
|
+
function getFragmentData(_documentNode, fragmentType) {
|
|
225
|
+
return fragmentType;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/account/useLogout.ts
|
|
229
|
+
var deleteSession = gql(
|
|
230
|
+
/* GraphQL */
|
|
231
|
+
`
|
|
232
|
+
mutation DeleteSession($sessionId: String!) {
|
|
233
|
+
accountDeleteSession(sessionId: $sessionId) {
|
|
234
|
+
status
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
`
|
|
238
|
+
);
|
|
239
|
+
function useLogout() {
|
|
240
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
241
|
+
const queryClient2 = useQueryClient();
|
|
242
|
+
const logout = useMutation({
|
|
243
|
+
mutationFn: () => {
|
|
244
|
+
return graphql2.mutation({
|
|
245
|
+
query: deleteSession,
|
|
246
|
+
variables: {
|
|
247
|
+
sessionId: "current"
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
onSuccess: async () => {
|
|
252
|
+
queryClient2.setQueryData(["appwrite", "account"], null);
|
|
253
|
+
queryClient2.removeQueries({ queryKey: ["appwrite", "account"] });
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return logout;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/account/usePasswordRecovery.ts
|
|
260
|
+
var createRecovery = gql(
|
|
261
|
+
/* GraphQL */
|
|
262
|
+
`
|
|
263
|
+
mutation CreateRecovery($email: String!, $url: String!) {
|
|
264
|
+
accountCreateRecovery(email: $email, url: $url) {
|
|
265
|
+
expire
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`
|
|
269
|
+
);
|
|
270
|
+
function usePasswordRecovery() {
|
|
271
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
272
|
+
const passwordRecovery = useMutation({
|
|
273
|
+
mutationFn: async ({ email, resetUrl }) => {
|
|
274
|
+
const { data, errors } = await graphql2.mutation({
|
|
275
|
+
query: createRecovery,
|
|
276
|
+
variables: {
|
|
277
|
+
email,
|
|
278
|
+
url: resetUrl
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
if (errors) {
|
|
282
|
+
throw errors;
|
|
283
|
+
}
|
|
284
|
+
return data.accountCreateRecovery ?? {};
|
|
285
|
+
},
|
|
286
|
+
onSuccess: async (_, variables) => {
|
|
287
|
+
localStorage.setItem("email", variables.email);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return passwordRecovery;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/account/useResetPassword.ts
|
|
294
|
+
var updateRecovery = gql(
|
|
295
|
+
/* GraphQL */
|
|
296
|
+
`
|
|
297
|
+
mutation UpdateRecovery(
|
|
298
|
+
$userId: String!
|
|
299
|
+
$secret: String!
|
|
300
|
+
$password: String!
|
|
301
|
+
$passwordAgain: String!
|
|
302
|
+
) {
|
|
303
|
+
accountUpdateRecovery(
|
|
304
|
+
userId: $userId
|
|
305
|
+
secret: $secret
|
|
306
|
+
password: $password
|
|
307
|
+
passwordAgain: $passwordAgain
|
|
308
|
+
) {
|
|
309
|
+
expire
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
`
|
|
313
|
+
);
|
|
314
|
+
function useResetPassword() {
|
|
315
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
316
|
+
const passwordReset = useMutation({
|
|
317
|
+
mutationFn: async ({ userId, secret, password, confirmPassword }) => {
|
|
318
|
+
const { data, errors } = await graphql2.mutation({
|
|
319
|
+
query: updateRecovery,
|
|
320
|
+
variables: {
|
|
321
|
+
userId,
|
|
322
|
+
secret,
|
|
323
|
+
password,
|
|
324
|
+
passwordAgain: confirmPassword
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
if (errors) {
|
|
328
|
+
throw errors;
|
|
329
|
+
}
|
|
330
|
+
return data.accountUpdateRecovery ?? {};
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
return passwordReset;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/account/useSignUp.ts
|
|
337
|
+
import { ID } from "appwrite";
|
|
338
|
+
var createAccount = gql(
|
|
339
|
+
/* GraphQL */
|
|
340
|
+
`
|
|
341
|
+
mutation CreateAccount($userId: String!, $name: String, $email: String!, $password: String!) {
|
|
342
|
+
accountCreate(userId: $userId, name: $name, email: $email, password: $password) {
|
|
343
|
+
name
|
|
344
|
+
email
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
`
|
|
348
|
+
);
|
|
349
|
+
var verify = gql(
|
|
350
|
+
/* GraphQL */
|
|
351
|
+
`
|
|
352
|
+
mutation VerifyEmail($url: String!) {
|
|
353
|
+
accountCreateVerification(url: $url) {
|
|
354
|
+
expire
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
`
|
|
358
|
+
);
|
|
359
|
+
function useSignUp() {
|
|
360
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
361
|
+
const signUp = useMutation({
|
|
362
|
+
mutationFn: async ({ userId, email, password, name }) => {
|
|
363
|
+
const { data, errors } = await graphql2.mutation({
|
|
364
|
+
query: createAccount,
|
|
365
|
+
variables: {
|
|
366
|
+
userId: userId ?? ID.unique(),
|
|
367
|
+
name,
|
|
368
|
+
email,
|
|
369
|
+
password
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
if (errors) {
|
|
373
|
+
throw errors;
|
|
374
|
+
}
|
|
375
|
+
return data.accountCreate ?? {};
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const verifyEmail = useMutation({
|
|
379
|
+
mutationFn: async ({ verifyUrl }) => {
|
|
380
|
+
const { data, errors } = await graphql2.mutation({
|
|
381
|
+
query: verify,
|
|
382
|
+
variables: {
|
|
383
|
+
url: verifyUrl
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
if (errors) {
|
|
387
|
+
throw errors;
|
|
388
|
+
}
|
|
389
|
+
return data.accountCreateVerification ?? {};
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
return { signUp, verifyEmail };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/account/useVerification.ts
|
|
396
|
+
var updateVerification = gql(
|
|
397
|
+
/* GraphQL */
|
|
398
|
+
`
|
|
399
|
+
mutation UpdateVerification($userId: String!, $secret: String!) {
|
|
400
|
+
accountUpdateVerification(userId: $userId, secret: $secret) {
|
|
401
|
+
expire
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
`
|
|
405
|
+
);
|
|
406
|
+
function useVerification() {
|
|
407
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
408
|
+
const queryClient2 = useQueryClient();
|
|
409
|
+
const verify2 = useMutation({
|
|
410
|
+
mutationFn: async ({ userId, secret }) => {
|
|
411
|
+
if (!userId || !secret) {
|
|
412
|
+
throw new Error("Missing userId or secret");
|
|
413
|
+
}
|
|
414
|
+
const { data, errors } = await graphql2.mutation({
|
|
415
|
+
query: updateVerification,
|
|
416
|
+
variables: {
|
|
417
|
+
userId,
|
|
418
|
+
secret
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
if (errors) {
|
|
422
|
+
throw errors;
|
|
423
|
+
}
|
|
424
|
+
return data.accountUpdateVerification ?? {};
|
|
425
|
+
},
|
|
426
|
+
onSuccess: async () => {
|
|
427
|
+
queryClient2.setQueryData(["appwrite", "account"], null);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
return verify2;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/databases/useCollection.ts
|
|
434
|
+
import { useEffect as useEffect2 } from "react";
|
|
435
|
+
var listDocuments = gql(
|
|
436
|
+
/* GraphQL */
|
|
437
|
+
`
|
|
438
|
+
query ListDocuments($databaseId: String!, $collectionId: String!, $queries: [String!]) {
|
|
439
|
+
databasesListDocuments(
|
|
440
|
+
databaseId: $databaseId
|
|
441
|
+
collectionId: $collectionId
|
|
442
|
+
queries: $queries
|
|
443
|
+
) {
|
|
444
|
+
total
|
|
445
|
+
documents {
|
|
446
|
+
_id
|
|
447
|
+
data
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
`
|
|
452
|
+
);
|
|
453
|
+
function useCollection({
|
|
454
|
+
databaseId,
|
|
455
|
+
collectionId,
|
|
456
|
+
queries,
|
|
457
|
+
options
|
|
458
|
+
}) {
|
|
459
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
460
|
+
const queryClient2 = useQueryClient();
|
|
461
|
+
const collection = useQuery({
|
|
462
|
+
queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
|
|
463
|
+
queryFn: async () => {
|
|
464
|
+
const { data, errors } = await graphql2.query({
|
|
465
|
+
query: listDocuments,
|
|
466
|
+
variables: {
|
|
467
|
+
databaseId,
|
|
468
|
+
collectionId,
|
|
469
|
+
queries
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
if (errors) {
|
|
473
|
+
throw errors;
|
|
474
|
+
}
|
|
475
|
+
const documents2 = data.databasesListDocuments?.documents?.map((document) => ({
|
|
476
|
+
...document,
|
|
477
|
+
...document ? JSON.parse(document.data) : {}
|
|
478
|
+
})) ?? [];
|
|
479
|
+
return {
|
|
480
|
+
total: data.databasesListDocuments?.total ?? 0,
|
|
481
|
+
documents: documents2
|
|
482
|
+
};
|
|
483
|
+
},
|
|
484
|
+
...options
|
|
485
|
+
});
|
|
486
|
+
useEffect2(() => {
|
|
487
|
+
const unsubscribe = graphql2.client.subscribe(
|
|
488
|
+
`databases.${databaseId}.collections.${collectionId}.documents`,
|
|
489
|
+
(response) => {
|
|
490
|
+
const [, operation] = response.events[0].match(/\.(\w+)$/);
|
|
491
|
+
const document = response.payload;
|
|
492
|
+
switch (operation) {
|
|
493
|
+
case "create":
|
|
494
|
+
case "update":
|
|
495
|
+
case "delete":
|
|
496
|
+
queryClient2.setQueryData(
|
|
497
|
+
["appwrite", "databases", databaseId, collectionId, "documents", document.$id],
|
|
498
|
+
document
|
|
499
|
+
);
|
|
500
|
+
queryClient2.invalidateQueries({
|
|
501
|
+
queryKey: ["appwrite", "databases", databaseId, collectionId, { queries }],
|
|
502
|
+
exact: true
|
|
503
|
+
});
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
return unsubscribe;
|
|
509
|
+
}, [databaseId, collectionId, graphql2.client, queryClient2, queries]);
|
|
510
|
+
return {
|
|
511
|
+
...collection,
|
|
512
|
+
documents: collection.data?.documents,
|
|
513
|
+
total: collection.data?.total
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/databases/useCreateDocument.ts
|
|
518
|
+
var createDocument = gql(
|
|
519
|
+
/* GraphQL */
|
|
520
|
+
`
|
|
521
|
+
mutation CreateDocument(
|
|
522
|
+
$databaseId: String!
|
|
523
|
+
$collectionId: String!
|
|
524
|
+
$documentId: String!
|
|
525
|
+
$data: JSON!
|
|
526
|
+
$permissions: [String!]
|
|
527
|
+
) {
|
|
528
|
+
databasesCreateDocument(
|
|
529
|
+
databaseId: $databaseId
|
|
530
|
+
collectionId: $collectionId
|
|
531
|
+
documentId: $documentId
|
|
532
|
+
data: $data
|
|
533
|
+
permissions: $permissions
|
|
534
|
+
) {
|
|
535
|
+
_id
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
`
|
|
539
|
+
);
|
|
540
|
+
function useCreateDocument(databaseId, collectionId, documentId, data, permissions, options) {
|
|
541
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
542
|
+
const mutationResult = useMutation({
|
|
543
|
+
mutationKey: ["appwrite", "databases", databaseId, collectionId, "documents", documentId],
|
|
544
|
+
mutationFn: async () => {
|
|
545
|
+
const { data: mutationData, errors } = await graphql2.mutation({
|
|
546
|
+
query: createDocument,
|
|
547
|
+
variables: {
|
|
548
|
+
databaseId,
|
|
549
|
+
collectionId,
|
|
550
|
+
documentId,
|
|
551
|
+
data,
|
|
552
|
+
permissions
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
if (errors) {
|
|
556
|
+
throw errors;
|
|
557
|
+
}
|
|
558
|
+
return mutationData.databasesCreateDocument?._id;
|
|
559
|
+
},
|
|
560
|
+
...options
|
|
561
|
+
});
|
|
562
|
+
return mutationResult;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// src/databases/useDocument.ts
|
|
566
|
+
import { useEffect as useEffect3 } from "react";
|
|
567
|
+
var getDocument = gql(
|
|
568
|
+
/* GraphQL */
|
|
569
|
+
`
|
|
570
|
+
query GetDocument($databaseId: String!, $collectionId: String!, $documentId: String!) {
|
|
571
|
+
databasesGetDocument(
|
|
572
|
+
databaseId: $databaseId
|
|
573
|
+
collectionId: $collectionId
|
|
574
|
+
documentId: $documentId
|
|
575
|
+
) {
|
|
576
|
+
_id
|
|
577
|
+
data
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
`
|
|
581
|
+
);
|
|
582
|
+
function useDocument(databaseId, collectionId, documentId, options) {
|
|
583
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
584
|
+
const queryClient2 = useQueryClient();
|
|
585
|
+
const queryResult = useQuery({
|
|
586
|
+
queryKey: ["appwrite", "databases", databaseId, collectionId, "documents", documentId],
|
|
587
|
+
queryFn: async () => {
|
|
588
|
+
const { data, errors } = await graphql2.query({
|
|
589
|
+
query: getDocument,
|
|
590
|
+
variables: {
|
|
591
|
+
databaseId,
|
|
592
|
+
collectionId,
|
|
593
|
+
documentId
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
if (errors) {
|
|
597
|
+
throw errors;
|
|
598
|
+
}
|
|
599
|
+
const document = {
|
|
600
|
+
...data.databasesGetDocument,
|
|
601
|
+
...data.databasesGetDocument ? JSON.parse(data.databasesGetDocument.data) : {}
|
|
602
|
+
};
|
|
603
|
+
return document;
|
|
604
|
+
},
|
|
605
|
+
...options
|
|
606
|
+
});
|
|
607
|
+
useEffect3(() => {
|
|
608
|
+
const unsubscribe = graphql2.client.subscribe(
|
|
609
|
+
`databases.${databaseId}.collections.${collectionId}.documents.${documentId}`,
|
|
610
|
+
(response) => {
|
|
611
|
+
queryClient2.setQueryData(
|
|
612
|
+
["appwrite", "databases", databaseId, collectionId, "documents", documentId],
|
|
613
|
+
response.payload
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
);
|
|
617
|
+
return unsubscribe;
|
|
618
|
+
}, [databaseId, collectionId, documentId, graphql2.client, queryClient2]);
|
|
619
|
+
return queryResult;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/functions/useFunction.ts
|
|
623
|
+
import { useState } from "react";
|
|
624
|
+
var createExecution = gql(
|
|
625
|
+
/* GraphQL */
|
|
626
|
+
`
|
|
627
|
+
mutation CreateExecution(
|
|
628
|
+
$functionId: String!
|
|
629
|
+
$body: String
|
|
630
|
+
$async: Boolean
|
|
631
|
+
$path: String
|
|
632
|
+
$method: String
|
|
633
|
+
$headers: JSON
|
|
634
|
+
) {
|
|
635
|
+
functionsCreateExecution(
|
|
636
|
+
functionId: $functionId
|
|
637
|
+
body: $body
|
|
638
|
+
async: $async
|
|
639
|
+
path: $path
|
|
640
|
+
method: $method
|
|
641
|
+
headers: $headers
|
|
642
|
+
) {
|
|
643
|
+
_id
|
|
644
|
+
status
|
|
645
|
+
responseStatusCode
|
|
646
|
+
responseBody
|
|
647
|
+
errors
|
|
648
|
+
duration
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
`
|
|
652
|
+
);
|
|
653
|
+
var getFunctionExecution = gql(
|
|
654
|
+
/* GraphQL */
|
|
655
|
+
`
|
|
656
|
+
query GetFunctionExecution($functionId: String!, $executionId: String!) {
|
|
657
|
+
functionsGetExecution(functionId: $functionId, executionId: $executionId) {
|
|
658
|
+
status
|
|
659
|
+
errors
|
|
660
|
+
duration
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
`
|
|
664
|
+
);
|
|
665
|
+
function useFunction() {
|
|
666
|
+
const { graphql: graphql2 } = useAppwrite();
|
|
667
|
+
const [currentExecution, setCurrentExecution] = useState(null);
|
|
668
|
+
const [currentFunction, setCurrentFunction] = useState(null);
|
|
669
|
+
const executeFunction = useMutation({
|
|
670
|
+
mutationFn: async ({ functionId, body, async, path, method, headers }) => {
|
|
671
|
+
setCurrentFunction(functionId);
|
|
672
|
+
const { data } = await graphql2.mutation({
|
|
673
|
+
query: createExecution,
|
|
674
|
+
variables: {
|
|
675
|
+
functionId,
|
|
676
|
+
body: JSON.stringify(body),
|
|
677
|
+
async,
|
|
678
|
+
path,
|
|
679
|
+
method,
|
|
680
|
+
headers
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
let unsubscribe = null;
|
|
684
|
+
const { _id, status, responseBody, errors } = data.functionsCreateExecution ?? {};
|
|
685
|
+
if (status === "completed") {
|
|
686
|
+
return JSON.parse(responseBody ?? "{}");
|
|
687
|
+
}
|
|
688
|
+
if (status === "failed" && errors) {
|
|
689
|
+
throw new Error(errors);
|
|
690
|
+
}
|
|
691
|
+
setCurrentExecution(_id ?? null);
|
|
692
|
+
const response = await new Promise((resolve, reject) => {
|
|
693
|
+
unsubscribe = graphql2.client.subscribe(`executions.${_id}`, (event) => {
|
|
694
|
+
switch (event.payload.status) {
|
|
695
|
+
case "completed":
|
|
696
|
+
setCurrentExecution(null);
|
|
697
|
+
resolve(JSON.parse(event.payload.responseBody));
|
|
698
|
+
break;
|
|
699
|
+
case "failed":
|
|
700
|
+
setCurrentExecution(null);
|
|
701
|
+
reject(event.payload.errors);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
return 1;
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
unsubscribe?.();
|
|
708
|
+
return response;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
const getExecution = useQuery({
|
|
712
|
+
queryKey: ["appwrite", "functions", currentFunction, currentExecution],
|
|
713
|
+
queryFn: async () => {
|
|
714
|
+
if (!currentExecution || !currentFunction) {
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
const { data } = await graphql2.query({
|
|
718
|
+
query: getFunctionExecution,
|
|
719
|
+
variables: {
|
|
720
|
+
functionId: currentFunction,
|
|
721
|
+
executionId: currentExecution
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
return data.functionsGetExecution ?? {};
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
return {
|
|
728
|
+
executeFunction,
|
|
729
|
+
currentExecution: getExecution
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/account/fragments.ts
|
|
734
|
+
var Account_UserFragment = gql(
|
|
735
|
+
/* GraphQL */
|
|
736
|
+
`
|
|
737
|
+
fragment Account_UserFragment on User {
|
|
738
|
+
name
|
|
739
|
+
email
|
|
740
|
+
prefs {
|
|
741
|
+
data
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
`
|
|
745
|
+
);
|
|
746
|
+
|
|
747
|
+
// src/index.ts
|
|
748
|
+
var fragments = {
|
|
749
|
+
Account_UserFragment
|
|
750
|
+
};
|
|
751
|
+
export {
|
|
752
|
+
fragments,
|
|
753
|
+
getFragmentData,
|
|
754
|
+
useAccount,
|
|
755
|
+
useAppwrite,
|
|
756
|
+
useCollection,
|
|
757
|
+
useCreateDocument,
|
|
758
|
+
useDocument,
|
|
759
|
+
useFunction,
|
|
760
|
+
useLogin,
|
|
761
|
+
useLogout,
|
|
762
|
+
useMutation,
|
|
763
|
+
usePasswordRecovery,
|
|
764
|
+
useQuery,
|
|
765
|
+
useQueryClient,
|
|
766
|
+
useResetPassword,
|
|
767
|
+
useSignUp,
|
|
768
|
+
useVerification
|
|
769
|
+
};
|
|
770
|
+
//# sourceMappingURL=index.mjs.map
|