naystack 1.5.41 → 1.6.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/dist/graphql/client.cjs.js +12 -11
- package/dist/graphql/client.d.mts +36 -3
- package/dist/graphql/client.d.ts +36 -3
- package/dist/graphql/client.esm.js +13 -12
- package/dist/graphql/index.cjs.js +1 -0
- package/dist/graphql/index.d.mts +1 -1
- package/dist/graphql/index.d.ts +1 -1
- package/dist/graphql/index.esm.js +1 -0
- package/dist/graphql/utils.cjs.js +1 -0
- package/dist/graphql/utils.d.mts +1 -1
- package/dist/graphql/utils.d.ts +1 -1
- package/dist/graphql/utils.esm.js +1 -0
- package/package.json +1 -1
|
@@ -118,41 +118,42 @@ var tokenContext = (token) => {
|
|
|
118
118
|
function useAuthQuery(query, variables) {
|
|
119
119
|
const token = (0, import_client2.useToken)();
|
|
120
120
|
const [fetch, result] = (0, import_client.useLazyQuery)(query);
|
|
121
|
-
const
|
|
121
|
+
const prevVarsRef = (0, import_react.useRef)(null);
|
|
122
122
|
(0, import_react.useEffect)(() => {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
const serialized = JSON.stringify(variables);
|
|
124
|
+
if (token && variables && prevVarsRef.current !== serialized) {
|
|
125
|
+
prevVarsRef.current = serialized;
|
|
125
126
|
void fetch({
|
|
126
127
|
// @ts-expect-error -- to allow dynamic props
|
|
127
|
-
variables: { input },
|
|
128
|
+
variables: { input: variables },
|
|
128
129
|
context: tokenContext(token),
|
|
129
130
|
fetchPolicy: "no-cache"
|
|
130
131
|
});
|
|
131
132
|
}
|
|
132
|
-
}, [fetch, token, variables
|
|
133
|
+
}, [fetch, token, variables]);
|
|
133
134
|
const reFetch = (0, import_react.useCallback)(
|
|
134
|
-
(
|
|
135
|
+
(input) => fetch({
|
|
135
136
|
// @ts-expect-error -- to allow dynamic props
|
|
136
|
-
variables: { input
|
|
137
|
+
variables: { input },
|
|
137
138
|
context: tokenContext(token),
|
|
138
139
|
fetchPolicy: "no-cache"
|
|
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
|
|
@@ -93,41 +93,42 @@ var tokenContext = (token) => {
|
|
|
93
93
|
function useAuthQuery(query, variables) {
|
|
94
94
|
const token = useToken();
|
|
95
95
|
const [fetch, result] = useLazyQuery(query);
|
|
96
|
-
const
|
|
96
|
+
const prevVarsRef = useRef(null);
|
|
97
97
|
useEffect(() => {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const serialized = JSON.stringify(variables);
|
|
99
|
+
if (token && variables && prevVarsRef.current !== serialized) {
|
|
100
|
+
prevVarsRef.current = serialized;
|
|
100
101
|
void fetch({
|
|
101
102
|
// @ts-expect-error -- to allow dynamic props
|
|
102
|
-
variables: { input },
|
|
103
|
+
variables: { input: variables },
|
|
103
104
|
context: tokenContext(token),
|
|
104
105
|
fetchPolicy: "no-cache"
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
}, [fetch, token, variables
|
|
108
|
+
}, [fetch, token, variables]);
|
|
108
109
|
const reFetch = useCallback(
|
|
109
|
-
(
|
|
110
|
+
(input) => fetch({
|
|
110
111
|
// @ts-expect-error -- to allow dynamic props
|
|
111
|
-
variables: { input
|
|
112
|
+
variables: { input },
|
|
112
113
|
context: tokenContext(token),
|
|
113
114
|
fetchPolicy: "no-cache"
|
|
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,
|
|
@@ -880,6 +880,7 @@ function FieldLibrary(type, queries) {
|
|
|
880
880
|
if (!def) continue;
|
|
881
881
|
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
882
882
|
value: async function(root, ctx, input) {
|
|
883
|
+
if (root[key]) return root[key];
|
|
883
884
|
return def.fn(root, ctx, input);
|
|
884
885
|
},
|
|
885
886
|
writable: false
|
package/dist/graphql/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { GQLError } from './errors.mjs';
|
|
2
2
|
export { initGraphQLServer } from './init.mjs';
|
|
3
3
|
export { AuthorizedContext, Context } from './types.mjs';
|
|
4
|
-
export { FieldLibrary, FieldResponseType, QueryLibrary, QueryResponseType, field, query } from './utils.mjs';
|
|
4
|
+
export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, query } from './utils.mjs';
|
|
5
5
|
import 'graphql/error';
|
|
6
6
|
import '@apollo/server';
|
|
7
7
|
import 'next/server';
|
package/dist/graphql/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { GQLError } from './errors.js';
|
|
2
2
|
export { initGraphQLServer } from './init.js';
|
|
3
3
|
export { AuthorizedContext, Context } from './types.js';
|
|
4
|
-
export { FieldLibrary, FieldResponseType, QueryLibrary, QueryResponseType, field, query } from './utils.js';
|
|
4
|
+
export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, query } from './utils.js';
|
|
5
5
|
import 'graphql/error';
|
|
6
6
|
import '@apollo/server';
|
|
7
7
|
import 'next/server';
|
|
@@ -876,6 +876,7 @@ function FieldLibrary(type, queries) {
|
|
|
876
876
|
if (!def) continue;
|
|
877
877
|
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
878
878
|
value: async function(root, ctx, input) {
|
|
879
|
+
if (root[key]) return root[key];
|
|
879
880
|
return def.fn(root, ctx, input);
|
|
880
881
|
},
|
|
881
882
|
writable: false
|
|
@@ -237,6 +237,7 @@ function FieldLibrary(type, queries) {
|
|
|
237
237
|
if (!def) continue;
|
|
238
238
|
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
239
239
|
value: async function(root, ctx, input) {
|
|
240
|
+
if (root[key]) return root[key];
|
|
240
241
|
return def.fn(root, ctx, input);
|
|
241
242
|
},
|
|
242
243
|
writable: false
|
package/dist/graphql/utils.d.mts
CHANGED
|
@@ -264,4 +264,4 @@ type QueryResponseType<T extends QueryDefinition<any, any, any, any, any, any>>
|
|
|
264
264
|
*/
|
|
265
265
|
type FieldResponseType<T extends FieldResolverDefinition<any, any, any, any, any, any, any>> = Awaited<ReturnType<T["call"]>>;
|
|
266
266
|
|
|
267
|
-
export { FieldLibrary, type FieldResponseType, QueryLibrary, type QueryResponseType, field, query };
|
|
267
|
+
export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, query };
|
package/dist/graphql/utils.d.ts
CHANGED
|
@@ -264,4 +264,4 @@ type QueryResponseType<T extends QueryDefinition<any, any, any, any, any, any>>
|
|
|
264
264
|
*/
|
|
265
265
|
type FieldResponseType<T extends FieldResolverDefinition<any, any, any, any, any, any, any>> = Awaited<ReturnType<T["call"]>>;
|
|
266
266
|
|
|
267
|
-
export { FieldLibrary, type FieldResponseType, QueryLibrary, type QueryResponseType, field, query };
|
|
267
|
+
export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, query };
|
|
@@ -222,6 +222,7 @@ function FieldLibrary(type, queries) {
|
|
|
222
222
|
if (!def) continue;
|
|
223
223
|
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
224
224
|
value: async function(root, ctx, input) {
|
|
225
|
+
if (root[key]) return root[key];
|
|
225
226
|
return def.fn(root, ctx, input);
|
|
226
227
|
},
|
|
227
228
|
writable: false
|