File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,22 @@ export function toSlug(string) {
17
17
18
18
var without = "aaaaeeeeiiiioooouuuunc" ;
19
19
20
- return String ( string )
20
+ string = String ( string )
21
+
22
+ if ( string . indexOf ( '(' ) === - 1 ) {
23
+ return string
24
+
25
+ // Handle uppercase characters
26
+ . toLowerCase ( )
27
+
28
+ // Dash blank characters
29
+ . replace ( / \s + / g, '-' )
30
+
31
+ // Trim dashes
32
+ . replace ( / ^ - | - $ / g, '' ) ;
33
+ }
34
+
35
+ return string
21
36
22
37
// Handle uppercase characters
23
38
. toLowerCase ( )
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ next: /learn/pagination/
12
12
13
13
** “只有作者才能看到他们自己的草稿”**
14
14
15
- 应当在 [ 业务逻辑层] ( /learn/thinking-in-graphs/#business-logic-layer ) 实施这种行为。在 GraphQL 层中放置授权逻辑是很吸引人的,如下所示:
15
+ 应当在 [ 业务逻辑层] ( /learn/thinking-in-graphs/#业务逻辑层 ) 实施这种行为。在 GraphQL 层中放置授权逻辑是很吸引人的,如下所示:
16
16
17
17
``` javascript
18
18
var postType = new GraphQLObjectType ({
@@ -32,7 +32,7 @@ var postType = new GraphQLObjectType({
32
32
});
33
33
```
34
34
35
- 可以看到我们通过检查帖子的 ` authorId ` 字段是否等于当前用户的 ` id ` 来定义“作者拥有一个帖子”。你能发现其中的问题吗?我们需要复制这段代码到服务中的每一个入口端点。一旦我们无法保证授权逻辑的完全同步,用户可能在使用不同的 API 时看到不同的数据。我们可以通过确定授权的 [ 唯一真实来源] ( /learn/thinking-in-graphs/#business-logic-layer ) 来避免这种情况。
35
+ 可以看到我们通过检查帖子的 ` authorId ` 字段是否等于当前用户的 ` id ` 来定义“作者拥有一个帖子”。你能发现其中的问题吗?我们需要复制这段代码到服务中的每一个入口端点。一旦我们无法保证授权逻辑的完全同步,用户可能在使用不同的 API 时看到不同的数据。我们可以通过确定授权的 [ 唯一真实来源] ( /learn/thinking-in-graphs/#业务逻辑层 ) 来避免这种情况。
36
36
37
37
在学习 GraphQL 或原型设计时,在解析器内定义授权逻辑是可以接受的。然而,对于生产代码库来说,还是将授权逻辑委托给业务逻辑层。这里有一个例子:
38
38
Original file line number Diff line number Diff line change 1
1
---
2
- title : Execution
2
+ title : 执行
3
3
layout : ../_core/DocsLayout
4
- category : Learn
4
+ category : 学习
5
5
permalink : /learn/execution/
6
6
next : /learn/introspection/
7
7
---
You can’t perform that action at this time.
0 commit comments