@operato/graphql 1.12.9 → 2.0.0-alpha.107
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/.storybook/main.js +2 -2
- package/.storybook/server.mjs +4 -4
- package/CHANGELOG.md +62 -0
- package/dist/src/active-request-counter-link.d.ts +1 -0
- package/dist/src/active-request-counter-link.js +3 -0
- package/dist/src/active-request-counter-link.js.map +1 -1
- package/dist/src/graphql-client.js +83 -86
- package/dist/src/graphql-client.js.map +1 -1
- package/dist/src/graphql-env.d.ts +6 -0
- package/dist/src/graphql-env.js +112 -0
- package/dist/src/graphql-env.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/use-query.d.ts +5 -0
- package/dist/src/use-query.js +29 -0
- package/dist/src/use-query.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -19
- package/src/active-request-counter-link.ts +4 -0
- package/src/graphql-client.ts +94 -120
- package/src/graphql-env.ts +145 -0
- package/src/index.ts +2 -2
- package/src/use-query.ts +34 -0
package/.storybook/main.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module.exports = {
|
2
|
-
stories: ['../dist/stories/**/*.stories.{js,md,mdx}']
|
3
|
-
}
|
2
|
+
stories: ['../dist/stories/**/*.stories.{js,md,mdx}']
|
3
|
+
}
|
package/.storybook/server.mjs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { storybookPlugin } from '@web/dev-server-storybook'
|
2
|
-
import baseConfig from '../web-dev-server.config.mjs'
|
1
|
+
import { storybookPlugin } from '@web/dev-server-storybook'
|
2
|
+
import baseConfig from '../web-dev-server.config.mjs'
|
3
3
|
|
4
4
|
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
5
5
|
...baseConfig,
|
6
6
|
open: '/',
|
7
|
-
plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins]
|
8
|
-
})
|
7
|
+
plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins]
|
8
|
+
})
|
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,68 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [2.0.0-alpha.107](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.106...v2.0.0-alpha.107) (2024-05-01)
|
7
|
+
|
8
|
+
|
9
|
+
### :bug: Bug Fix
|
10
|
+
|
11
|
+
* add useQuery hook into @operato/graphql ([a0b5f19](https://github.com/hatiolab/operato/commit/a0b5f19b31dacd7fcf1dc5335a4211c037568183))
|
12
|
+
* consider graphql link for mocking ([8eb3687](https://github.com/hatiolab/operato/commit/8eb36875876244b9d15809f88fa6600589b132ef))
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
## [2.0.0-alpha.57](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.56...v2.0.0-alpha.57) (2024-04-07)
|
17
|
+
|
18
|
+
**Note:** Version bump only for package @operato/graphql
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## [2.0.0-alpha.51](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.50...v2.0.0-alpha.51) (2024-03-29)
|
25
|
+
|
26
|
+
|
27
|
+
### :bug: Bug Fix
|
28
|
+
|
29
|
+
* upgrade lit ([e661c33](https://github.com/hatiolab/operato/commit/e661c333d2bb97f784b5ac2c0e365714ee5e80ff))
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
## [2.0.0-alpha.47](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.46...v2.0.0-alpha.47) (2024-03-27)
|
34
|
+
|
35
|
+
|
36
|
+
### :bug: Bug Fix
|
37
|
+
|
38
|
+
* storybook 실행 환경 ([6a2940f](https://github.com/hatiolab/operato/commit/6a2940fb89dc26566acdce7cf1781a71cbad61c5))
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
## [2.0.0-alpha.43](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.42...v2.0.0-alpha.43) (2024-03-24)
|
43
|
+
|
44
|
+
|
45
|
+
### :rocket: New Features
|
46
|
+
|
47
|
+
* 모듈의 동적 라우팅 구성을 지원함 ([3b812a4](https://github.com/hatiolab/operato/commit/3b812a460e81b3ce7c8da8900a6378aff1484444))
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
## [2.0.0-alpha.28](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.27...v2.0.0-alpha.28) (2024-02-20)
|
52
|
+
|
53
|
+
|
54
|
+
### :bug: Bug Fix
|
55
|
+
|
56
|
+
* upgrade devDependencies for webcomponents ([1489b8b](https://github.com/hatiolab/operato/commit/1489b8b790d9bcee779a070a630697f25c01728f))
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## [2.0.0-alpha.0](https://github.com/hatiolab/operato/compare/v1.13.1...v2.0.0-alpha.0) (2024-01-05)
|
61
|
+
|
62
|
+
**Note:** Version bump only for package @operato/graphql
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
6
68
|
### [1.12.9](https://github.com/hatiolab/operato/compare/v1.12.8...v1.12.9) (2024-01-04)
|
7
69
|
|
8
70
|
|
@@ -3,3 +3,4 @@ export declare const activeRequestCounterLink: ApolloLink;
|
|
3
3
|
export declare function setActiveRequestCounterCallback(newCallback: (activeRequestCount: number) => void): void;
|
4
4
|
export declare function resetActiveRequestCounterCallback(): void;
|
5
5
|
export declare function decreaseActiveRequestCounter(): void;
|
6
|
+
export declare function increaseActiveRequestCounter(): void;
|
@@ -17,4 +17,7 @@ export function resetActiveRequestCounterCallback() {
|
|
17
17
|
export function decreaseActiveRequestCounter() {
|
18
18
|
callback && callback(--activeRequests);
|
19
19
|
}
|
20
|
+
export function increaseActiveRequestCounter() {
|
21
|
+
callback && callback(++activeRequests);
|
22
|
+
}
|
20
23
|
//# sourceMappingURL=active-request-counter-link.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"active-request-counter-link.js","sourceRoot":"","sources":["../../src/active-request-counter-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,IAAI,cAAc,GAAG,CAAC,CAAA;AAEtB,IAAI,QAAQ,GAAkD,IAAI,CAAA;AAElE,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,UAAU,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;IAEtC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QACvC,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;QAEtC,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,UAAU,+BAA+B,CAAC,WAAiD;IAC/F,QAAQ,GAAG,WAAW,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,iCAAiC;IAC/C,QAAQ,GAAG,IAAI,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;AACxC,CAAC","sourcesContent":["import { ApolloLink } from '@apollo/client/core'\n\nvar activeRequests = 0\n\nvar callback: ((activeRequestCount: number) => void) | null = null\n\nexport const activeRequestCounterLink = new ApolloLink((operation, forward) => {\n callback && callback(++activeRequests)\n\n return forward(operation).map(response => {\n callback && callback(--activeRequests)\n\n return response\n })\n})\n\nexport function setActiveRequestCounterCallback(newCallback: (activeRequestCount: number) => void) {\n callback = newCallback\n}\n\nexport function resetActiveRequestCounterCallback() {\n callback = null\n}\n\nexport function decreaseActiveRequestCounter() {\n callback && callback(--activeRequests)\n}\n"]}
|
1
|
+
{"version":3,"file":"active-request-counter-link.js","sourceRoot":"","sources":["../../src/active-request-counter-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,IAAI,cAAc,GAAG,CAAC,CAAA;AAEtB,IAAI,QAAQ,GAAkD,IAAI,CAAA;AAElE,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,UAAU,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;IAEtC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QACvC,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;QAEtC,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,UAAU,+BAA+B,CAAC,WAAiD;IAC/F,QAAQ,GAAG,WAAW,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,iCAAiC;IAC/C,QAAQ,GAAG,IAAI,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,QAAQ,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;AACxC,CAAC","sourcesContent":["import { ApolloLink } from '@apollo/client/core'\n\nvar activeRequests = 0\n\nvar callback: ((activeRequestCount: number) => void) | null = null\n\nexport const activeRequestCounterLink = new ApolloLink((operation, forward) => {\n callback && callback(++activeRequests)\n\n return forward(operation).map(response => {\n callback && callback(--activeRequests)\n\n return response\n })\n})\n\nexport function setActiveRequestCounterCallback(newCallback: (activeRequestCount: number) => void) {\n callback = newCallback\n}\n\nexport function resetActiveRequestCounterCallback() {\n callback = null\n}\n\nexport function decreaseActiveRequestCounter() {\n callback && callback(--activeRequests)\n}\n\nexport function increaseActiveRequestCounter() {\n callback && callback(++activeRequests)\n}\n"]}
|
@@ -1,10 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { ApolloClient, ApolloLink, from, HttpLink, InMemoryCache, split } from '@apollo/client/core';
|
4
|
-
import { onError } from '@apollo/client/link/error';
|
5
|
-
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
|
6
|
-
import { getMainDefinition } from '@apollo/client/utilities';
|
7
|
-
import { activeRequestCounterLink, decreaseActiveRequestCounter } from './active-request-counter-link';
|
1
|
+
import { ApolloClient, InMemoryCache } from '@apollo/client/core';
|
2
|
+
import { getClientLink } from './graphql-env';
|
8
3
|
export const GRAPHQL_URI = '/graphql';
|
9
4
|
export const SUBSCRIPTION_URI = GRAPHQL_URI;
|
10
5
|
const defaultOptions = {
|
@@ -20,66 +15,65 @@ const defaultOptions = {
|
|
20
15
|
errorPolicy: 'all'
|
21
16
|
}
|
22
17
|
};
|
23
|
-
const ERROR_HANDLER = ({ operation, graphQLErrors, networkError }) => {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
18
|
+
// const ERROR_HANDLER: ErrorLink.ErrorHandler = ({ operation, graphQLErrors, networkError }) => {
|
19
|
+
// if (graphQLErrors) {
|
20
|
+
// document.dispatchEvent(
|
21
|
+
// new CustomEvent('notify', {
|
22
|
+
// detail: {
|
23
|
+
// level: 'error',
|
24
|
+
// message: graphQLErrors[0].message,
|
25
|
+
// ex: graphQLErrors
|
26
|
+
// }
|
27
|
+
// })
|
28
|
+
// )
|
29
|
+
// }
|
30
|
+
// if (networkError) {
|
31
|
+
// decreaseActiveRequestCounter()
|
32
|
+
// /* networkError가 ServerParseError 이거나 ServerError 인 경우에만 statusCode를 갖는다. */
|
33
|
+
// switch ((networkError as ServerParseError).statusCode) {
|
34
|
+
// case undefined /* in case this error is not a server side error */:
|
35
|
+
// document.dispatchEvent(
|
36
|
+
// new CustomEvent('notify', {
|
37
|
+
// detail: {
|
38
|
+
// level: 'error',
|
39
|
+
// message: networkError.message,
|
40
|
+
// ex: networkError
|
41
|
+
// }
|
42
|
+
// })
|
43
|
+
// )
|
44
|
+
// break
|
45
|
+
// case 401:
|
46
|
+
// /* 401 에러가 리턴되면, 인증이 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 signin 프로세스를 진행할 수 있다. */
|
47
|
+
// document.dispatchEvent(new CustomEvent('auth-required'))
|
48
|
+
// break
|
49
|
+
// case 403:
|
50
|
+
// /* 403 에러가 리턴되면, 도메인 정보가 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 domain-register 프로세스 등을 진행할 수 있다. */
|
51
|
+
// document.dispatchEvent(new CustomEvent('domain-required'))
|
52
|
+
// break
|
53
|
+
// default:
|
54
|
+
// var { name, response, statusCode, bodyText, message } = networkError as ServerParseError
|
55
|
+
// if (name == 'ServerParseError') {
|
56
|
+
// message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`
|
57
|
+
// } else {
|
58
|
+
// /* in case this error is instanceof ServerError */
|
59
|
+
// message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`
|
60
|
+
// }
|
61
|
+
// document.dispatchEvent(
|
62
|
+
// new CustomEvent('notify', {
|
63
|
+
// detail: {
|
64
|
+
// level: 'error',
|
65
|
+
// message,
|
66
|
+
// ex: networkError
|
67
|
+
// }
|
68
|
+
// })
|
69
|
+
// )
|
70
|
+
// }
|
71
|
+
// }
|
72
|
+
// }
|
73
73
|
const cache = new InMemoryCache({
|
74
74
|
addTypename: false
|
75
75
|
// dataIdFromObject: object => object.key
|
76
76
|
});
|
77
|
-
const httpOptions = {
|
78
|
-
uri: GRAPHQL_URI,
|
79
|
-
credentials: 'include',
|
80
|
-
headers: { 'Apollo-Require-Preflight': 'true' }
|
81
|
-
};
|
82
|
-
const httpLink = ApolloLink.split(operation => operation.getContext().hasUpload, createUploadLink(httpOptions), new HttpLink(httpOptions));
|
83
77
|
// const initPersistCache = async () => {
|
84
78
|
// persistCache({
|
85
79
|
// cache,
|
@@ -87,32 +81,35 @@ const httpLink = ApolloLink.split(operation => operation.getContext().hasUpload,
|
|
87
81
|
// })
|
88
82
|
// }
|
89
83
|
// initPersistCache()
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
})
|
84
|
+
// var mockedResponses: any = {}
|
85
|
+
// const createMockLink = () =>
|
86
|
+
// new ApolloLink((operation, forward) => {
|
87
|
+
// return new Observable(observer => {
|
88
|
+
// const operationName = operation.operationName
|
89
|
+
// if (mockedResponses[operationName]) {
|
90
|
+
// observer.next({
|
91
|
+
// data: mockedResponses[operationName]
|
92
|
+
// })
|
93
|
+
// } else {
|
94
|
+
// observer.error(new Error(`No mock response for operation ${operationName}`))
|
95
|
+
// }
|
96
|
+
// observer.complete()
|
97
|
+
// })
|
98
|
+
// })
|
99
|
+
// const link = process.env.STORYBOOK_ENV
|
100
|
+
// ? createMockLink()
|
101
|
+
// : split(
|
102
|
+
// ({ query }) => {
|
103
|
+
// const def = getMainDefinition(query)
|
104
|
+
// return def.kind === 'OperationDefinition' && def.operation === 'subscription'
|
105
|
+
// },
|
106
|
+
// wsLink,
|
107
|
+
// from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink])
|
108
|
+
// )
|
109
109
|
export const client = new ApolloClient({
|
110
110
|
defaultOptions,
|
111
111
|
cache,
|
112
|
-
link:
|
113
|
-
const def = getMainDefinition(query);
|
114
|
-
return def.kind === 'OperationDefinition' && def.operation === 'subscription';
|
115
|
-
}, wsLink, from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink]))
|
112
|
+
link: getClientLink()
|
116
113
|
});
|
117
114
|
export const subscribe = async (request, subscribe) => {
|
118
115
|
return client.subscribe(request).subscribe(subscribe);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"graphql-client.js","sourceRoot":"","sources":["../../src/graphql-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"graphql-client.js","sourceRoot":"","sources":["../../src/graphql-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkB,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEjF,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAA;AAE3C,MAAM,cAAc,GAAmB;IACrC,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU,EAAE,gBAAgB;QACzC,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,kGAAkG;AAClG,yBAAyB;AACzB,8BAA8B;AAC9B,oCAAoC;AACpC,oBAAoB;AACpB,4BAA4B;AAC5B,+CAA+C;AAC/C,8BAA8B;AAC9B,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,IAAI,YAAY,CAAC;IACrC,cAAc;IACd,KAAK;IACL,IAAI,EAAE,aAAa,EAAE;CACtB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,OAAY,EAAE,SAAc,EAAE,EAAE;IAC9D,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACvD,CAAC,CAAA","sourcesContent":["import { ApolloClient, DefaultOptions, InMemoryCache } from '@apollo/client/core'\n\nimport { getClientLink } from './graphql-env'\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\nconst defaultOptions: DefaultOptions = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\n// const ERROR_HANDLER: ErrorLink.ErrorHandler = ({ operation, graphQLErrors, networkError }) => {\n// if (graphQLErrors) {\n// document.dispatchEvent(\n// new CustomEvent('notify', {\n// detail: {\n// level: 'error',\n// message: graphQLErrors[0].message,\n// ex: graphQLErrors\n// }\n// })\n// )\n// }\n\n// if (networkError) {\n// decreaseActiveRequestCounter()\n\n// /* networkError가 ServerParseError 이거나 ServerError 인 경우에만 statusCode를 갖는다. */\n// switch ((networkError as ServerParseError).statusCode) {\n// case undefined /* in case this error is not a server side error */:\n// document.dispatchEvent(\n// new CustomEvent('notify', {\n// detail: {\n// level: 'error',\n// message: networkError.message,\n// ex: networkError\n// }\n// })\n// )\n// break\n\n// case 401:\n// /* 401 에러가 리턴되면, 인증이 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 signin 프로세스를 진행할 수 있다. */\n// document.dispatchEvent(new CustomEvent('auth-required'))\n// break\n\n// case 403:\n// /* 403 에러가 리턴되면, 도메인 정보가 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 domain-register 프로세스 등을 진행할 수 있다. */\n// document.dispatchEvent(new CustomEvent('domain-required'))\n// break\n\n// default:\n// var { name, response, statusCode, bodyText, message } = networkError as ServerParseError\n// if (name == 'ServerParseError') {\n// message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`\n// } else {\n// /* in case this error is instanceof ServerError */\n// message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`\n// }\n\n// document.dispatchEvent(\n// new CustomEvent('notify', {\n// detail: {\n// level: 'error',\n// message,\n// ex: networkError\n// }\n// })\n// )\n// }\n// }\n// }\n\nconst cache = new InMemoryCache({\n addTypename: false\n // dataIdFromObject: object => object.key\n})\n\n// const initPersistCache = async () => {\n// persistCache({\n// cache,\n// storage: window.localStorage\n// })\n// }\n\n// initPersistCache()\n\n// var mockedResponses: any = {}\n\n// const createMockLink = () =>\n// new ApolloLink((operation, forward) => {\n// return new Observable(observer => {\n// const operationName = operation.operationName\n\n// if (mockedResponses[operationName]) {\n// observer.next({\n// data: mockedResponses[operationName]\n// })\n// } else {\n// observer.error(new Error(`No mock response for operation ${operationName}`))\n// }\n\n// observer.complete()\n// })\n// })\n\n// const link = process.env.STORYBOOK_ENV\n// ? createMockLink()\n// : split(\n// ({ query }) => {\n// const def = getMainDefinition(query)\n// return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n// },\n// wsLink,\n// from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink])\n// )\n\nexport const client = new ApolloClient({\n defaultOptions,\n cache,\n link: getClientLink()\n})\n\nexport const subscribe = async (request: any, subscribe: any) => {\n return client.subscribe(request).subscribe(subscribe)\n}\n"]}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { ApolloLink } from '@apollo/client/core';
|
2
|
+
export declare const GRAPHQL_URI = "/graphql";
|
3
|
+
export declare const SUBSCRIPTION_URI = "/graphql";
|
4
|
+
export declare const setClientLink: (link: ApolloLink) => void;
|
5
|
+
export declare const getClientLink: () => ApolloLink;
|
6
|
+
export declare const createMockLink: (mockedResponses?: any) => ApolloLink;
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import createUploadLink from 'apollo-upload-client/createUploadLink.mjs';
|
2
|
+
import { createClient as createWebSocketClient } from 'graphql-ws';
|
3
|
+
import { ApolloLink, from, HttpLink, Observable, split } from '@apollo/client/core';
|
4
|
+
import { onError } from '@apollo/client/link/error';
|
5
|
+
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
|
6
|
+
import { getMainDefinition } from '@apollo/client/utilities';
|
7
|
+
import { activeRequestCounterLink, decreaseActiveRequestCounter } from './active-request-counter-link';
|
8
|
+
export const GRAPHQL_URI = '/graphql';
|
9
|
+
export const SUBSCRIPTION_URI = GRAPHQL_URI;
|
10
|
+
var apolloLink;
|
11
|
+
const httpOptions = {
|
12
|
+
uri: GRAPHQL_URI,
|
13
|
+
credentials: 'include',
|
14
|
+
headers: { 'Apollo-Require-Preflight': 'true' }
|
15
|
+
};
|
16
|
+
const httpLink = ApolloLink.split(operation => operation.getContext().hasUpload, createUploadLink(httpOptions), new HttpLink(httpOptions));
|
17
|
+
const wsLink = new GraphQLWsLink(createWebSocketClient({
|
18
|
+
url: location.origin.replace(/^http/, 'ws') + SUBSCRIPTION_URI,
|
19
|
+
keepAlive: 10000,
|
20
|
+
retryAttempts: 1000000,
|
21
|
+
shouldRetry: e => true,
|
22
|
+
connectionParams: {
|
23
|
+
headers: {
|
24
|
+
/*
|
25
|
+
특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.
|
26
|
+
referer: location.href
|
27
|
+
또는, 이미 서브도메인 정보를 알고 있다면,
|
28
|
+
'x-things-factory-domain': '[subdomain]'
|
29
|
+
을 보낼 수 있다.
|
30
|
+
관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.
|
31
|
+
*/
|
32
|
+
referer: location.href
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}));
|
36
|
+
const ERROR_HANDLER = ({ operation, graphQLErrors, networkError }) => {
|
37
|
+
if (graphQLErrors) {
|
38
|
+
document.dispatchEvent(new CustomEvent('notify', {
|
39
|
+
detail: {
|
40
|
+
level: 'error',
|
41
|
+
message: graphQLErrors[0].message,
|
42
|
+
ex: graphQLErrors
|
43
|
+
}
|
44
|
+
}));
|
45
|
+
}
|
46
|
+
if (networkError) {
|
47
|
+
decreaseActiveRequestCounter();
|
48
|
+
/* networkError가 ServerParseError 이거나 ServerError 인 경우에만 statusCode를 갖는다. */
|
49
|
+
switch (networkError.statusCode) {
|
50
|
+
case undefined /* in case this error is not a server side error */:
|
51
|
+
document.dispatchEvent(new CustomEvent('notify', {
|
52
|
+
detail: {
|
53
|
+
level: 'error',
|
54
|
+
message: networkError.message,
|
55
|
+
ex: networkError
|
56
|
+
}
|
57
|
+
}));
|
58
|
+
break;
|
59
|
+
case 401:
|
60
|
+
/* 401 에러가 리턴되면, 인증이 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 signin 프로세스를 진행할 수 있다. */
|
61
|
+
document.dispatchEvent(new CustomEvent('auth-required'));
|
62
|
+
break;
|
63
|
+
case 403:
|
64
|
+
/* 403 에러가 리턴되면, 도메인 정보가 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 domain-register 프로세스 등을 진행할 수 있다. */
|
65
|
+
document.dispatchEvent(new CustomEvent('domain-required'));
|
66
|
+
break;
|
67
|
+
default:
|
68
|
+
var { name, response, statusCode, bodyText, message } = networkError;
|
69
|
+
if (name == 'ServerParseError') {
|
70
|
+
message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`;
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
/* in case this error is instanceof ServerError */
|
74
|
+
message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`;
|
75
|
+
}
|
76
|
+
document.dispatchEvent(new CustomEvent('notify', {
|
77
|
+
detail: {
|
78
|
+
level: 'error',
|
79
|
+
message,
|
80
|
+
ex: networkError
|
81
|
+
}
|
82
|
+
}));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
};
|
86
|
+
export const setClientLink = (link) => {
|
87
|
+
apolloLink = link;
|
88
|
+
};
|
89
|
+
export const getClientLink = () => {
|
90
|
+
if (!apolloLink) {
|
91
|
+
apolloLink = split(({ query }) => {
|
92
|
+
const def = getMainDefinition(query);
|
93
|
+
return def.kind === 'OperationDefinition' && def.operation === 'subscription';
|
94
|
+
}, wsLink, from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink]));
|
95
|
+
}
|
96
|
+
return apolloLink;
|
97
|
+
};
|
98
|
+
export const createMockLink = (mockedResponses = {}) => new ApolloLink((operation, forward) => {
|
99
|
+
return new Observable(observer => {
|
100
|
+
const operationName = operation.operationName;
|
101
|
+
if (mockedResponses[operationName]) {
|
102
|
+
observer.next({
|
103
|
+
data: mockedResponses[operationName]
|
104
|
+
});
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
observer.error(new Error(`No mock response for operation ${operationName}`));
|
108
|
+
}
|
109
|
+
observer.complete();
|
110
|
+
});
|
111
|
+
});
|
112
|
+
//# sourceMappingURL=graphql-env.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"graphql-env.js","sourceRoot":"","sources":["../../src/graphql-env.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2CAA2C,CAAA;AACxE,OAAO,EAAE,YAAY,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAe,UAAU,EAAoB,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAClH,OAAO,EAAa,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,wB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CAAC,IAAgB,EAAE,EAAE;IAChD,UAAU,GAAG,IAAI,CAAA;AACnB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,KAAK,CAChB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YACZ,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;YACpC,OAAO,GAAG,CAAC,IAAI,KAAK,qBAAqB,IAAI,GAAG,CAAC,SAAS,KAAK,cAAc,CAAA;QAC/E,CAAC,EACD,MAAM,EACN,IAAI,CAAC,CAAC,wBAAwB,EAAE,OAAO,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,CAAC,CACnE,CAAA;IACH,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,kBAAuB,EAAE,EAAE,EAAE,CAC1D,IAAI,UAAU,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IACpC,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC/B,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAA;QAE7C,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;YACnC,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,eAAe,CAAC,aAAa,CAAC;aACrC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,kCAAkC,aAAa,EAAE,CAAC,CAAC,CAAA;QAC9E,CAAC;QAED,QAAQ,CAAC,QAAQ,EAAE,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import createUploadLink from 'apollo-upload-client/createUploadLink.mjs'\nimport { createClient as createWebSocketClient } from 'graphql-ws'\n\nimport { ApolloLink, from, HttpLink, HttpOptions, Observable, ServerParseError, split } from '@apollo/client/core'\nimport { ErrorLink, onError } from '@apollo/client/link/error'\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions'\nimport { getMainDefinition } from '@apollo/client/utilities'\nimport { activeRequestCounterLink, decreaseActiveRequestCounter } from './active-request-counter-link'\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\nvar apolloLink: ApolloLink\n\nconst httpOptions: HttpOptions = {\n uri: GRAPHQL_URI,\n credentials: 'include',\n headers: { 'Apollo-Require-Preflight': 'true' }\n}\n\nconst httpLink = ApolloLink.split(\n operation => operation.getContext().hasUpload,\n createUploadLink(httpOptions) as any,\n new HttpLink(httpOptions)\n)\n\nconst wsLink = new GraphQLWsLink(\n createWebSocketClient({\n url: location.origin.replace(/^http/, 'ws') + SUBSCRIPTION_URI,\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n connectionParams: {\n headers: {\n /* \n 특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.\n referer: location.href\n 또는, 이미 서브도메인 정보를 알고 있다면,\n 'x-things-factory-domain': '[subdomain]'\n 을 보낼 수 있다.\n 관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.\n */\n referer: location.href\n }\n }\n })\n)\n\nconst ERROR_HANDLER: ErrorLink.ErrorHandler = ({ operation, graphQLErrors, networkError }) => {\n if (graphQLErrors) {\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message: graphQLErrors[0].message,\n ex: graphQLErrors\n }\n })\n )\n }\n\n if (networkError) {\n decreaseActiveRequestCounter()\n\n /* networkError가 ServerParseError 이거나 ServerError 인 경우에만 statusCode를 갖는다. */\n switch ((networkError as ServerParseError).statusCode) {\n case undefined /* in case this error is not a server side error */:\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message: networkError.message,\n ex: networkError\n }\n })\n )\n break\n\n case 401:\n /* 401 에러가 리턴되면, 인증이 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 signin 프로세스를 진행할 수 있다. */\n document.dispatchEvent(new CustomEvent('auth-required'))\n break\n\n case 403:\n /* 403 에러가 리턴되면, 도메인 정보가 필요하다는 메시지를 dispatch 한다. 이 auth 모듈 등에서 이 메시지를 받아서 domain-register 프로세스 등을 진행할 수 있다. */\n document.dispatchEvent(new CustomEvent('domain-required'))\n break\n\n default:\n var { name, response, statusCode, bodyText, message } = networkError as ServerParseError\n if (name == 'ServerParseError') {\n message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`\n } else {\n /* in case this error is instanceof ServerError */\n message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`\n }\n\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message,\n ex: networkError\n }\n })\n )\n }\n }\n}\n\nexport const setClientLink = (link: ApolloLink) => {\n apolloLink = link\n}\n\nexport const getClientLink = () => {\n if (!apolloLink) {\n apolloLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink])\n )\n }\n\n return apolloLink\n}\n\nexport const createMockLink = (mockedResponses: any = {}) =>\n new ApolloLink((operation, forward) => {\n return new Observable(observer => {\n const operationName = operation.operationName\n\n if (mockedResponses[operationName]) {\n observer.next({\n data: mockedResponses[operationName]\n })\n } else {\n observer.error(new Error(`No mock response for operation ${operationName}`))\n }\n\n observer.complete()\n })\n })\n"]}
|
package/dist/src/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export * from './gql-context';
|
2
2
|
export * from './graphql-client';
|
3
3
|
export * from './json-to-grqphql-query';
|
4
|
-
export
|
4
|
+
export * from './active-request-counter-link';
|
5
|
+
export * from './use-query';
|
package/dist/src/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export * from './gql-context';
|
2
2
|
export * from './graphql-client';
|
3
3
|
export * from './json-to-grqphql-query';
|
4
|
-
export
|
4
|
+
export * from './active-request-counter-link';
|
5
|
+
export * from './use-query';
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,aAAa,CAAA","sourcesContent":["export * from './gql-context'\nexport * from './graphql-client'\nexport * from './json-to-grqphql-query'\nexport * from './active-request-counter-link'\nexport * from './use-query'\n"]}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import gql from 'graphql-tag';
|
2
|
+
import { useState, useEffect } from 'haunted';
|
3
|
+
import { client } from './graphql-client';
|
4
|
+
export function useQuery(query, variables = {}) {
|
5
|
+
const [data, setData] = useState(null);
|
6
|
+
const [loading, setLoading] = useState(true);
|
7
|
+
const [error, setError] = useState(null);
|
8
|
+
useEffect(() => {
|
9
|
+
const fetchData = async () => {
|
10
|
+
setLoading(true);
|
11
|
+
try {
|
12
|
+
const { data } = await client.query({
|
13
|
+
query: gql `
|
14
|
+
${query}
|
15
|
+
`,
|
16
|
+
variables
|
17
|
+
});
|
18
|
+
setData(data);
|
19
|
+
}
|
20
|
+
catch (error) {
|
21
|
+
setError(error);
|
22
|
+
}
|
23
|
+
setLoading(false);
|
24
|
+
};
|
25
|
+
fetchData();
|
26
|
+
}, [query, variables]); // 의존성 배열에 쿼리와 변수를 포함시켜 쿼리나 변수가 바뀔 때마다 쿼리를 다시 실행합니다.
|
27
|
+
return { data, loading, error };
|
28
|
+
}
|
29
|
+
//# sourceMappingURL=use-query.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-query.js","sourceRoot":"","sources":["../../src/use-query.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,YAAiB,EAAE;IACzD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IACtC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAExC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;YAC3B,UAAU,CAAC,IAAI,CAAC,CAAA;YAEhB,IAAI,CAAC;gBACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;oBAClC,KAAK,EAAE,GAAG,CAAA;cACN,KAAK;WACR;oBACD,SAAS;iBACV,CAAC,CAAA;gBACF,OAAO,CAAC,IAAI,CAAC,CAAA;YACf,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,QAAQ,CAAC,KAAK,CAAC,CAAA;YACjB,CAAC;YAED,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC,CAAA;QAED,SAAS,EAAE,CAAA;IACb,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA,CAAC,oDAAoD;IAE3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import gql from 'graphql-tag'\nimport { useState, useEffect } from 'haunted'\n\nimport { client } from './graphql-client'\n\nexport function useQuery(query: string, variables: any = {}) {\n const [data, setData] = useState(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState(null)\n\n useEffect(() => {\n const fetchData = async () => {\n setLoading(true)\n\n try {\n const { data } = await client.query({\n query: gql`\n ${query}\n `,\n variables\n })\n setData(data)\n } catch (error: any) {\n setError(error)\n }\n\n setLoading(false)\n }\n\n fetchData()\n }, [query, variables]) // 의존성 배열에 쿼리와 변수를 포함시켜 쿼리나 변수가 바뀔 때마다 쿼리를 다시 실행합니다.\n\n return { data, loading, error }\n}\n"]}
|