@operato/graphql 8.0.0-beta.0 β†’ 8.0.0-beta.2

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 CHANGED
@@ -3,6 +3,24 @@
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
+ ## [8.0.0-beta.2](https://github.com/hatiolab/operato/compare/v8.0.0-beta.1...v8.0.0-beta.2) (2025-01-08)
7
+
8
+
9
+ ### :bug: Bug Fix
10
+
11
+ * typo .npmignore ([d9c0c8c](https://github.com/hatiolab/operato/commit/d9c0c8c79abc688c3c2cfb6c37fcb689483a5977))
12
+
13
+
14
+
15
+ ## [8.0.0-beta.1](https://github.com/hatiolab/operato/compare/v8.0.0-beta.0...v8.0.0-beta.1) (2025-01-08)
16
+
17
+
18
+ ### :bug: Bug Fix
19
+
20
+ * missing .npmignore ([be05985](https://github.com/hatiolab/operato/commit/be05985abfae4af53501f718dd52932099f7fbcb))
21
+
22
+
23
+
6
24
  ## [8.0.0-beta.0](https://github.com/hatiolab/operato/compare/v8.0.0-alpha.56...v8.0.0-beta.0) (2025-01-07)
7
25
 
8
26
  **Note:** Version bump only for package @operato/graphql
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/graphql",
3
3
  "description": "Webcomponent graphql-client following open-wc recommendations",
4
4
  "author": "heartyoh@hatiolab.com",
5
- "version": "8.0.0-beta.0",
5
+ "version": "8.0.0-beta.2",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@apollo/client": "^3.6.9",
61
- "@operato/utils": "^8.0.0-beta.0",
61
+ "@operato/utils": "^8.0.0-beta.2",
62
62
  "apollo-upload-client": "^18.0.0",
63
63
  "graphql-tag": "^2.12.6",
64
64
  "graphql-ws": "^5.14.0",
@@ -122,5 +122,5 @@
122
122
  "prettier --write"
123
123
  ]
124
124
  },
125
- "gitHead": "c4e9cc245659d050a9ffd66542083a6daad4bcb9"
125
+ "gitHead": "ee1b5124995accb99272d3b5854f3df1d8746dda"
126
126
  }
package/.editorconfig DELETED
@@ -1,29 +0,0 @@
1
- # EditorConfig helps developers define and maintain consistent
2
- # coding styles between different editors and IDEs
3
- # editorconfig.org
4
-
5
- root = true
6
-
7
-
8
- [*]
9
-
10
- # Change these settings to your own preference
11
- indent_style = space
12
- indent_size = 2
13
-
14
- # We recommend you to keep these unchanged
15
- end_of_line = lf
16
- charset = utf-8
17
- trim_trailing_whitespace = true
18
- insert_final_newline = true
19
-
20
- [*.md]
21
- trim_trailing_whitespace = false
22
-
23
- [*.json]
24
- indent_size = 2
25
-
26
- [*.{html,js,md}]
27
- block_comment_start = /**
28
- block_comment = *
29
- block_comment_end = */
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- stories: ['../dist/stories/**/*.stories.{js,md,mdx}']
3
- }
@@ -1,52 +0,0 @@
1
- import { i18next } from '@operato/i18n'
2
-
3
- export const globalTypes = {
4
- locale: {
5
- name: 'Locale',
6
- description: 'Internationalization locale',
7
- toolbar: {
8
- icon: 'globe',
9
- items: [
10
- { value: 'en', right: 'πŸ‡ΊπŸ‡Έ', title: 'English' },
11
- { value: 'ko', right: 'πŸ‡°πŸ‡·', title: 'ν•œκ΅­μ–΄' },
12
- { value: 'zh', right: 'πŸ‡¨πŸ‡³', title: 'δΈ­ζ–‡' },
13
- { value: 'ja', right: 'πŸ‡―πŸ‡΅', title: 'ζ—₯本θͺž' },
14
- { value: 'ms', right: 'πŸ‡²πŸ‡Ύ', title: 'Bahasa Melayu' }
15
- ],
16
- showName: true
17
- }
18
- },
19
- theme: {
20
- name: 'Theme',
21
- description: 'Global theme for components',
22
- toolbar: {
23
- icon: 'paintbrush',
24
- items: [
25
- { value: 'light', title: 'Light' },
26
- { value: 'dark', title: 'Dark' }
27
- ],
28
- showName: true
29
- }
30
- }
31
- }
32
-
33
- export const decorators = [
34
- (Story, context) => {
35
- const { locale, theme } = context.globals
36
-
37
- if (locale) {
38
- i18next.changeLanguage(locale)
39
- }
40
-
41
- // Set the theme class for the document
42
- if (theme === 'dark') {
43
- document.documentElement.classList.add('dark')
44
- document.documentElement.classList.remove('light')
45
- } else {
46
- document.documentElement.classList.add('light')
47
- document.documentElement.classList.remove('dark')
48
- }
49
-
50
- return Story()
51
- }
52
- ]
@@ -1,8 +0,0 @@
1
- import { storybookPlugin } from '@web/dev-server-storybook'
2
- import baseConfig from '../web-dev-server.config.mjs'
3
-
4
- export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
- ...baseConfig,
6
- open: '/',
7
- plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins]
8
- })
package/demo/index.html DELETED
@@ -1,29 +0,0 @@
1
- <!doctype html>
2
- <html lang="en-GB">
3
- <head>
4
- <meta charset="utf-8">
5
- <style>
6
- body {
7
- background: #fafafa;
8
- }
9
- </style>
10
- </head>
11
- <body>
12
- <div id="demo"></div>
13
-
14
- <script type="module">
15
- import { html, render } from 'lit';
16
- import '../dist/src/graphql-client.js';
17
-
18
- const title = 'Hello owc World!';
19
- render(
20
- html`
21
- <graphql-client .title=${title}>
22
- some light-dom
23
- </graphql-client>
24
- `,
25
- document.querySelector('#demo')
26
- );
27
- </script>
28
- </body>
29
- </html>
@@ -1,31 +0,0 @@
1
- import { ApolloLink } from '@apollo/client/core'
2
-
3
- var activeRequests = 0
4
-
5
- var callback: ((activeRequestCount: number) => void) | null = null
6
-
7
- export const activeRequestCounterLink = new ApolloLink((operation, forward) => {
8
- callback && callback(++activeRequests)
9
-
10
- return forward(operation).map(response => {
11
- callback && callback(--activeRequests)
12
-
13
- return response
14
- })
15
- })
16
-
17
- export function setActiveRequestCounterCallback(newCallback: (activeRequestCount: number) => void) {
18
- callback = newCallback
19
- }
20
-
21
- export function resetActiveRequestCounterCallback() {
22
- callback = null
23
- }
24
-
25
- export function decreaseActiveRequestCounter() {
26
- callback && callback(--activeRequests)
27
- }
28
-
29
- export function increaseActiveRequestCounter() {
30
- callback && callback(++activeRequests)
31
- }
@@ -1,26 +0,0 @@
1
- export const CONTEXT_KEY = '__context__'
2
-
3
- export function gqlContext() {
4
- const search = new URLSearchParams(location.search)
5
- return JSON.parse(search.get(CONTEXT_KEY) || '""') || ''
6
- }
7
-
8
- export function buildGqlContext(
9
- context:
10
- | {
11
- headers: {
12
- 'x-things-factory-domain': string
13
- }
14
- }
15
- | string
16
- ) {
17
- if (!context) {
18
- throw new Error('context is not passed')
19
- }
20
-
21
- if (typeof context !== 'string') {
22
- context = JSON.stringify(context)
23
- }
24
-
25
- return new URLSearchParams({ [CONTEXT_KEY]: context as string }).toString()
26
- }
@@ -1,35 +0,0 @@
1
- import { ApolloClient, DefaultOptions, InMemoryCache } from '@apollo/client/core'
2
-
3
- import { getClientLink } from './graphql-env'
4
-
5
- export const GRAPHQL_URI = '/graphql'
6
- export const SUBSCRIPTION_URI = GRAPHQL_URI
7
-
8
- const defaultOptions: DefaultOptions = {
9
- watchQuery: {
10
- fetchPolicy: 'no-cache',
11
- errorPolicy: 'ignore'
12
- },
13
- query: {
14
- fetchPolicy: 'no-cache', //'network-only'
15
- errorPolicy: 'all'
16
- },
17
- mutate: {
18
- errorPolicy: 'all'
19
- }
20
- }
21
-
22
- const cache = new InMemoryCache({
23
- addTypename: false
24
- // dataIdFromObject: object => object.key
25
- })
26
-
27
- export const client = new ApolloClient({
28
- defaultOptions,
29
- cache,
30
- link: getClientLink()
31
- })
32
-
33
- export const subscribe = async (request: any, subscribe: any) => {
34
- return client.subscribe(request).subscribe(subscribe)
35
- }
@@ -1,147 +0,0 @@
1
- import createUploadLink from 'apollo-upload-client/createUploadLink.mjs'
2
- import { createClient as createWebSocketClient } from 'graphql-ws'
3
-
4
- import { ApolloLink, from, HttpLink, HttpOptions, Observable, ServerParseError, split } from '@apollo/client/core'
5
- import { ErrorLink, onError } from '@apollo/client/link/error'
6
- import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
7
- import { getMainDefinition } from '@apollo/client/utilities'
8
-
9
- import { decodeHTML } from '@operato/utils'
10
- import { activeRequestCounterLink, decreaseActiveRequestCounter } from './active-request-counter-link'
11
-
12
- export const GRAPHQL_URI = '/graphql'
13
- export const SUBSCRIPTION_URI = GRAPHQL_URI
14
-
15
- var apolloLink: ApolloLink
16
-
17
- const httpOptions: HttpOptions = {
18
- uri: GRAPHQL_URI,
19
- credentials: 'include',
20
- headers: { 'Apollo-Require-Preflight': 'true' }
21
- }
22
-
23
- const httpLink = ApolloLink.split(
24
- operation => operation.getContext().hasUpload,
25
- createUploadLink(httpOptions) as any,
26
- new HttpLink(httpOptions)
27
- )
28
-
29
- const wsLink = new GraphQLWsLink(
30
- createWebSocketClient({
31
- url: location.origin.replace(/^http/, 'ws') + SUBSCRIPTION_URI,
32
- keepAlive: 10_000,
33
- retryAttempts: 1_000_000,
34
- shouldRetry: e => true,
35
- connectionParams: {
36
- headers: {
37
- /*
38
- νŠΉμ • λ„λ©”μΈμ˜ λ°μ΄νƒ€λ§Œ λ°›κ³ μž ν•˜λŠ” κ²½μš°μ—, referer 정보λ₯Ό μ œκ³΅ν•΄μ„œ μ„œλ²„μ—μ„œ μ„œλΈŒλ„λ©”μΈ 정보λ₯Ό μ·¨λ“ν•˜λ„λ‘ ν•œλ‹€.
39
- referer: location.href
40
- λ˜λŠ”, 이미 μ„œλΈŒλ„λ©”μΈ 정보λ₯Ό μ•Œκ³  μžˆλ‹€λ©΄,
41
- 'x-things-factory-domain': '[subdomain]'
42
- 을 보낼 수 μžˆλ‹€.
43
- κ΄€λ ¨ 정보λ₯Ό 보내지 μ•ŠλŠ”λ‹€λ©΄, μ‚¬μš©μžκ°€ κΆŒν•œμ„ κ°€μ§„ λͺ¨λ“  λ„λ©”μΈμ˜ 데이타λ₯Ό μˆ˜μ‹ ν•˜κ²Œ λœλ‹€.
44
- */
45
- referer: location.href
46
- }
47
- }
48
- })
49
- )
50
-
51
- const ERROR_HANDLER: ErrorLink.ErrorHandler = ({ operation, graphQLErrors, networkError }) => {
52
- if (graphQLErrors) {
53
- document.dispatchEvent(
54
- new CustomEvent('notify', {
55
- detail: {
56
- level: 'error',
57
- message: decodeHTML(graphQLErrors[0].message),
58
- ex: graphQLErrors
59
- }
60
- })
61
- )
62
- }
63
-
64
- if (networkError) {
65
- decreaseActiveRequestCounter()
66
-
67
- /* networkErrorκ°€ ServerParseError μ΄κ±°λ‚˜ ServerError 인 κ²½μš°μ—λ§Œ statusCodeλ₯Ό κ°–λŠ”λ‹€. */
68
- switch ((networkError as ServerParseError).statusCode) {
69
- case undefined /* in case this error is not a server side error */:
70
- document.dispatchEvent(
71
- new CustomEvent('notify', {
72
- detail: {
73
- level: 'error',
74
- message: networkError.message,
75
- ex: networkError
76
- }
77
- })
78
- )
79
- break
80
-
81
- case 401:
82
- /* 401 μ—λŸ¬κ°€ λ¦¬ν„΄λ˜λ©΄, 인증이 ν•„μš”ν•˜λ‹€λŠ” λ©”μ‹œμ§€λ₯Ό dispatch ν•œλ‹€. 이 auth λͺ¨λ“ˆ λ“±μ—μ„œ 이 λ©”μ‹œμ§€λ₯Ό λ°›μ•„μ„œ signin ν”„λ‘œμ„ΈμŠ€λ₯Ό μ§„ν–‰ν•  수 μžˆλ‹€. */
83
- document.dispatchEvent(new CustomEvent('auth-required'))
84
- break
85
-
86
- case 403:
87
- /* 403 μ—λŸ¬κ°€ λ¦¬ν„΄λ˜λ©΄, 도메인 정보가 ν•„μš”ν•˜λ‹€λŠ” λ©”μ‹œμ§€λ₯Ό dispatch ν•œλ‹€. 이 auth λͺ¨λ“ˆ λ“±μ—μ„œ 이 λ©”μ‹œμ§€λ₯Ό λ°›μ•„μ„œ domain-register ν”„λ‘œμ„ΈμŠ€ 등을 μ§„ν–‰ν•  수 μžˆλ‹€. */
88
- document.dispatchEvent(new CustomEvent('domain-required'))
89
- break
90
-
91
- default:
92
- var { name, response, statusCode, bodyText, message } = networkError as ServerParseError
93
- if (name == 'ServerParseError') {
94
- message = `[ ${statusCode || ''} : ${response.statusText} ] ${bodyText}`
95
- } else {
96
- /* in case this error is instanceof ServerError */
97
- message = `[ ${statusCode || ''} : ${response.statusText} ] ${message}`
98
- }
99
-
100
- document.dispatchEvent(
101
- new CustomEvent('notify', {
102
- detail: {
103
- level: 'error',
104
- message: decodeHTML(message),
105
- ex: networkError
106
- }
107
- })
108
- )
109
- }
110
- }
111
- }
112
-
113
- export const setClientLink = (link: ApolloLink) => {
114
- apolloLink = link
115
- }
116
-
117
- export const getClientLink = () => {
118
- if (!apolloLink) {
119
- apolloLink = split(
120
- ({ query }) => {
121
- const def = getMainDefinition(query)
122
- return def.kind === 'OperationDefinition' && def.operation === 'subscription'
123
- },
124
- wsLink,
125
- from([activeRequestCounterLink, onError(ERROR_HANDLER), httpLink])
126
- )
127
- }
128
-
129
- return apolloLink
130
- }
131
-
132
- export const createMockLink = (mockedResponses: any = {}) =>
133
- new ApolloLink((operation, forward) => {
134
- return new Observable(observer => {
135
- const operationName = operation.operationName
136
-
137
- if (mockedResponses[operationName]) {
138
- observer.next({
139
- data: mockedResponses[operationName]
140
- })
141
- } else {
142
- observer.error(new Error(`No mock response for operation ${operationName}`))
143
- }
144
-
145
- observer.complete()
146
- })
147
- })
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './gql-context'
2
- export * from './graphql-client'
3
- export * from './json-to-grqphql-query'
4
- export * from './active-request-counter-link'
5
- export * from './use-query'
@@ -1,206 +0,0 @@
1
- /* inspired by https://github.com/dupski/json-to-graphql-query */
2
-
3
- import { EnumType } from './types/EnumType'
4
- import { VariableType } from './types/VariableType'
5
-
6
- export const configFields = [
7
- '__args',
8
- '__alias',
9
- '__aliasFor',
10
- '__variables',
11
- '__directives',
12
- '__on',
13
- '__all_on',
14
- '__typeName',
15
- '__name'
16
- ]
17
-
18
- function stringify(obj_from_json: any): string {
19
- if (obj_from_json instanceof EnumType) {
20
- return obj_from_json.value
21
- }
22
- // variables should be prefixed with dollar sign and not quoted
23
- else if (obj_from_json instanceof VariableType) {
24
- return `$${obj_from_json.value}`
25
- }
26
- // Cheers to Derek: https://stackoverflow.com/questions/11233498/json-stringify-without-quotes-on-properties
27
- else if (typeof obj_from_json !== 'object' || obj_from_json === null) {
28
- // not an object, stringify using native function
29
- return JSON.stringify(obj_from_json)
30
- } else if (Array.isArray(obj_from_json)) {
31
- return `[${obj_from_json.map(item => stringify(item)).join(', ')}]`
32
- }
33
- // Implements recursive object serialization according to JSON spec
34
- // but without quotes around the keys.
35
- const props: string = Object.keys(obj_from_json)
36
- .map(key => `${key}: ${stringify(obj_from_json[key])}`)
37
- .join(', ')
38
-
39
- return `{${props}}`
40
- }
41
-
42
- export function buildArgs(argsObj: { [name: string]: any }): string {
43
- const args = []
44
- for (const argName in argsObj) {
45
- args.push(`${argName}: ${stringify(argsObj[argName])}`)
46
- }
47
- return args.join(', ')
48
- }
49
-
50
- export function buildVariables(varsObj: any): string {
51
- const args = []
52
- for (const varName in varsObj) {
53
- args.push(`$${varName}: ${varsObj[varName]}`)
54
- }
55
- return args.join(', ')
56
- }
57
-
58
- function buildDirectives(dirsObj: any): string {
59
- const directiveName = Object.keys(dirsObj)[0]
60
- const directiveValue = dirsObj[directiveName]
61
- if (typeof directiveValue === 'boolean') {
62
- return directiveName
63
- } else if (typeof directiveValue === 'object') {
64
- const args = []
65
- for (const argName in directiveValue) {
66
- const argVal = stringify(directiveValue[argName]).replace(/"/g, '')
67
- args.push(`${argName}: ${argVal}`)
68
- }
69
- return `${directiveName}(${args.join(', ')})`
70
- } else {
71
- throw new Error(
72
- `Unsupported type for directive: ${typeof directiveValue}. Types allowed: object, boolean.\n` +
73
- `Offending object: ${JSON.stringify(dirsObj)}`
74
- )
75
- }
76
- }
77
-
78
- function getIndent(level: number): string {
79
- return Array(level * 4 + 1).join(' ')
80
- }
81
-
82
- function filterNonConfigFields(fieldName: string, ignoreFields: string[]) {
83
- // Returns true if fieldName is not a 'configField'.
84
- return configFields.indexOf(fieldName) == -1 && ignoreFields.indexOf(fieldName) == -1
85
- }
86
-
87
- function convertQuery(node: any, level: number, output: [string, number][], options: IJsonToGraphQLOptions) {
88
- Object.keys(node)
89
- .filter(key => filterNonConfigFields(key, options.ignoreFields!))
90
- .forEach(key => {
91
- let value = node[key]
92
- if (typeof value === 'object') {
93
- if (Array.isArray(value)) {
94
- value = value.find(item => item && typeof item === 'object')
95
- if (!value) {
96
- output.push([`${key}`, level])
97
- return
98
- }
99
- }
100
-
101
- const fieldCount = Object.keys(value).filter(keyCount =>
102
- filterNonConfigFields(keyCount, options.ignoreFields!)
103
- ).length
104
- const subFields = fieldCount > 0
105
- const argsExist = typeof value.__args === 'object' && Object.keys(value.__args).length > 0
106
- const directivesExist = typeof value.__directives === 'object'
107
- const fullFragmentsExist = value.__all_on instanceof Array
108
- const partialFragmentsExist = typeof value.__on === 'object'
109
-
110
- let token = `${key}`
111
-
112
- if (typeof value.__name === 'string') {
113
- token = `${token} ${value.__name}`
114
- }
115
-
116
- if (typeof value.__aliasFor === 'string') {
117
- token = `${token}: ${value.__aliasFor}`
118
- }
119
-
120
- if (typeof value.__variables === 'object') {
121
- token = `${token} (${buildVariables(value.__variables)})`
122
- } else if (argsExist || directivesExist) {
123
- let argsStr = ''
124
- let dirsStr = ''
125
- if (directivesExist) {
126
- // TODO: Add support for multiple directives on one node.
127
- const numDirectives = Object.keys(value.__directives).length
128
- if (numDirectives > 1) {
129
- throw new Error(
130
- `Too many directives. The object/key ` +
131
- `'${Object.keys(value)[0]}' had ${numDirectives} directives, ` +
132
- `but only 1 directive per object/key is supported at this time.`
133
- )
134
- }
135
- dirsStr = `@${buildDirectives(value.__directives)}`
136
- }
137
- if (argsExist) {
138
- argsStr = `(${buildArgs(value.__args)})`
139
- }
140
- const spacer = directivesExist && argsExist ? ' ' : ''
141
- token = `${token} ${dirsStr}${spacer}${argsStr}`
142
- }
143
-
144
- output.push([token + (subFields || partialFragmentsExist || fullFragmentsExist ? ' {' : ''), level])
145
- convertQuery(value, level + 1, output, options)
146
-
147
- if (fullFragmentsExist) {
148
- value.__all_on.forEach((fullFragment: string) => {
149
- output.push([`...${fullFragment}`, level + 1])
150
- })
151
- }
152
- if (partialFragmentsExist) {
153
- const inlineFragments: { __typeName: string }[] = value.__on instanceof Array ? value.__on : [value.__on]
154
- inlineFragments.forEach(inlineFragment => {
155
- const name = inlineFragment.__typeName
156
- output.push([`... on ${name} {`, level + 1])
157
- convertQuery(inlineFragment, level + 2, output, options)
158
- output.push(['}', level + 1])
159
- })
160
- }
161
-
162
- if (subFields || partialFragmentsExist || fullFragmentsExist) {
163
- output.push(['}', level])
164
- }
165
- } else if (options.includeFalsyKeys === true || value) {
166
- output.push([`${key}`, level])
167
- }
168
- })
169
- }
170
-
171
- export interface IJsonToGraphQLOptions {
172
- pretty?: boolean
173
- ignoreFields?: string[]
174
- includeFalsyKeys?: boolean
175
- }
176
-
177
- export function jsonToGraphQLQuery(query: any, options: IJsonToGraphQLOptions = {}) {
178
- if (!query || typeof query != 'object') {
179
- throw new Error('query object not specified')
180
- }
181
- if (Object.keys(query).length == 0) {
182
- throw new Error('query object has no data')
183
- }
184
- if (!(options.ignoreFields instanceof Array)) {
185
- options.ignoreFields = []
186
- }
187
-
188
- const queryLines: [string, number][] = []
189
- convertQuery(query, 0, queryLines, options)
190
-
191
- let output = ''
192
- queryLines.forEach(([line, level]) => {
193
- if (options.pretty) {
194
- if (output) {
195
- output += '\n'
196
- }
197
- output += getIndent(level) + line
198
- } else {
199
- if (output) {
200
- output += ' '
201
- }
202
- output += line
203
- }
204
- })
205
- return output
206
- }
@@ -1,5 +0,0 @@
1
- class EnumType {
2
- constructor(public value: string) {}
3
- }
4
-
5
- export { EnumType }
@@ -1,9 +0,0 @@
1
- class VariableType {
2
- constructor(public value: string) {}
3
-
4
- toJSON() {
5
- return `$${this.value}`
6
- }
7
- }
8
-
9
- export { VariableType }
package/src/use-query.ts DELETED
@@ -1,34 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { useState, useEffect } from 'haunted'
3
-
4
- import { client } from './graphql-client'
5
-
6
- export function useQuery(query: string, variables: any = {}) {
7
- const [data, setData] = useState(null)
8
- const [loading, setLoading] = useState(true)
9
- const [error, setError] = useState(null)
10
-
11
- useEffect(() => {
12
- const fetchData = async () => {
13
- setLoading(true)
14
-
15
- try {
16
- const { data } = await client.query({
17
- query: gql`
18
- ${query}
19
- `,
20
- variables
21
- })
22
- setData(data)
23
- } catch (error: any) {
24
- setError(error)
25
- }
26
-
27
- setLoading(false)
28
- }
29
-
30
- fetchData()
31
- }, [query, variables]) // μ˜μ‘΄μ„± 배열에 쿼리와 λ³€μˆ˜λ₯Ό ν¬ν•¨μ‹œμΌœ μΏΌλ¦¬λ‚˜ λ³€μˆ˜κ°€ λ°”λ€” λ•Œλ§ˆλ‹€ 쿼리λ₯Ό λ‹€μ‹œ μ‹€ν–‰ν•©λ‹ˆλ‹€.
32
-
33
- return { data, loading, error }
34
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
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
- "useDefineForClassFields": false,
13
- "importHelpers": true,
14
- "outDir": "dist",
15
- "sourceMap": true,
16
- "inlineSources": true,
17
- "rootDir": "./",
18
- "declaration": true,
19
- "incremental": true,
20
- "skipLibCheck": true,
21
- "skipLibCheck": true,
22
- "types": ["node", "mocha"]
23
- },
24
- "include": ["**/*.ts"]
25
- }
@@ -1,27 +0,0 @@
1
- // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
-
3
- /** Use Hot Module replacement by adding --hmr to the start command */
4
- const hmr = process.argv.includes('--hmr');
5
-
6
- export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
- open: '/demo/',
8
- /** Use regular watch mode if HMR is not enabled. */
9
- watch: !hmr,
10
- /** Resolve bare module imports */
11
- nodeResolve: {
12
- exportConditions: ['browser', 'development'],
13
- },
14
-
15
- /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
- // esbuildTarget: 'auto'
17
-
18
- /** Set appIndex to enable SPA routing */
19
- // appIndex: 'demo/index.html',
20
-
21
- plugins: [
22
- /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
- // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
- ],
25
-
26
- // See documentation for all available options
27
- });
@@ -1,41 +0,0 @@
1
- // import { playwrightLauncher } from '@web/test-runner-playwright';
2
-
3
- const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
-
5
- export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
- /** Test files to run */
7
- files: 'dist/test/**/*.test.js',
8
-
9
- /** Resolve bare module imports */
10
- nodeResolve: {
11
- exportConditions: ['browser', 'development'],
12
- },
13
-
14
- /** Filter out lit dev mode logs */
15
- filterBrowserLogs(log) {
16
- for (const arg of log.args) {
17
- if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
- return false;
19
- }
20
- }
21
- return true;
22
- },
23
-
24
- /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
- // esbuildTarget: 'auto',
26
-
27
- /** Amount of browsers to run concurrently */
28
- // concurrentBrowsers: 2,
29
-
30
- /** Amount of test files per browser to test concurrently */
31
- // concurrency: 1,
32
-
33
- /** Browsers to run tests on */
34
- // browsers: [
35
- // playwrightLauncher({ product: 'chromium' }),
36
- // playwrightLauncher({ product: 'firefox' }),
37
- // playwrightLauncher({ product: 'webkit' }),
38
- // ],
39
-
40
- // See documentation for all available options
41
- });