@operato/scene-graphql 1.0.0-alpha.9 → 1.0.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/CHANGELOG.md +270 -9
- package/assets/favicon.ico +0 -0
- package/assets/images/spinner.png +0 -0
- package/dist/graphql-client.js.map +1 -1
- package/dist/graphql-query-and-mutation.d.ts +0 -2
- package/dist/graphql-query-and-mutation.js +9 -8
- package/dist/graphql-query-and-mutation.js.map +1 -1
- package/dist/graphql-subscription.d.ts +0 -2
- package/dist/graphql-subscription.js +17 -36
- package/dist/graphql-subscription.js.map +1 -1
- package/helps/scene/component/graphql.ko.md +19 -1
- package/helps/scene/component/graphql.md +19 -1
- package/helps/scene/component/graphql.zh.md +28 -10
- package/package.json +8 -10
- package/src/graphql-client.ts +2 -2
- package/src/graphql-query-and-mutation.ts +8 -7
- package/src/graphql-subscription.ts +22 -40
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -20,7 +20,7 @@ Graphql API를 사용할 수 있는 데이타소스 컴포넌트 패미리이다
|
|
|
20
20
|
## properties for graphql-query/mutation
|
|
21
21
|
|
|
22
22
|
- client component ID
|
|
23
|
-
- endpoint가 설정된 graphql-client의 ID를 설정한다.
|
|
23
|
+
- endpoint가 설정된 graphql-client의 ID를 설정한다. 비워두면 origin 서버의 graphql 클라이언트가 사용된다.
|
|
24
24
|
- period
|
|
25
25
|
- 주기적인 query/mutation 호출이 필요한 경우에 그 주기를 second 단위로 설정한다.
|
|
26
26
|
- query
|
|
@@ -32,4 +32,22 @@ Graphql API를 사용할 수 있는 데이타소스 컴포넌트 패미리이다
|
|
|
32
32
|
|
|
33
33
|
- query/mutation 결과는 바로 이 컴포넌트의 data속성이 되므로, 그 결과를 데이터바인딩에 적용할 수 있다.
|
|
34
34
|
- 데이타의 형태는 query에 의해서 결정된다.
|
|
35
|
+
- 예를 들어 쿼리가 다음과 같다면, items 를 접근하기 위한 접근자(accessor)는 'data.boards.items' 가 된다.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
query {
|
|
39
|
+
boards {
|
|
40
|
+
items {
|
|
41
|
+
id
|
|
42
|
+
name
|
|
43
|
+
description
|
|
44
|
+
thumbnail
|
|
45
|
+
createdAt
|
|
46
|
+
updatedAt
|
|
47
|
+
}
|
|
48
|
+
total
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
35
53
|
- 실제 데이터의 형태는 크롬 브라우저의 개발자 도구의 'Network' - 'XHR'에서 확인할 수 있다.
|
|
@@ -20,7 +20,7 @@ It is a family of data source components that can use Graphql API.
|
|
|
20
20
|
## properties for graphql-query/mutation
|
|
21
21
|
|
|
22
22
|
- client component ID
|
|
23
|
-
- Set the ID of the graphql-client where the endpoint is configured.
|
|
23
|
+
- Set the ID of the graphql-client where the endpoint is configured. If not set, the graphql client for the origin server is used.
|
|
24
24
|
- period
|
|
25
25
|
- When periodic query/mutation call is needed, set the period in second unit.
|
|
26
26
|
- query
|
|
@@ -32,4 +32,22 @@ It is a family of data source components that can use Graphql API.
|
|
|
32
32
|
|
|
33
33
|
- Since the query/mutation result becomes the data property of this component, the result can be applied to data binding.
|
|
34
34
|
- The type of data is determined by query.
|
|
35
|
+
- For example, if the query is as follows, the accessor to access items is 'data.boards.items'
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
query {
|
|
39
|
+
boards {
|
|
40
|
+
items {
|
|
41
|
+
id
|
|
42
|
+
name
|
|
43
|
+
description
|
|
44
|
+
thumbnail
|
|
45
|
+
createdAt
|
|
46
|
+
updatedAt
|
|
47
|
+
}
|
|
48
|
+
total
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
35
53
|
- The actual data format can be checked in'Network'-'XHR' of the developer tools of the Chrome browser.
|
|
@@ -1,35 +1,53 @@
|
|
|
1
1
|
# graphql
|
|
2
2
|
|
|
3
|
-
它是可以使用Graphql API的一系列数据源组件。
|
|
3
|
+
它是可以使用 Graphql API 的一系列数据源组件。
|
|
4
4
|
|
|
5
5
|
- graphql-client
|
|
6
|
-
- Graphql组件这是连接要在系列中使用的服务器的组件。
|
|
6
|
+
- Graphql 组件这是连接要在系列中使用的服务器的组件。
|
|
7
7
|
- graphql-query
|
|
8
8
|
- graphql-mutation
|
|
9
9
|
|
|
10
10
|
## properties for graphql-client
|
|
11
11
|
|
|
12
12
|
- endpoint
|
|
13
|
-
- 输入提供Graphql服务的服务器的连接信息。
|
|
14
|
-
- 在graphql-client组件中配置。
|
|
13
|
+
- 输入提供 Graphql 服务的服务器的连接信息。
|
|
14
|
+
- 在 graphql-client 组件中配置。
|
|
15
15
|
- 当前,尚无用于服务器身份验证的功能,因此它用于不需要身份验证或已通过身份验证的服务(原始服务器等)。
|
|
16
16
|
- '/graphql'
|
|
17
17
|
- 'http://localhost:3000/graphql'
|
|
18
|
-
- 该组件用于在graphql-query或graphql-mutation组件的客户端组件ID属性中进行设置。
|
|
18
|
+
- 该组件用于在 graphql-query 或 graphql-mutation 组件的客户端组件 ID 属性中进行设置。
|
|
19
19
|
|
|
20
20
|
## properties for graphql-query/mutation
|
|
21
21
|
|
|
22
22
|
- client component ID
|
|
23
|
-
- 设置配置端点的graphql-client的ID
|
|
23
|
+
- 设置配置端点的 graphql-client 的 ID。如果未设置,则使用源服务器的 graphql 客户端。
|
|
24
24
|
- period
|
|
25
|
-
- 需要定期执行query/mutation时,请以秒为单位设置周期。
|
|
25
|
+
- 需要定期执行 query/mutation 时,请以秒为单位设置周期。
|
|
26
26
|
- query
|
|
27
|
-
- 设置要调用的graphql查询。
|
|
27
|
+
- 设置要调用的 graphql 查询。
|
|
28
28
|
- auto start
|
|
29
29
|
- 看板启动时是否自动调用。
|
|
30
30
|
|
|
31
|
-
## 在Chrome浏览器中确认收到数据
|
|
31
|
+
## 在 Chrome 浏览器中确认收到数据
|
|
32
32
|
|
|
33
33
|
- 由于`query/mutation`结果成为该组件的数据属性,因此该结果可以应用于数据绑定。
|
|
34
34
|
- 数据类型由查询确定。
|
|
35
|
-
-
|
|
35
|
+
- 比如查询如下,访问 items 的 accessor 是'data.boards.items'
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
query {
|
|
39
|
+
boards {
|
|
40
|
+
items {
|
|
41
|
+
id
|
|
42
|
+
name
|
|
43
|
+
description
|
|
44
|
+
thumbnail
|
|
45
|
+
createdAt
|
|
46
|
+
updatedAt
|
|
47
|
+
}
|
|
48
|
+
total
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- 实际数据形态可以在 Chrome 浏览器的开发人员工具的“network”-“ XHR”中查看。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/scene-graphql",
|
|
3
3
|
"description": "Graphql datasource component for things-scene",
|
|
4
|
-
"version": "1.0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -26,23 +26,21 @@
|
|
|
26
26
|
"migration": "things-factory-migration"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@apollo/client": "^3.
|
|
30
|
-
"@hatiolab/things-scene": "^
|
|
31
|
-
"@operato/graphql": "^1.0.0
|
|
32
|
-
"jsonwebtoken": "^8.5.1",
|
|
33
|
-
"subscriptions-transport-ws": "^0.11.0"
|
|
29
|
+
"@apollo/client": "^3.6.9",
|
|
30
|
+
"@hatiolab/things-scene": "^3.0.19",
|
|
31
|
+
"@operato/graphql": "^1.0.0"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
34
|
"@hatiolab/prettier-config": "^1.0.0",
|
|
37
|
-
"@
|
|
38
|
-
"@things-factory/
|
|
39
|
-
"@things-factory/operato-board": "^5.0.0-alpha.28",
|
|
35
|
+
"@things-factory/builder": "^5.0.0-zeta.28",
|
|
36
|
+
"@things-factory/operato-board": "^5.0.0-zeta.28",
|
|
40
37
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
41
38
|
"@typescript-eslint/parser": "^4.33.0",
|
|
42
39
|
"@web/dev-server": "^0.1.28",
|
|
43
40
|
"concurrently": "^5.3.0",
|
|
44
41
|
"eslint": "^7.32.0",
|
|
45
42
|
"eslint-config-prettier": "^8.3.0",
|
|
43
|
+
"graphql-tag": "^2.12.6",
|
|
46
44
|
"husky": "^4.3.8",
|
|
47
45
|
"lint-staged": "^10.5.4",
|
|
48
46
|
"prettier": "^2.4.1",
|
|
@@ -61,5 +59,5 @@
|
|
|
61
59
|
"prettier --write"
|
|
62
60
|
]
|
|
63
61
|
},
|
|
64
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "41d54d5fd010844be20b670f46119e4c06d6850e"
|
|
65
63
|
}
|
package/src/graphql-client.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { ServerParseError } from '@apollo/client'
|
|
6
5
|
import {
|
|
7
6
|
ApolloClient,
|
|
8
7
|
DefaultOptions,
|
|
@@ -10,7 +9,8 @@ import {
|
|
|
10
9
|
HttpLink,
|
|
11
10
|
HttpOptions,
|
|
12
11
|
InMemoryCache,
|
|
13
|
-
NormalizedCacheObject
|
|
12
|
+
NormalizedCacheObject,
|
|
13
|
+
ServerParseError
|
|
14
14
|
} from '@apollo/client/core'
|
|
15
15
|
import { ErrorLink, onError } from '@apollo/client/link/error'
|
|
16
16
|
import { Component, ComponentNature, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
|
|
@@ -2,7 +2,7 @@ import gql from 'graphql-tag'
|
|
|
2
2
|
|
|
3
3
|
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'
|
|
4
4
|
import { Component, ComponentNature, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
|
|
5
|
-
import { buildArgs } from '@operato/graphql'
|
|
5
|
+
import { buildArgs, client as localClient } from '@operato/graphql'
|
|
6
6
|
|
|
7
7
|
import GraphqlClient from './graphql-client'
|
|
8
8
|
|
|
@@ -15,6 +15,7 @@ const NATURE: ComponentNature = {
|
|
|
15
15
|
type: 'id-input',
|
|
16
16
|
label: 'client',
|
|
17
17
|
name: 'client',
|
|
18
|
+
placeholder: 'leave blank to use origin server',
|
|
18
19
|
property: {
|
|
19
20
|
component: 'graphql-client' // component의 type (null or undefined이면 모든 컴포넌트)
|
|
20
21
|
}
|
|
@@ -41,8 +42,6 @@ const NATURE: ComponentNature = {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
class GraphQLQuery extends DataSource(RectPath(Shape)) {
|
|
44
|
-
public client?: ApolloClient<NormalizedCacheObject>
|
|
45
|
-
|
|
46
45
|
private _repeatTimer?: NodeJS.Timeout
|
|
47
46
|
private _isStarted: boolean = false
|
|
48
47
|
|
|
@@ -163,19 +162,21 @@ class GraphQLQuery extends DataSource(RectPath(Shape)) {
|
|
|
163
162
|
var query = this.query
|
|
164
163
|
var variables = this.value
|
|
165
164
|
|
|
166
|
-
if (
|
|
167
|
-
|
|
165
|
+
if (query) {
|
|
166
|
+
const graphqlClient: ApolloClient<NormalizedCacheObject> =
|
|
167
|
+
(client && (this.root.findById(client) as GraphqlClient)?.client) || localClient
|
|
168
|
+
|
|
168
169
|
var response
|
|
169
170
|
|
|
170
171
|
if (typeof variables === 'object') {
|
|
171
|
-
response = await
|
|
172
|
+
response = await graphqlClient.query({
|
|
172
173
|
query: gql`
|
|
173
174
|
${query}
|
|
174
175
|
`,
|
|
175
176
|
variables: variables
|
|
176
177
|
})
|
|
177
178
|
} else {
|
|
178
|
-
response = await
|
|
179
|
+
response = await graphqlClient.query({
|
|
179
180
|
query: gql`
|
|
180
181
|
${query}
|
|
181
182
|
`,
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { gql } from 'graphql-tag'
|
|
6
6
|
|
|
7
7
|
import { Component, ComponentNature, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
|
|
8
|
+
import { subscribe } from '@operato/graphql'
|
|
8
9
|
|
|
9
10
|
const NATURE: ComponentNature = {
|
|
10
11
|
mutable: false,
|
|
@@ -12,6 +13,7 @@ const NATURE: ComponentNature = {
|
|
|
12
13
|
rotatable: true,
|
|
13
14
|
properties: [
|
|
14
15
|
{
|
|
16
|
+
/* origin의 subscription 만을 허용하므로, 엔드포인트 속성은 무시한다. */
|
|
15
17
|
type: 'string',
|
|
16
18
|
label: 'endpoint',
|
|
17
19
|
name: 'endpoint'
|
|
@@ -27,7 +29,6 @@ const NATURE: ComponentNature = {
|
|
|
27
29
|
|
|
28
30
|
export default class GraphqlSubscription extends DataSource(RectPath(Shape)) {
|
|
29
31
|
private static _image: HTMLImageElement
|
|
30
|
-
private client?: SubscriptionClient
|
|
31
32
|
private unsubscribe?: () => void
|
|
32
33
|
|
|
33
34
|
static get image() {
|
|
@@ -43,10 +44,6 @@ export default class GraphqlSubscription extends DataSource(RectPath(Shape)) {
|
|
|
43
44
|
if (this.unsubscribe) {
|
|
44
45
|
this.unsubscribe()
|
|
45
46
|
}
|
|
46
|
-
if (this.client) {
|
|
47
|
-
this.client.unsubscribeAll()
|
|
48
|
-
this.client.close(true)
|
|
49
|
-
}
|
|
50
47
|
|
|
51
48
|
super.dispose()
|
|
52
49
|
}
|
|
@@ -59,51 +56,36 @@ export default class GraphqlSubscription extends DataSource(RectPath(Shape)) {
|
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
ready() {
|
|
62
|
-
|
|
59
|
+
super.ready()
|
|
60
|
+
|
|
61
|
+
if (this.app.isViewMode) {
|
|
62
|
+
this.requestData()
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
get nature() {
|
|
66
67
|
return NATURE
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
_initGraphqlSubscription() {
|
|
70
|
-
if (!this.app.isViewMode) return
|
|
71
|
-
|
|
72
|
-
this.requestData()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
70
|
async requestData() {
|
|
76
|
-
var {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
또는, 이미 서브도메인 정보를 알고 있다면,
|
|
87
|
-
'x-things-factory-domain': '[subdomain]'
|
|
88
|
-
을 보낼 수 있다.
|
|
89
|
-
관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.
|
|
90
|
-
*/
|
|
91
|
-
referer: location.href
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
this.client.onConnected(() => {
|
|
97
|
-
const { unsubscribe } = this.client!.request({ query }).subscribe({
|
|
98
|
-
next({ data }) {
|
|
71
|
+
var { query } = this.state
|
|
72
|
+
|
|
73
|
+
const { unsubscribe } = await subscribe(
|
|
74
|
+
{
|
|
75
|
+
query: gql`
|
|
76
|
+
${query}
|
|
77
|
+
`
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
next: ({ data }: { data: any }) => {
|
|
99
81
|
if (data) {
|
|
100
|
-
|
|
82
|
+
this.data = data
|
|
101
83
|
}
|
|
102
84
|
}
|
|
103
|
-
}
|
|
85
|
+
}
|
|
86
|
+
)
|
|
104
87
|
|
|
105
|
-
|
|
106
|
-
})
|
|
88
|
+
this.unsubscribe = unsubscribe
|
|
107
89
|
}
|
|
108
90
|
}
|
|
109
91
|
|