@ctx-core/graphql-client 7.4.204 → 7.4.208

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.
@@ -0,0 +1,20 @@
1
+ import type { FetchHttpOpts } from '../_types/index.js'
2
+ export declare function graphql_fetch<data_T = unknown>(
3
+ body:string, fn_in_http_opts?:FetchHttpOpts
4
+ ):Promise<graphql_fetch_response_T<data_T>>
5
+ export interface graphql_fetch_response_T<data_T = unknown> {
6
+ data:data_T
7
+ }
8
+ export {
9
+ graphql_fetch as fetch_graphql,
10
+ graphql_fetch as fetch__graphql,
11
+ }
12
+ export declare function graphql_fetch_<
13
+ O1 = unknown
14
+ >(in_http_opts?:FetchHttpOpts):graphql_fetch_T<O1>
15
+ export declare type graphql_fetch_T<O = unknown> =
16
+ (body:string, fn_in_http_opts?:FetchHttpOpts)=>Promise<graphql_fetch_response_T<O>>
17
+ export {
18
+ graphql_fetch_ as _graphql_fetch,
19
+ graphql_fetch_ as _fetch__graphql,
20
+ }
@@ -0,0 +1,63 @@
1
+ import { import_meta_env_ } from 'ctx-core/env'
2
+ import { fetch_response_pair__new } from 'ctx-core/fetch'
3
+ import { graphql_url_ } from '../graphql_url/index.js'
4
+ let in_graphql_fetch
5
+ /**
6
+ * @param {string}body
7
+ * @param {import('../_types/index.js/index.js').FetchHttpOpts}fn_in_http_opts
8
+ * @returns {Promise<import('./index.d.ts/index.js').graphql_fetch_response_T>}
9
+ */
10
+ export function graphql_fetch(
11
+ body,
12
+ fn_in_http_opts = {}
13
+ ) {
14
+ if (!in_graphql_fetch) {
15
+ in_graphql_fetch = graphql_fetch_({
16
+ url: graphql_url_()
17
+ })
18
+ }
19
+ return in_graphql_fetch(body, fn_in_http_opts)
20
+ }
21
+ export {
22
+ graphql_fetch as fetch_graphql,
23
+ graphql_fetch as fetch__graphql,
24
+ }
25
+ /**
26
+ * @param {import('../_types/index.js').FetchHttpOpts}in_http_opts
27
+ * @returns {import('../graphql_fetch').graphql_fetch_response_T}
28
+ * @private
29
+ */
30
+ export function graphql_fetch_(in_http_opts = {}) {
31
+ return async function graphql_fetch(body, fn_in_http_opts = {}) {
32
+ const url = fn_in_http_opts.url || in_http_opts.url
33
+ if (!url) {
34
+ throw `no url prop`
35
+ }
36
+ const [payload, response] = await fetch_response_pair__new(url, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ ...in_http_opts.headers,
41
+ ...fn_in_http_opts.headers,
42
+ },
43
+ body,
44
+ ...in_http_opts,
45
+ ...fn_in_http_opts
46
+ })
47
+ if (response.ok) {
48
+ if (payload.errors) throw payload
49
+ return payload
50
+ } else {
51
+ if (import_meta_env_().NODE_ENV === 'production') {
52
+ console.error(payload)
53
+ throw `Error fetching graphql`
54
+ } else {
55
+ throw payload
56
+ }
57
+ }
58
+ }
59
+ }
60
+ export {
61
+ graphql_fetch_ as _graphql_fetch,
62
+ graphql_fetch_ as _fetch__graphql,
63
+ }
@@ -0,0 +1,5 @@
1
+ export declare function graphql_port_txt_(port?:number|string|undefined):string
2
+ export {
3
+ graphql_port_txt_ as _graphql_port_txt,
4
+ graphql_port_txt_ as _txt__port__graphql,
5
+ }
@@ -0,0 +1,13 @@
1
+ import { import_meta_env_ } from 'ctx-core/env'
2
+ /**
3
+ * @param {number|string}port
4
+ * @returns {string}
5
+ * @private
6
+ */
7
+ export function graphql_port_txt_(port = import_meta_env_().PORT) {
8
+ return (port || 80) === 80 ? '' : `:${port}`
9
+ }
10
+ export {
11
+ graphql_port_txt_ as _graphql_port_txt,
12
+ graphql_port_txt_ as _txt__port__graphql,
13
+ }
@@ -0,0 +1,5 @@
1
+ export declare function graphql_url_(host?:string, port?:number):string
2
+ export {
3
+ graphql_url_ as _graphql_url,
4
+ graphql_url_ as _url__graphql,
5
+ }
@@ -0,0 +1,11 @@
1
+ import { is_browser_ } from 'ctx-core/env'
2
+ import { graphql_port_txt_ } from '../graphql_port_txt/index.js'
3
+ export function graphql_url_(host = '127.0.0.1', port = 80) {
4
+ if (is_browser_()) return '/graphql'
5
+ const host_port = `${host}${graphql_port_txt_(port)}`
6
+ return `http://${host_port}/graphql`
7
+ }
8
+ export {
9
+ graphql_url_ as _graphql_url,
10
+ graphql_url_ as _url__graphql,
11
+ }
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './_types/index.js'
2
2
  export * from './graphql_fetch/index.js'
3
- export * from './graphql_fetch_/index.js'
4
- export * from './graphql_port_txt_/index.js'
5
- export * from './graphql_url_/index.js'
3
+ export * from './graphql_port_txt/index.js'
4
+ export * from './graphql_url/index.js'
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './graphql_fetch/index.js'
2
- export * from './graphql_fetch_/index.js'
3
- export * from './graphql_port_txt_/index.js'
4
- export * from './graphql_url_/index.js'
2
+ export * from './graphql_port_txt/index.js'
3
+ export * from './graphql_url/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctx-core/graphql-client",
3
- "version": "7.4.204",
3
+ "version": "7.4.208",
4
4
  "description": "ctx-core graphql-client",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -22,9 +22,9 @@
22
22
  "*.js",
23
23
  "*.json",
24
24
  "./_types",
25
- "./gql",
26
- "./graphql_validation_errors_",
27
- "./ValidationError"
25
+ "./graphql_fetch",
26
+ "./graphql_port_txt",
27
+ "./graphql_url"
28
28
  ],
29
29
  "types": "./index.d.ts",
30
30
  "exports": {
@@ -32,13 +32,10 @@
32
32
  "./package.json": "./package.json"
33
33
  },
34
34
  "dependencies": {
35
- "@ctx-core/dom": "^15.3.18",
36
- "@ctx-core/fetch-undici": "^3.1.188",
37
- "@ctx-core/graphql": "^9.1.122",
38
- "ctx-core": "^5.36.0"
35
+ "ctx-core": "^5.36.2"
39
36
  },
40
37
  "devDependencies": {
41
- "@types/node": "^20.11.13",
38
+ "@types/node": "^20.11.14",
42
39
  "c8": "^9.1.0",
43
40
  "check-dts": "^0.7.2",
44
41
  "tsx": "^4.7.0",