fogwind 1 неделя назад
Родитель
Сommit
2318bbc368
3 измененных файлов с 29 добавлено и 0 удалено
  1. 11 0
      README.md
  2. 16 0
      src/graphql/theme/queries/ThemeCustomization.ts
  3. 2 0
      src/lib/apollo-client.ts

+ 11 - 0
README.md

@@ -181,3 +181,14 @@ Bagisto headless eCommerce framework that will always remain free under the [MIT
 
 ## Security Vulnerabilities
 If you think that you have found a security issue in Bagisto Headless Commerce, please do not use the issue tracker and do not post it publicly. Instead, all security issues must be sent to [mailto:support@bagisto.com](mailto:support@bagisto.com).
+
+
+## 关于Next.js的缓存机制
+https://www.cnblogs.com/xibaoyu/p/18898224
+
+## 关于next-auth
+https://next-auth.js.org/getting-started/introduction
+
+
+## 关于.env
+.env中NEXT_PUBLIC_NEXT_AUTH_SECRET字段的值是openssl rand -base64 32 生成的,应该是生成token时或者session签名时用到

+ 16 - 0
src/graphql/theme/queries/ThemeCustomization.ts

@@ -1,5 +1,21 @@
 import { gql } from "@apollo/client";
 
+/**
+ * query 是操作类型
+ * themeCustomization 是操作名称
+ * $first 是变量名称,Int是变量$first的类型
+ * 
+ * query 里边的是接口返回的数据结构的形式,以及字段名(字段名根据后端的模型定义确定)
+ * themeCustomizations 是接口返回数据的字段名,这个不是随便写的,由后端的定义确定,比如:
+ * {
+ *     data: {
+ *         themeCustomizations: { ... }
+ *     }
+ * }
+ * first 是接口参数,值是变量$first的值,含义是请求从列表开头开始的 N 条数据
+ * 如果定义变量时后边有!,表示这个变量是必须要有值的,没有!表示这个变量可以不传值(也就是接口参数是否是必传的)
+ * edges 和 node 是graphql中的概念,edges相当于数组,node相当于数组中的项
+ */
 export const GET_THEME_CUSTOMIZATION = gql`
   query themeCustomization($first: Int) {
     themeCustomizations(first: $first) {

+ 2 - 0
src/lib/apollo-client.ts

@@ -39,11 +39,13 @@ function createApolloClient() {
   const ssrMode = typeof window === "undefined";
   const cache = new InMemoryCache();
 
+  // 服务端渲染的话请求的地址是bagisto后端地址,否则的话请求的是nextjs的代理接口
   const httpLink = new HttpLink({
     uri: ssrMode ? GRAPHQL_URL : "/api/graphql",
     credentials: "include",
   });
 
+  // 如果是服务端渲染,因为直接调用bagisto后端接口,需要设置storefront key
   const authLink = setContext(async (_, { headers }) => {
     if (ssrMode) {
       const storefrontKey =