naystack 1.5.42 → 1.6.1
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/graphql/client.cjs.js +17 -16
- package/dist/graphql/client.d.mts +36 -3
- package/dist/graphql/client.d.ts +36 -3
- package/dist/graphql/client.esm.js +18 -17
- package/package.json +1 -1
|
@@ -117,42 +117,43 @@ var tokenContext = (token) => {
|
|
|
117
117
|
};
|
|
118
118
|
function useAuthQuery(query, variables) {
|
|
119
119
|
const token = (0, import_client2.useToken)();
|
|
120
|
-
const [fetch, result] = (0, import_client.useLazyQuery)(query
|
|
121
|
-
|
|
120
|
+
const [fetch, result] = (0, import_client.useLazyQuery)(query, {
|
|
121
|
+
fetchPolicy: "no-cache"
|
|
122
|
+
});
|
|
123
|
+
const prevVarsRef = (0, import_react.useRef)(null);
|
|
122
124
|
(0, import_react.useEffect)(() => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
const serialized = JSON.stringify(variables);
|
|
126
|
+
if (token && variables && prevVarsRef.current !== serialized) {
|
|
127
|
+
prevVarsRef.current = serialized;
|
|
125
128
|
void fetch({
|
|
126
129
|
// @ts-expect-error -- to allow dynamic props
|
|
127
|
-
variables: { input },
|
|
128
|
-
context: tokenContext(token)
|
|
129
|
-
fetchPolicy: "no-cache"
|
|
130
|
+
variables: { input: variables },
|
|
131
|
+
context: tokenContext(token)
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
|
-
}, [fetch, token, variables
|
|
134
|
+
}, [fetch, token, variables]);
|
|
133
135
|
const reFetch = (0, import_react.useCallback)(
|
|
134
|
-
(
|
|
136
|
+
(input) => fetch({
|
|
135
137
|
// @ts-expect-error -- to allow dynamic props
|
|
136
|
-
variables: { input
|
|
137
|
-
context: tokenContext(token)
|
|
138
|
-
fetchPolicy: "no-cache"
|
|
138
|
+
variables: { input },
|
|
139
|
+
context: tokenContext(token)
|
|
139
140
|
}),
|
|
140
141
|
[fetch, token]
|
|
141
142
|
);
|
|
142
|
-
return [reFetch, result];
|
|
143
|
+
return [reFetch, { ...result, hasAuth: !!token }];
|
|
143
144
|
}
|
|
144
145
|
function useAuthMutation(mutation, options) {
|
|
145
146
|
const token = (0, import_client2.useToken)();
|
|
146
147
|
const [mutate, result] = (0, import_client.useMutation)(mutation, options);
|
|
147
148
|
const method = (0, import_react.useCallback)(
|
|
148
|
-
(
|
|
149
|
+
(input) => mutate({
|
|
149
150
|
// @ts-expect-error -- to allow dynamic props
|
|
150
|
-
variables: { input
|
|
151
|
+
variables: { input },
|
|
151
152
|
context: tokenContext(token)
|
|
152
153
|
}),
|
|
153
154
|
[token]
|
|
154
155
|
);
|
|
155
|
-
return [method, result];
|
|
156
|
+
return [method, { ...result, hasAuth: !!token }];
|
|
156
157
|
}
|
|
157
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
158
159
|
0 && (module.exports = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as graphql from 'graphql';
|
|
1
2
|
import * as _apollo_client from '@apollo/client';
|
|
2
|
-
import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
3
|
+
import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
|
|
3
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
5
|
import React__default, { PropsWithChildren } from 'react';
|
|
5
6
|
|
|
@@ -58,7 +59,31 @@ declare const tokenContext: (token?: string | null) => {
|
|
|
58
59
|
*
|
|
59
60
|
* @category GraphQL
|
|
60
61
|
*/
|
|
61
|
-
declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>,
|
|
62
|
+
declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, {
|
|
63
|
+
readonly hasAuth: false;
|
|
64
|
+
readonly client: ApolloClient<any>;
|
|
65
|
+
readonly observable: _apollo_client.ObservableQuery<T, V>;
|
|
66
|
+
readonly data: T | undefined;
|
|
67
|
+
readonly previousData?: T | undefined;
|
|
68
|
+
readonly error?: _apollo_client.ApolloError;
|
|
69
|
+
readonly errors?: ReadonlyArray<graphql.GraphQLFormattedError>;
|
|
70
|
+
readonly loading: boolean;
|
|
71
|
+
readonly networkStatus: _apollo_client.NetworkStatus;
|
|
72
|
+
readonly called: boolean;
|
|
73
|
+
readonly startPolling: (pollInterval: number) => void;
|
|
74
|
+
readonly stopPolling: () => void;
|
|
75
|
+
readonly subscribeToMore: _apollo_client.SubscribeToMoreFunction<T, V>;
|
|
76
|
+
readonly updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<T, V>) => void;
|
|
77
|
+
readonly refetch: (variables?: Partial<V> | undefined) => Promise<_apollo_client.ApolloQueryResult<T>>;
|
|
78
|
+
readonly reobserve: (newOptions?: Partial<_apollo_client.WatchQueryOptions<V, T>> | undefined, newNetworkStatus?: _apollo_client.NetworkStatus) => Promise<_apollo_client.ApolloQueryResult<T>>;
|
|
79
|
+
readonly variables: V | undefined;
|
|
80
|
+
readonly fetchMore: <TFetchData = T, TFetchVars extends OperationVariables = V>(fetchMoreOptions: _apollo_client.FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
81
|
+
updateQuery?: ((previousQueryResult: _apollo_client.Unmasked<T>, options: {
|
|
82
|
+
fetchMoreResult: _apollo_client.Unmasked<TFetchData>;
|
|
83
|
+
variables: TFetchVars;
|
|
84
|
+
}) => _apollo_client.Unmasked<T>) | undefined;
|
|
85
|
+
}) => Promise<_apollo_client.ApolloQueryResult<TFetchData>>;
|
|
86
|
+
}];
|
|
62
87
|
/**
|
|
63
88
|
* Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
|
|
64
89
|
*
|
|
@@ -94,6 +119,14 @@ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocum
|
|
|
94
119
|
*
|
|
95
120
|
* @category GraphQL
|
|
96
121
|
*/
|
|
97
|
-
declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input?: V["input"]) => Promise<_apollo_client.FetchResult<T>>,
|
|
122
|
+
declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input?: V["input"]) => Promise<_apollo_client.FetchResult<T>>, {
|
|
123
|
+
readonly hasAuth: false;
|
|
124
|
+
readonly data?: T | null | undefined;
|
|
125
|
+
readonly error?: _apollo_client.ApolloError;
|
|
126
|
+
readonly loading: boolean;
|
|
127
|
+
readonly called: boolean;
|
|
128
|
+
readonly client: ApolloClient<object>;
|
|
129
|
+
readonly reset: () => void;
|
|
130
|
+
}];
|
|
98
131
|
|
|
99
132
|
export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as graphql from 'graphql';
|
|
1
2
|
import * as _apollo_client from '@apollo/client';
|
|
2
|
-
import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
3
|
+
import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
|
|
3
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
5
|
import React__default, { PropsWithChildren } from 'react';
|
|
5
6
|
|
|
@@ -58,7 +59,31 @@ declare const tokenContext: (token?: string | null) => {
|
|
|
58
59
|
*
|
|
59
60
|
* @category GraphQL
|
|
60
61
|
*/
|
|
61
|
-
declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>,
|
|
62
|
+
declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, {
|
|
63
|
+
readonly hasAuth: false;
|
|
64
|
+
readonly client: ApolloClient<any>;
|
|
65
|
+
readonly observable: _apollo_client.ObservableQuery<T, V>;
|
|
66
|
+
readonly data: T | undefined;
|
|
67
|
+
readonly previousData?: T | undefined;
|
|
68
|
+
readonly error?: _apollo_client.ApolloError;
|
|
69
|
+
readonly errors?: ReadonlyArray<graphql.GraphQLFormattedError>;
|
|
70
|
+
readonly loading: boolean;
|
|
71
|
+
readonly networkStatus: _apollo_client.NetworkStatus;
|
|
72
|
+
readonly called: boolean;
|
|
73
|
+
readonly startPolling: (pollInterval: number) => void;
|
|
74
|
+
readonly stopPolling: () => void;
|
|
75
|
+
readonly subscribeToMore: _apollo_client.SubscribeToMoreFunction<T, V>;
|
|
76
|
+
readonly updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<T, V>) => void;
|
|
77
|
+
readonly refetch: (variables?: Partial<V> | undefined) => Promise<_apollo_client.ApolloQueryResult<T>>;
|
|
78
|
+
readonly reobserve: (newOptions?: Partial<_apollo_client.WatchQueryOptions<V, T>> | undefined, newNetworkStatus?: _apollo_client.NetworkStatus) => Promise<_apollo_client.ApolloQueryResult<T>>;
|
|
79
|
+
readonly variables: V | undefined;
|
|
80
|
+
readonly fetchMore: <TFetchData = T, TFetchVars extends OperationVariables = V>(fetchMoreOptions: _apollo_client.FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
81
|
+
updateQuery?: ((previousQueryResult: _apollo_client.Unmasked<T>, options: {
|
|
82
|
+
fetchMoreResult: _apollo_client.Unmasked<TFetchData>;
|
|
83
|
+
variables: TFetchVars;
|
|
84
|
+
}) => _apollo_client.Unmasked<T>) | undefined;
|
|
85
|
+
}) => Promise<_apollo_client.ApolloQueryResult<TFetchData>>;
|
|
86
|
+
}];
|
|
62
87
|
/**
|
|
63
88
|
* Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
|
|
64
89
|
*
|
|
@@ -94,6 +119,14 @@ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocum
|
|
|
94
119
|
*
|
|
95
120
|
* @category GraphQL
|
|
96
121
|
*/
|
|
97
|
-
declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input?: V["input"]) => Promise<_apollo_client.FetchResult<T>>,
|
|
122
|
+
declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input?: V["input"]) => Promise<_apollo_client.FetchResult<T>>, {
|
|
123
|
+
readonly hasAuth: false;
|
|
124
|
+
readonly data?: T | null | undefined;
|
|
125
|
+
readonly error?: _apollo_client.ApolloError;
|
|
126
|
+
readonly loading: boolean;
|
|
127
|
+
readonly called: boolean;
|
|
128
|
+
readonly client: ApolloClient<object>;
|
|
129
|
+
readonly reset: () => void;
|
|
130
|
+
}];
|
|
98
131
|
|
|
99
132
|
export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
|
|
@@ -13,7 +13,7 @@ import { useToken } from "naystack/auth/email/client";
|
|
|
13
13
|
import React, {
|
|
14
14
|
useCallback,
|
|
15
15
|
useEffect,
|
|
16
|
-
|
|
16
|
+
useRef
|
|
17
17
|
} from "react";
|
|
18
18
|
|
|
19
19
|
// src/env.ts
|
|
@@ -92,42 +92,43 @@ var tokenContext = (token) => {
|
|
|
92
92
|
};
|
|
93
93
|
function useAuthQuery(query, variables) {
|
|
94
94
|
const token = useToken();
|
|
95
|
-
const [fetch, result] = useLazyQuery(query
|
|
96
|
-
|
|
95
|
+
const [fetch, result] = useLazyQuery(query, {
|
|
96
|
+
fetchPolicy: "no-cache"
|
|
97
|
+
});
|
|
98
|
+
const prevVarsRef = useRef(null);
|
|
97
99
|
useEffect(() => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
const serialized = JSON.stringify(variables);
|
|
101
|
+
if (token && variables && prevVarsRef.current !== serialized) {
|
|
102
|
+
prevVarsRef.current = serialized;
|
|
100
103
|
void fetch({
|
|
101
104
|
// @ts-expect-error -- to allow dynamic props
|
|
102
|
-
variables: { input },
|
|
103
|
-
context: tokenContext(token)
|
|
104
|
-
fetchPolicy: "no-cache"
|
|
105
|
+
variables: { input: variables },
|
|
106
|
+
context: tokenContext(token)
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
|
-
}, [fetch, token, variables
|
|
109
|
+
}, [fetch, token, variables]);
|
|
108
110
|
const reFetch = useCallback(
|
|
109
|
-
(
|
|
111
|
+
(input) => fetch({
|
|
110
112
|
// @ts-expect-error -- to allow dynamic props
|
|
111
|
-
variables: { input
|
|
112
|
-
context: tokenContext(token)
|
|
113
|
-
fetchPolicy: "no-cache"
|
|
113
|
+
variables: { input },
|
|
114
|
+
context: tokenContext(token)
|
|
114
115
|
}),
|
|
115
116
|
[fetch, token]
|
|
116
117
|
);
|
|
117
|
-
return [reFetch, result];
|
|
118
|
+
return [reFetch, { ...result, hasAuth: !!token }];
|
|
118
119
|
}
|
|
119
120
|
function useAuthMutation(mutation, options) {
|
|
120
121
|
const token = useToken();
|
|
121
122
|
const [mutate, result] = useMutation(mutation, options);
|
|
122
123
|
const method = useCallback(
|
|
123
|
-
(
|
|
124
|
+
(input) => mutate({
|
|
124
125
|
// @ts-expect-error -- to allow dynamic props
|
|
125
|
-
variables: { input
|
|
126
|
+
variables: { input },
|
|
126
127
|
context: tokenContext(token)
|
|
127
128
|
}),
|
|
128
129
|
[token]
|
|
129
130
|
);
|
|
130
|
-
return [method, result];
|
|
131
|
+
return [method, { ...result, hasAuth: !!token }];
|
|
131
132
|
}
|
|
132
133
|
export {
|
|
133
134
|
ApolloWrapper,
|