naystack 1.7.25 → 1.7.26

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.
@@ -116,31 +116,34 @@ var tokenContext = (token) => {
116
116
  };
117
117
  };
118
118
  function useAuthQuery(query, variables) {
119
- const token = (0, import_client2.useToken)();
120
119
  const [fetch, result] = (0, import_client.useLazyQuery)(query, {
121
120
  fetchPolicy: "no-cache"
122
121
  });
123
122
  const prevVarsRef = (0, import_react.useRef)(null);
124
123
  (0, import_react.useEffect)(() => {
125
124
  const serialized = JSON.stringify(variables);
126
- if (token && variables && prevVarsRef.current !== serialized) {
125
+ if (variables && prevVarsRef.current !== serialized) {
127
126
  prevVarsRef.current = serialized;
128
127
  void fetch({
129
128
  // @ts-expect-error -- to allow dynamic props
130
129
  variables: { input: variables },
131
- context: tokenContext(token)
130
+ context: {
131
+ credentials: `include`
132
+ }
132
133
  });
133
134
  }
134
- }, [fetch, token, variables]);
135
+ }, [fetch, variables]);
135
136
  const reFetch = (0, import_react.useCallback)(
136
137
  (input) => fetch({
137
138
  // @ts-expect-error -- to allow dynamic props
138
139
  variables: { input },
139
- context: tokenContext(token)
140
+ context: {
141
+ credentials: `include`
142
+ }
140
143
  }),
141
- [fetch, token]
144
+ [fetch]
142
145
  );
143
- return [reFetch, { ...result, hasAuth: !!token }];
146
+ return [reFetch, result];
144
147
  }
145
148
  function useAuthMutation(mutation, options) {
146
149
  const token = (0, import_client2.useToken)();
@@ -1,6 +1,5 @@
1
- import * as graphql from 'graphql';
2
1
  import * as _apollo_client from '@apollo/client';
3
- import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
2
+ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions, ApolloClient } from '@apollo/client';
4
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
4
  import React__default, { PropsWithChildren } from 'react';
6
5
 
@@ -59,31 +58,7 @@ declare const tokenContext: (token?: string | null) => {
59
58
  *
60
59
  * @category GraphQL
61
60
  */
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
- }];
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>>, _apollo_client.QueryResult<T, V>];
87
62
  /**
88
63
  * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
89
64
  *
@@ -1,6 +1,5 @@
1
- import * as graphql from 'graphql';
2
1
  import * as _apollo_client from '@apollo/client';
3
- import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
2
+ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions, ApolloClient } from '@apollo/client';
4
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
4
  import React__default, { PropsWithChildren } from 'react';
6
5
 
@@ -59,31 +58,7 @@ declare const tokenContext: (token?: string | null) => {
59
58
  *
60
59
  * @category GraphQL
61
60
  */
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
- }];
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>>, _apollo_client.QueryResult<T, V>];
87
62
  /**
88
63
  * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
89
64
  *
@@ -91,31 +91,34 @@ var tokenContext = (token) => {
91
91
  };
92
92
  };
93
93
  function useAuthQuery(query, variables) {
94
- const token = useToken();
95
94
  const [fetch, result] = useLazyQuery(query, {
96
95
  fetchPolicy: "no-cache"
97
96
  });
98
97
  const prevVarsRef = useRef(null);
99
98
  useEffect(() => {
100
99
  const serialized = JSON.stringify(variables);
101
- if (token && variables && prevVarsRef.current !== serialized) {
100
+ if (variables && prevVarsRef.current !== serialized) {
102
101
  prevVarsRef.current = serialized;
103
102
  void fetch({
104
103
  // @ts-expect-error -- to allow dynamic props
105
104
  variables: { input: variables },
106
- context: tokenContext(token)
105
+ context: {
106
+ credentials: `include`
107
+ }
107
108
  });
108
109
  }
109
- }, [fetch, token, variables]);
110
+ }, [fetch, variables]);
110
111
  const reFetch = useCallback(
111
112
  (input) => fetch({
112
113
  // @ts-expect-error -- to allow dynamic props
113
114
  variables: { input },
114
- context: tokenContext(token)
115
+ context: {
116
+ credentials: `include`
117
+ }
115
118
  }),
116
- [fetch, token]
119
+ [fetch]
117
120
  );
118
- return [reFetch, { ...result, hasAuth: !!token }];
121
+ return [reFetch, result];
119
122
  }
120
123
  function useAuthMutation(mutation, options) {
121
124
  const token = useToken();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.7.25",
3
+ "version": "1.7.26",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",