@operato/scene-graphql 0.1.3
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 +16 -0
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/graphql-client.d.ts +29 -0
- package/dist/graphql-client.js +143 -0
- package/dist/graphql-client.js.map +1 -0
- package/dist/graphql-query-and-mutation.d.ts +68 -0
- package/dist/graphql-query-and-mutation.js +197 -0
- package/dist/graphql-query-and-mutation.js.map +1 -0
- package/dist/graphql-subscription.d.ts +28 -0
- package/dist/graphql-subscription.js +90 -0
- package/dist/graphql-subscription.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/graphql-client.d.ts +17 -0
- package/dist/templates/graphql-client.js +19 -0
- package/dist/templates/graphql-client.js.map +1 -0
- package/dist/templates/graphql-mutation.d.ts +17 -0
- package/dist/templates/graphql-mutation.js +23 -0
- package/dist/templates/graphql-mutation.js.map +1 -0
- package/dist/templates/graphql-query.d.ts +17 -0
- package/dist/templates/graphql-query.js +31 -0
- package/dist/templates/graphql-query.js.map +1 -0
- package/dist/templates/graphql-subscription.d.ts +18 -0
- package/dist/templates/graphql-subscription.js +26 -0
- package/dist/templates/graphql-subscription.js.map +1 -0
- package/dist/templates/index.d.ts +48 -0
- package/dist/templates/index.js +6 -0
- package/dist/templates/index.js.map +1 -0
- package/helps/scene/component/graphql-subscription.ko.md +19 -0
- package/helps/scene/component/graphql-subscription.md +19 -0
- package/helps/scene/component/graphql-subscription.zh.md +19 -0
- package/helps/scene/component/graphql.ko.md +35 -0
- package/helps/scene/component/graphql.md +35 -0
- package/helps/scene/component/graphql.zh.md +35 -0
- package/icons/icon-graphql-client.png +0 -0
- package/icons/icon-graphql-mutation.png +0 -0
- package/icons/icon-graphql-query-input.png +0 -0
- package/icons/icon-graphql-query.png +0 -0
- package/icons/icon-graphql-subscription.png +0 -0
- package/icons/no-image.png +0 -0
- package/icons/symbol-graphql-client.png +0 -0
- package/icons/symbol-graphql-mutation.png +0 -0
- package/icons/symbol-graphql-query.png +0 -0
- package/icons/symbol-graphql-subscription.png +0 -0
- package/package.json +65 -0
- package/src/graphql-client.ts +185 -0
- package/src/graphql-query-and-mutation.ts +233 -0
- package/src/graphql-subscription.ts +110 -0
- package/src/index.ts +5 -0
- package/src/templates/graphql-client.ts +19 -0
- package/src/templates/graphql-mutation.ts +23 -0
- package/src/templates/graphql-query.ts +31 -0
- package/src/templates/graphql-subscription.ts +26 -0
- package/src/templates/index.ts +6 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +7 -0
- package/translations/ko.json +7 -0
- package/translations/zh.json +7 -0
- package/tsconfig.json +22 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ServerParseError } from '@apollo/client'
|
|
6
|
+
import {
|
|
7
|
+
ApolloClient,
|
|
8
|
+
DefaultOptions,
|
|
9
|
+
from,
|
|
10
|
+
HttpLink,
|
|
11
|
+
HttpOptions,
|
|
12
|
+
InMemoryCache,
|
|
13
|
+
NormalizedCacheObject
|
|
14
|
+
} from '@apollo/client/core'
|
|
15
|
+
import { ErrorLink, onError } from '@apollo/client/link/error'
|
|
16
|
+
import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
|
|
17
|
+
|
|
18
|
+
const defaultOptions: DefaultOptions = {
|
|
19
|
+
watchQuery: {
|
|
20
|
+
fetchPolicy: 'no-cache',
|
|
21
|
+
errorPolicy: 'ignore'
|
|
22
|
+
},
|
|
23
|
+
query: {
|
|
24
|
+
fetchPolicy: 'no-cache', //'network-only'
|
|
25
|
+
errorPolicy: 'all'
|
|
26
|
+
},
|
|
27
|
+
mutate: {
|
|
28
|
+
errorPolicy: 'all'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ERROR_HANDLER: ErrorLink.ErrorHandler = ({ operation, graphQLErrors, networkError }) => {
|
|
33
|
+
if (graphQLErrors) {
|
|
34
|
+
document.dispatchEvent(
|
|
35
|
+
new CustomEvent('notify', {
|
|
36
|
+
detail: {
|
|
37
|
+
level: 'error',
|
|
38
|
+
message: graphQLErrors[0].message,
|
|
39
|
+
ex: graphQLErrors
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (networkError) {
|
|
46
|
+
/* networkError가 ServerParseError 이거나 ServerError 인 경우에만 statusCode를 갖는다. */
|
|
47
|
+
switch ((networkError as ServerParseError).statusCode) {
|
|
48
|
+
case undefined /* in case this error is not a server side error */:
|
|
49
|
+
document.dispatchEvent(
|
|
50
|
+
new CustomEvent('notify', {
|
|
51
|
+
detail: {
|
|
52
|
+
level: 'error',
|
|
53
|
+
message: networkError.message,
|
|
54
|
+
ex: networkError
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
break
|
|
59
|
+
|
|
60
|
+
case 401:
|
|
61
|
+
/* 401 에러가 리턴되면, 인증이 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 signin 프로세스를 진행할 수 있다. */
|
|
62
|
+
document.dispatchEvent(new CustomEvent('auth-required'))
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
case 403:
|
|
66
|
+
/* 403 에러가 리턴되면, 도메인 정보가 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 domain-register 프로세스 등을 진행할 수 있다. */
|
|
67
|
+
document.dispatchEvent(new CustomEvent('domain-required'))
|
|
68
|
+
break
|
|
69
|
+
|
|
70
|
+
default:
|
|
71
|
+
var { name, response, statusCode, bodyText, message } = networkError as ServerParseError
|
|
72
|
+
if (name == 'ServerParseError') {
|
|
73
|
+
message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`
|
|
74
|
+
} else {
|
|
75
|
+
/* in case this error is instanceof ServerError */
|
|
76
|
+
message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
document.dispatchEvent(
|
|
80
|
+
new CustomEvent('notify', {
|
|
81
|
+
detail: {
|
|
82
|
+
level: 'error',
|
|
83
|
+
message,
|
|
84
|
+
ex: networkError
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const NATURE = {
|
|
93
|
+
mutable: false,
|
|
94
|
+
resizable: true,
|
|
95
|
+
rotatable: true,
|
|
96
|
+
properties: [
|
|
97
|
+
{
|
|
98
|
+
type: 'string',
|
|
99
|
+
label: 'endpoint',
|
|
100
|
+
name: 'endpoint'
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
help: 'scene/component/graphql'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default class GraphqlClient extends DataSource(RectPath(Shape)) {
|
|
107
|
+
private static _image: HTMLImageElement
|
|
108
|
+
private _client?: ApolloClient<NormalizedCacheObject>
|
|
109
|
+
|
|
110
|
+
static get image() {
|
|
111
|
+
if (!GraphqlClient._image) {
|
|
112
|
+
GraphqlClient._image = new Image()
|
|
113
|
+
GraphqlClient._image.src = new URL('../icons/symbol-graphql-client.png', import.meta.url).href
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return GraphqlClient._image
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ready() {
|
|
120
|
+
super.ready()
|
|
121
|
+
|
|
122
|
+
this.init()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
init() {
|
|
126
|
+
var { endpoint } = this.state
|
|
127
|
+
|
|
128
|
+
if (!endpoint) {
|
|
129
|
+
console.warn('endpoint not defined')
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var cache = new InMemoryCache()
|
|
134
|
+
const httpOptions: HttpOptions = {
|
|
135
|
+
uri: endpoint,
|
|
136
|
+
credentials: 'include'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const client = new ApolloClient({
|
|
140
|
+
defaultOptions,
|
|
141
|
+
cache,
|
|
142
|
+
link: from([onError(ERROR_HANDLER), new HttpLink(httpOptions)])
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
this._client = client
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get client(): ApolloClient<NormalizedCacheObject> | undefined {
|
|
149
|
+
return this._client
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
dispose() {
|
|
153
|
+
super.dispose()
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
if (this._client) {
|
|
157
|
+
this._client.stop()
|
|
158
|
+
}
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.error(e)
|
|
161
|
+
}
|
|
162
|
+
delete this._client
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
render(context: CanvasRenderingContext2D) {
|
|
166
|
+
/*
|
|
167
|
+
* TODO role이 publisher 인지 subscriber 인지에 따라서 구분할 수 있는 표시를 추가할 것.
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
var { left, top, width, height } = this.bounds
|
|
171
|
+
|
|
172
|
+
context.beginPath()
|
|
173
|
+
this.drawImage(context, GraphqlClient.image, left, top, width, height)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
onchangeData(data: any, before: any) {
|
|
177
|
+
super.onchangeData(data, before)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
get nature() {
|
|
181
|
+
return NATURE
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
Component.register('graphql-client', GraphqlClient)
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import gql from 'graphql-tag'
|
|
2
|
+
|
|
3
|
+
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'
|
|
4
|
+
import { Component, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
|
|
5
|
+
import { buildArgs } from '@operato/graphql'
|
|
6
|
+
|
|
7
|
+
import GraphqlClient from './graphql-client'
|
|
8
|
+
|
|
9
|
+
const NATURE = {
|
|
10
|
+
mutable: false,
|
|
11
|
+
resizable: true,
|
|
12
|
+
rotatable: true,
|
|
13
|
+
properties: [
|
|
14
|
+
{
|
|
15
|
+
type: 'id-input',
|
|
16
|
+
label: 'client',
|
|
17
|
+
name: 'client',
|
|
18
|
+
property: {
|
|
19
|
+
component: 'graphql-client' // component의 type (null or undefined이면 모든 컴포넌트)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'number',
|
|
24
|
+
label: 'period',
|
|
25
|
+
name: 'period',
|
|
26
|
+
placeholder: 'SECONDS'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'graphql',
|
|
30
|
+
label: 'query',
|
|
31
|
+
name: 'query'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'checkbox',
|
|
35
|
+
label: 'auto-start',
|
|
36
|
+
name: 'autoStart'
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
'value-property': 'value',
|
|
40
|
+
help: 'scene/component/graphql'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class GraphQLQuery extends DataSource(RectPath(Shape)) {
|
|
44
|
+
public client?: ApolloClient<NormalizedCacheObject>
|
|
45
|
+
|
|
46
|
+
private _repeatTimer?: NodeJS.Timeout
|
|
47
|
+
private _isStarted: boolean = false
|
|
48
|
+
|
|
49
|
+
value: any
|
|
50
|
+
|
|
51
|
+
get nature() {
|
|
52
|
+
return NATURE
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onchange(after: Properties, before: Properties) {
|
|
56
|
+
if ('value' in after) {
|
|
57
|
+
if (after.value) this.requestData()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get period() {
|
|
62
|
+
return this.state.period * 1000
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
set period(period) {
|
|
66
|
+
this.setState('period', period)
|
|
67
|
+
this._initGraphqlQuery()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get repeatTimer() {
|
|
71
|
+
return this._repeatTimer
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set repeatTimer(repeatTimer) {
|
|
75
|
+
this._stopRepeater()
|
|
76
|
+
this._repeatTimer = repeatTimer
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get autoStart() {
|
|
80
|
+
return this.state.autoStart
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
set autoStart(autoStart) {
|
|
84
|
+
this.setState('autoStart', autoStart)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get query() {
|
|
88
|
+
var _query = this.state.query
|
|
89
|
+
var objToVal = (exp: any) => {
|
|
90
|
+
if (typeof exp === 'string') return exp
|
|
91
|
+
else return JSON.stringify(exp)
|
|
92
|
+
}
|
|
93
|
+
var changedQuery: string | undefined = (Component.buildSubstitutor(_query, this, objToVal) || (() => _query))()
|
|
94
|
+
try {
|
|
95
|
+
changedQuery = changedQuery!.replace(/\(.*\)/gi, params => {
|
|
96
|
+
let paramObject = eval(`({${params.slice(1, -1)}})`)
|
|
97
|
+
return '(' + buildArgs(paramObject) + ')'
|
|
98
|
+
})
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log(e)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return changedQuery
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get source() {
|
|
107
|
+
return this.getState('source')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
set source(source) {
|
|
111
|
+
this.setState('source', source)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
dispose() {
|
|
115
|
+
super.dispose()
|
|
116
|
+
this._stopRepeater()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ready() {
|
|
120
|
+
super.ready()
|
|
121
|
+
if (this.autoStart) {
|
|
122
|
+
this._initGraphqlQuery()
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_initGraphqlQuery() {
|
|
127
|
+
if (!this.app.isViewMode) return
|
|
128
|
+
|
|
129
|
+
this._stopRepeater()
|
|
130
|
+
this._startRepeater()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
_stopRepeater() {
|
|
134
|
+
if (this.repeatTimer !== undefined) {
|
|
135
|
+
clearTimeout(this._repeatTimer!)
|
|
136
|
+
delete this._repeatTimer
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this._isStarted = false
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
_startRepeater() {
|
|
143
|
+
this._isStarted = true
|
|
144
|
+
|
|
145
|
+
// requestAnimationFrame 이 호출되지 않을 때는 requestData 호출도 하지 않도록 함.
|
|
146
|
+
var _ = () => {
|
|
147
|
+
if (!this._isStarted) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
this.requestData()
|
|
151
|
+
if (!Number.isNaN(this.period) && this.period > 0) {
|
|
152
|
+
this._repeatTimer = setTimeout(() => {
|
|
153
|
+
requestAnimationFrame(_)
|
|
154
|
+
}, this.period)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
requestAnimationFrame(_)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async requestData() {
|
|
161
|
+
if (!this.app.isViewMode) return
|
|
162
|
+
var { client } = this.state
|
|
163
|
+
var query = this.query
|
|
164
|
+
var variables = this.value
|
|
165
|
+
|
|
166
|
+
if (client && query) {
|
|
167
|
+
this.client = (this.root.findById(client) as GraphqlClient)?.client
|
|
168
|
+
var response
|
|
169
|
+
|
|
170
|
+
if (typeof variables === 'object') {
|
|
171
|
+
response = await this.client?.query({
|
|
172
|
+
query: gql`
|
|
173
|
+
${query}
|
|
174
|
+
`,
|
|
175
|
+
variables: variables
|
|
176
|
+
})
|
|
177
|
+
} else {
|
|
178
|
+
response = await this.client?.query({
|
|
179
|
+
query: gql`
|
|
180
|
+
${query}
|
|
181
|
+
`,
|
|
182
|
+
errorPolicy: 'all'
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log('response', response)
|
|
187
|
+
this.data = response
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export class Query extends GraphQLQuery {
|
|
193
|
+
private static _image: HTMLImageElement
|
|
194
|
+
|
|
195
|
+
static get image() {
|
|
196
|
+
if (!Query._image) {
|
|
197
|
+
Query._image = new Image()
|
|
198
|
+
Query._image.src = new URL('../icons/symbol-graphql-query.png', import.meta.url).href
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return Query._image
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
render(context: CanvasRenderingContext2D) {
|
|
205
|
+
var { left, top, width, height } = this.bounds
|
|
206
|
+
|
|
207
|
+
context.beginPath()
|
|
208
|
+
this.drawImage(context, Query.image, left, top, width, height)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export class Mutation extends GraphQLQuery {
|
|
213
|
+
private static _image: HTMLImageElement
|
|
214
|
+
|
|
215
|
+
static get image() {
|
|
216
|
+
if (!Mutation._image) {
|
|
217
|
+
Mutation._image = new Image()
|
|
218
|
+
Mutation._image.src = new URL('../icons/symbol-graphql-mutation.png', import.meta.url).href
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return Mutation._image
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
render(context: CanvasRenderingContext2D) {
|
|
225
|
+
var { left, top, width, height } = this.bounds
|
|
226
|
+
|
|
227
|
+
context.beginPath()
|
|
228
|
+
this.drawImage(context, Mutation.image, left, top, width, height)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
Component.register('graphql-query', Query)
|
|
233
|
+
Component.register('graphql-mutation', Mutation)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SubscriptionClient } from 'subscriptions-transport-ws'
|
|
6
|
+
|
|
7
|
+
import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
|
|
8
|
+
|
|
9
|
+
const NATURE = {
|
|
10
|
+
mutable: false,
|
|
11
|
+
resizable: true,
|
|
12
|
+
rotatable: true,
|
|
13
|
+
properties: [
|
|
14
|
+
{
|
|
15
|
+
type: 'string',
|
|
16
|
+
label: 'endpoint',
|
|
17
|
+
name: 'endpoint'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'graphql',
|
|
21
|
+
label: 'query',
|
|
22
|
+
name: 'query'
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
help: 'scene/component/graphql-subscription'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default class GraphqlSubscription extends DataSource(RectPath(Shape)) {
|
|
29
|
+
private static _image: HTMLImageElement
|
|
30
|
+
private client?: SubscriptionClient
|
|
31
|
+
private unsubscribe?: () => void
|
|
32
|
+
|
|
33
|
+
static get image() {
|
|
34
|
+
if (!GraphqlSubscription._image) {
|
|
35
|
+
GraphqlSubscription._image = new Image()
|
|
36
|
+
GraphqlSubscription._image.src = new URL('../icons/symbol-graphql-subscription.png', import.meta.url).href
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return GraphqlSubscription._image
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dispose() {
|
|
43
|
+
if (this.unsubscribe) {
|
|
44
|
+
this.unsubscribe()
|
|
45
|
+
}
|
|
46
|
+
if (this.client) {
|
|
47
|
+
this.client.unsubscribeAll()
|
|
48
|
+
this.client.close(true)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
super.dispose()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
render(context: CanvasRenderingContext2D) {
|
|
55
|
+
var { left, top, width, height } = this.bounds
|
|
56
|
+
|
|
57
|
+
context.beginPath()
|
|
58
|
+
this.drawImage(context, GraphqlSubscription.image, left, top, width, height)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ready() {
|
|
62
|
+
this._initGraphqlSubscription()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get nature() {
|
|
66
|
+
return NATURE
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_initGraphqlSubscription() {
|
|
70
|
+
if (!this.app.isViewMode) return
|
|
71
|
+
|
|
72
|
+
this.requestData()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async requestData() {
|
|
76
|
+
var { endpoint, query } = this.state
|
|
77
|
+
var self = this
|
|
78
|
+
|
|
79
|
+
this.client = new SubscriptionClient(endpoint, {
|
|
80
|
+
reconnect: true,
|
|
81
|
+
connectionParams: {
|
|
82
|
+
headers: {
|
|
83
|
+
/*
|
|
84
|
+
특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.
|
|
85
|
+
referer: location.href
|
|
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 }) {
|
|
99
|
+
if (data) {
|
|
100
|
+
self.data = data
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
this.unsubscribe = unsubscribe
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
Component.register('graphql-subscription', GraphqlSubscription)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const icon = new URL('../../icons/icon-graphql-client.png', import.meta.url).href
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'graphql-client',
|
|
5
|
+
description: 'graphql-client',
|
|
6
|
+
group: 'dataSource',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'graphql-client',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
fillStyle: 'cyan',
|
|
16
|
+
strokeStyle: 'darkgray',
|
|
17
|
+
endpoint: '/'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const icon = new URL('../../icons/icon-graphql-mutation.png', import.meta.url).href
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'graphql-mutation',
|
|
5
|
+
description: 'graphql-mutation',
|
|
6
|
+
group: 'dataSource',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'graphql-mutation',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
autoStart: false,
|
|
16
|
+
period: 0,
|
|
17
|
+
query: `mutation {
|
|
18
|
+
resolverName ( patches:[] ) {
|
|
19
|
+
id
|
|
20
|
+
}
|
|
21
|
+
}`
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const icon = new URL('../../icons/icon-graphql-query.png', import.meta.url).href
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'graphql-query',
|
|
5
|
+
description: 'graphql-query',
|
|
6
|
+
group: 'dataSource',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'graphql-query',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
autoStart: true,
|
|
16
|
+
period: 0,
|
|
17
|
+
query: `query {
|
|
18
|
+
boards {
|
|
19
|
+
items {
|
|
20
|
+
id
|
|
21
|
+
name
|
|
22
|
+
description
|
|
23
|
+
thumbnail
|
|
24
|
+
createdAt
|
|
25
|
+
updatedAt
|
|
26
|
+
}
|
|
27
|
+
total
|
|
28
|
+
}
|
|
29
|
+
}`
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const icon = new URL('../../icons/icon-graphql-subscription.png', import.meta.url).href
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: 'graphql-subscription',
|
|
5
|
+
description: 'graphql-subscription',
|
|
6
|
+
group: 'dataSource',
|
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
|
8
|
+
icon,
|
|
9
|
+
model: {
|
|
10
|
+
type: 'graphql-subscription',
|
|
11
|
+
left: 10,
|
|
12
|
+
top: 10,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
lineWidth: 1,
|
|
16
|
+
endpoint: 'ws://localhost:3000/subscriptions',
|
|
17
|
+
requestType: 'mutation',
|
|
18
|
+
query: `subscription {
|
|
19
|
+
systemRebooted {
|
|
20
|
+
name
|
|
21
|
+
version
|
|
22
|
+
description
|
|
23
|
+
}
|
|
24
|
+
}`
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import graphqlClient from './graphql-client'
|
|
2
|
+
import graphqlMutation from './graphql-mutation'
|
|
3
|
+
import graphqlQuery from './graphql-query'
|
|
4
|
+
import graphqlSubscription from './graphql-subscription'
|
|
5
|
+
|
|
6
|
+
export default [graphqlClient, graphqlQuery, graphqlMutation, graphqlSubscription]
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"noEmitOnError": true,
|
|
7
|
+
"lib": ["es2017", "dom"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"importHelpers": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"inlineSources": true,
|
|
16
|
+
"rootDir": "src",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"incremental": true,
|
|
19
|
+
"types": ["node"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["**/*.ts", "*.d.ts"]
|
|
22
|
+
}
|