naystack 1.7.10 → 1.7.12
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.
|
@@ -32,15 +32,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var client_exports = {};
|
|
33
33
|
__export(client_exports, {
|
|
34
34
|
ApolloWrapperClient: () => ApolloWrapperClient,
|
|
35
|
-
ApolloWrapperNext: () => ApolloWrapper,
|
|
36
35
|
tokenContext: () => tokenContext,
|
|
37
36
|
useAuthMutation: () => useAuthMutation,
|
|
38
37
|
useAuthQuery: () => useAuthQuery
|
|
39
38
|
});
|
|
40
39
|
module.exports = __toCommonJS(client_exports);
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
40
|
+
var import_client = require("@apollo/client");
|
|
41
|
+
var import_client2 = require("naystack/auth/client");
|
|
42
|
+
var import_react = __toESM(require("react"));
|
|
44
43
|
|
|
45
44
|
// src/env.ts
|
|
46
45
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -92,39 +91,20 @@ function getEnv(key, skipCheck) {
|
|
|
92
91
|
return value;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
// src/graphql/
|
|
96
|
-
var import_client = require("@apollo/client");
|
|
97
|
-
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
98
|
-
var import_react = __toESM(require("react"));
|
|
94
|
+
// src/graphql/client.tsx
|
|
99
95
|
function makeClient(cacheConfig) {
|
|
100
|
-
return new
|
|
101
|
-
cache: new
|
|
96
|
+
return new import_client.ApolloClient({
|
|
97
|
+
cache: new import_client.InMemoryCache(cacheConfig),
|
|
102
98
|
link: new import_client.HttpLink({
|
|
103
99
|
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
104
100
|
})
|
|
105
101
|
});
|
|
106
102
|
}
|
|
107
|
-
var ApolloWrapper = ({
|
|
108
|
-
children,
|
|
109
|
-
cacheConfig
|
|
110
|
-
}) => {
|
|
111
|
-
return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// src/graphql/client.tsx
|
|
115
|
-
function makeClient2(cacheConfig) {
|
|
116
|
-
return new import_client2.ApolloClient({
|
|
117
|
-
cache: new import_client2.InMemoryCache(cacheConfig),
|
|
118
|
-
link: new import_client2.HttpLink({
|
|
119
|
-
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
120
|
-
})
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
103
|
var ApolloWrapperClient = ({
|
|
124
104
|
children,
|
|
125
105
|
cacheConfig
|
|
126
106
|
}) => {
|
|
127
|
-
return /* @__PURE__ */
|
|
107
|
+
return /* @__PURE__ */ import_react.default.createElement(import_client.ApolloProvider, { client: makeClient(cacheConfig) }, children);
|
|
128
108
|
};
|
|
129
109
|
var tokenContext = (token) => {
|
|
130
110
|
if (!token) return void 0;
|
|
@@ -136,12 +116,12 @@ var tokenContext = (token) => {
|
|
|
136
116
|
};
|
|
137
117
|
};
|
|
138
118
|
function useAuthQuery(query, variables) {
|
|
139
|
-
const token = (0,
|
|
140
|
-
const [fetch, result] = (0,
|
|
119
|
+
const token = (0, import_client2.useToken)();
|
|
120
|
+
const [fetch, result] = (0, import_client.useLazyQuery)(query, {
|
|
141
121
|
fetchPolicy: "no-cache"
|
|
142
122
|
});
|
|
143
|
-
const prevVarsRef = (0,
|
|
144
|
-
(0,
|
|
123
|
+
const prevVarsRef = (0, import_react.useRef)(null);
|
|
124
|
+
(0, import_react.useEffect)(() => {
|
|
145
125
|
const serialized = JSON.stringify(variables);
|
|
146
126
|
if (token && variables && prevVarsRef.current !== serialized) {
|
|
147
127
|
prevVarsRef.current = serialized;
|
|
@@ -152,7 +132,7 @@ function useAuthQuery(query, variables) {
|
|
|
152
132
|
});
|
|
153
133
|
}
|
|
154
134
|
}, [fetch, token, variables]);
|
|
155
|
-
const reFetch = (0,
|
|
135
|
+
const reFetch = (0, import_react.useCallback)(
|
|
156
136
|
(input) => fetch({
|
|
157
137
|
// @ts-expect-error -- to allow dynamic props
|
|
158
138
|
variables: { input },
|
|
@@ -163,9 +143,9 @@ function useAuthQuery(query, variables) {
|
|
|
163
143
|
return [reFetch, { ...result, hasAuth: !!token }];
|
|
164
144
|
}
|
|
165
145
|
function useAuthMutation(mutation, options) {
|
|
166
|
-
const token = (0,
|
|
167
|
-
const [mutate, result] = (0,
|
|
168
|
-
const method = (0,
|
|
146
|
+
const token = (0, import_client2.useToken)();
|
|
147
|
+
const [mutate, result] = (0, import_client.useMutation)(mutation, options);
|
|
148
|
+
const method = (0, import_react.useCallback)(
|
|
169
149
|
(input) => mutate({
|
|
170
150
|
// @ts-expect-error -- to allow dynamic props
|
|
171
151
|
variables: { input },
|
|
@@ -178,7 +158,6 @@ function useAuthMutation(mutation, options) {
|
|
|
178
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
159
|
0 && (module.exports = {
|
|
180
160
|
ApolloWrapperClient,
|
|
181
|
-
ApolloWrapperNext,
|
|
182
161
|
tokenContext,
|
|
183
162
|
useAuthMutation,
|
|
184
163
|
useAuthQuery
|
|
@@ -3,7 +3,6 @@ import * as _apollo_client from '@apollo/client';
|
|
|
3
3
|
import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
|
|
4
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
5
|
import React__default, { PropsWithChildren } from 'react';
|
|
6
|
-
export { ApolloWrapper as ApolloWrapperNext } from './next.mjs';
|
|
7
6
|
|
|
8
7
|
declare const ApolloWrapperClient: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
9
8
|
cacheConfig?: InMemoryCacheConfig;
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as _apollo_client from '@apollo/client';
|
|
|
3
3
|
import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
|
|
4
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
5
|
import React__default, { PropsWithChildren } from 'react';
|
|
6
|
-
export { ApolloWrapper as ApolloWrapperNext } from './next.js';
|
|
7
6
|
|
|
8
7
|
declare const ApolloWrapperClient: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
9
8
|
cacheConfig?: InMemoryCacheConfig;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
// src/graphql/client.tsx
|
|
4
4
|
import {
|
|
5
|
-
ApolloClient
|
|
5
|
+
ApolloClient,
|
|
6
6
|
ApolloProvider,
|
|
7
|
-
HttpLink
|
|
8
|
-
InMemoryCache
|
|
7
|
+
HttpLink,
|
|
8
|
+
InMemoryCache,
|
|
9
9
|
useLazyQuery,
|
|
10
10
|
useMutation
|
|
11
11
|
} from "@apollo/client";
|
|
12
12
|
import { useToken } from "naystack/auth/client";
|
|
13
|
-
import
|
|
13
|
+
import React, {
|
|
14
14
|
useCallback,
|
|
15
15
|
useEffect,
|
|
16
16
|
useRef
|
|
@@ -66,14 +66,7 @@ function getEnv(key, skipCheck) {
|
|
|
66
66
|
return value;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// src/graphql/
|
|
70
|
-
import { HttpLink } from "@apollo/client";
|
|
71
|
-
import {
|
|
72
|
-
ApolloClient,
|
|
73
|
-
ApolloNextAppProvider,
|
|
74
|
-
InMemoryCache
|
|
75
|
-
} from "@apollo/client-integration-nextjs";
|
|
76
|
-
import React from "react";
|
|
69
|
+
// src/graphql/client.tsx
|
|
77
70
|
function makeClient(cacheConfig) {
|
|
78
71
|
return new ApolloClient({
|
|
79
72
|
cache: new InMemoryCache(cacheConfig),
|
|
@@ -82,27 +75,11 @@ function makeClient(cacheConfig) {
|
|
|
82
75
|
})
|
|
83
76
|
});
|
|
84
77
|
}
|
|
85
|
-
var ApolloWrapper = ({
|
|
86
|
-
children,
|
|
87
|
-
cacheConfig
|
|
88
|
-
}) => {
|
|
89
|
-
return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// src/graphql/client.tsx
|
|
93
|
-
function makeClient2(cacheConfig) {
|
|
94
|
-
return new ApolloClient2({
|
|
95
|
-
cache: new InMemoryCache2(cacheConfig),
|
|
96
|
-
link: new HttpLink2({
|
|
97
|
-
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
98
|
-
})
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
78
|
var ApolloWrapperClient = ({
|
|
102
79
|
children,
|
|
103
80
|
cacheConfig
|
|
104
81
|
}) => {
|
|
105
|
-
return /* @__PURE__ */
|
|
82
|
+
return /* @__PURE__ */ React.createElement(ApolloProvider, { client: makeClient(cacheConfig) }, children);
|
|
106
83
|
};
|
|
107
84
|
var tokenContext = (token) => {
|
|
108
85
|
if (!token) return void 0;
|
|
@@ -155,7 +132,6 @@ function useAuthMutation(mutation, options) {
|
|
|
155
132
|
}
|
|
156
133
|
export {
|
|
157
134
|
ApolloWrapperClient,
|
|
158
|
-
ApolloWrapper as ApolloWrapperNext,
|
|
159
135
|
tokenContext,
|
|
160
136
|
useAuthMutation,
|
|
161
137
|
useAuthQuery
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "naystack",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.12",
|
|
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",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"import": "./dist/graphql/client.esm.js",
|
|
34
34
|
"require": "./dist/graphql/client.cjs.js"
|
|
35
35
|
},
|
|
36
|
+
"./graphql/next": {
|
|
37
|
+
"types": "./dist/graphql/next.d.ts",
|
|
38
|
+
"import": "./dist/graphql/next.esm.js",
|
|
39
|
+
"require": "./dist/graphql/next.cjs.js"
|
|
40
|
+
},
|
|
36
41
|
"./file": {
|
|
37
42
|
"types": "./dist/file/index.d.ts",
|
|
38
43
|
"import": "./dist/file/index.esm.js",
|