@okam/directus-query 1.4.1 → 1.5.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 +41 -0
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/index.mjs +47 -67
- package/lib/config.d.ts +2 -1
- package/lib/hooks/use-graphql.d.ts +5 -7
- package/lib/hooks/use-suspense-graphql.d.ts +4 -3
- package/lib/init.d.ts +5 -4
- package/lib/providers/index.d.ts +5 -0
- package/lib/providers/interface.d.ts +12 -0
- package/lib/query.d.ts +4 -3
- package/lib/request.d.ts +1 -0
- package/logger.d.ts +1 -1
- package/package.json +9 -4
- package/server.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
## 1.5.0 (2026-01-16)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **directus-query:** stop bundling okam libs ([ebb2885](https://github.com/OKAMca/stack/commit/ebb2885))
|
|
10
|
+
- **directus-next:** draft route handler uses zod, returns draft isEnabled whenever possible ([#376](https://github.com/OKAMca/stack/pull/376))
|
|
11
|
+
- update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
|
|
12
|
+
- package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
|
|
13
|
+
- search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
|
|
14
|
+
|
|
15
|
+
### ⚠️ Breaking Changes
|
|
16
|
+
|
|
17
|
+
- Consumers must now have react and react-dom in their own
|
|
18
|
+
|
|
19
|
+
### ❤️ Thank You
|
|
20
|
+
|
|
21
|
+
- Marie-Maxime Tanguay @marie-maxime
|
|
22
|
+
- Pierre-Olivier Clerson @poclerson
|
|
23
|
+
- poclerson
|
|
24
|
+
|
|
25
|
+
## 1.4.2 (2025-07-24)
|
|
26
|
+
|
|
27
|
+
### 🩹 Fixes
|
|
28
|
+
|
|
29
|
+
- update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
|
|
30
|
+
- package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
|
|
31
|
+
- search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
|
|
32
|
+
|
|
33
|
+
### 🧱 Updated Dependencies
|
|
34
|
+
|
|
35
|
+
- Updated core-lib to 1.17.0
|
|
36
|
+
|
|
37
|
+
### ❤️ Thank You
|
|
38
|
+
|
|
39
|
+
- Marie-Maxime Tanguay
|
|
40
|
+
- Pierre-Olivier Clerson @poclerson
|
|
41
|
+
|
|
1
42
|
## 1.3.0 (2024-11-06)
|
|
2
43
|
|
|
3
44
|
|
package/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export * from './lib/hooks';
|
|
|
2
2
|
export * from './lib/query';
|
|
3
3
|
export { logger as DirectusQueryLogger } from './logger';
|
|
4
4
|
export { default as initDirectusQuery } from './lib/init';
|
|
5
|
+
export { graphqlRequestClient as defaultGraphqlRequestClient, graphqlRequestAdmin as defaultGraphqlRequestAdmin, } from './lib/request';
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@tanstack/react-query"),_=require("radashi"),l=require("graphql-request"),Q=require("@okam/logger"),a=Q.createLogger("[DirectusQuery]"),A=process.env.NEXT_PUBLIC_GRAPHQL_URL,N=process.env.NEXT_SERVER_GRAPHQL_URL,p=process.env.NEXT_GRAPHQL_URL_ADMIN,E=process.env.NEXT_PUBLIC_API_TOKEN??"",G=process.env.NEXT_PUBLIC_API_TOKEN,y=new l.GraphQLClient(N||A,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${E}`}}),q=new l.GraphQLClient(p,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${G}`}});new t.QueryClient({queryCache:new t.QueryCache({onError:e=>{a.log("QueryClient Error","error",{error:e})}}),defaultOptions:{queries:{staleTime:5*1e3}}});function o(e,r,n=y){return n.request(e,{...r})}function c(e,r){return[_.get(e,"definitions.0.name.value"),r]}function L(e,r,n,u){const s=c(e,r);return t.useQuery({queryKey:s,queryFn:async({queryKey:i})=>o(e,i[1],u),...n})}function P(e,r,n){const u=c(e,r);return t.useSuspenseQuery({queryKey:u,queryFn:async({queryKey:s})=>o(e,s[1]),...n})}function T(e,r,n){const u=c(e,r);return t.useSuspenseQuery({queryKey:u,queryFn:async({queryKey:s})=>o(e,s[1],q),...n})}const d=process.env.NEXT_PUBLIC_GRAPHQL_URL,R=process.env.NEXT_PUBLIC_API_TOKEN,h={credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${R}`}},g=(e=d,r=h)=>{const n=new l.GraphQLClient(e,r);function u(s,i){return o(s,i,n)}return{queryGql:u,client:n}};exports.DirectusQueryLogger=a;exports.defaultGraphqlRequestAdmin=q;exports.defaultGraphqlRequestClient=y;exports.getQueryValues=c;exports.initDirectusQuery=g;exports.queryGql=o;exports.useGqlQuery=L;exports.useSuspenseGqlQuery=P;exports.useSuspenseGqlQueryAdmin=T;
|
package/index.mjs
CHANGED
|
@@ -1,48 +1,26 @@
|
|
|
1
|
-
import { QueryClient as
|
|
2
|
-
import { get as
|
|
1
|
+
import { QueryClient as l, QueryCache as _, useQuery as y, useSuspenseQuery as a } from "@tanstack/react-query";
|
|
2
|
+
import { get as q } from "radashi";
|
|
3
3
|
import { GraphQLClient as c } from "graphql-request";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.nameSpace = "[STACK]", this.suppressConsole = !1, this.env = process.env.NODE_ENV, this.nameSpace = n ?? this.nameSpace, this.suppressConsole = s ?? this.suppressConsole, this.logger = e ?? this.internalLogger;
|
|
7
|
-
}
|
|
8
|
-
internalLogger(n, e, s) {
|
|
9
|
-
this.env !== "production" && console[e || "log"](`${this.nameSpace} ${n}`.trimStart(), s ?? "");
|
|
10
|
-
}
|
|
11
|
-
setLogger(n) {
|
|
12
|
-
this.logger = (e, s, t) => {
|
|
13
|
-
this.suppressConsole && this.internalLogger(e, s, t), n(e, s, t);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
static getInstance() {
|
|
17
|
-
return o.instance || (o.instance = new o()), o.instance;
|
|
18
|
-
}
|
|
19
|
-
log(n, e, s) {
|
|
20
|
-
this.logger(n, e, s);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
o.getInstance();
|
|
24
|
-
const y = (r, n, e = !1) => {
|
|
25
|
-
const s = new o(r, n, e);
|
|
26
|
-
return s.log("Logger initialized", "info"), s;
|
|
27
|
-
}, N = y("[DirectusQuery]"), E = process.env.NEXT_PUBLIC_GRAPHQL_URL, A = process.env.NEXT_SERVER_GRAPHQL_URL, L = process.env.NEXT_GRAPHQL_URL_ADMIN, f = process.env.NEXT_PUBLIC_API_TOKEN ?? "", Q = process.env.NEXT_PUBLIC_API_TOKEN, T = new c(A || E, {
|
|
4
|
+
import { createLogger as N } from "@okam/logger";
|
|
5
|
+
const A = N("[DirectusQuery]"), E = process.env.NEXT_PUBLIC_GRAPHQL_URL, Q = process.env.NEXT_SERVER_GRAPHQL_URL, p = process.env.NEXT_GRAPHQL_URL_ADMIN, L = process.env.NEXT_PUBLIC_API_TOKEN ?? "", P = process.env.NEXT_PUBLIC_API_TOKEN, T = new c(Q || E, {
|
|
28
6
|
credentials: "include",
|
|
29
7
|
mode: "cors",
|
|
30
8
|
fetch,
|
|
31
9
|
headers: {
|
|
32
|
-
Authorization: `Bearer ${
|
|
10
|
+
Authorization: `Bearer ${L}`
|
|
33
11
|
}
|
|
34
|
-
}),
|
|
12
|
+
}), R = new c(p, {
|
|
35
13
|
credentials: "include",
|
|
36
14
|
mode: "cors",
|
|
37
15
|
fetch,
|
|
38
16
|
headers: {
|
|
39
|
-
Authorization: `Bearer ${
|
|
17
|
+
Authorization: `Bearer ${P}`
|
|
40
18
|
}
|
|
41
19
|
});
|
|
42
|
-
new
|
|
43
|
-
queryCache: new
|
|
44
|
-
onError: (
|
|
45
|
-
|
|
20
|
+
new l({
|
|
21
|
+
queryCache: new _({
|
|
22
|
+
onError: (e) => {
|
|
23
|
+
A.log("QueryClient Error", "error", { error: e });
|
|
46
24
|
}
|
|
47
25
|
}),
|
|
48
26
|
defaultOptions: {
|
|
@@ -51,61 +29,63 @@ new p({
|
|
|
51
29
|
}
|
|
52
30
|
}
|
|
53
31
|
});
|
|
54
|
-
function
|
|
55
|
-
return
|
|
56
|
-
...
|
|
32
|
+
function u(e, r, n = T) {
|
|
33
|
+
return n.request(e, {
|
|
34
|
+
...r
|
|
57
35
|
});
|
|
58
36
|
}
|
|
59
|
-
function
|
|
60
|
-
return [
|
|
37
|
+
function i(e, r) {
|
|
38
|
+
return [q(e, "definitions.0.name.value"), r];
|
|
61
39
|
}
|
|
62
|
-
function
|
|
63
|
-
const t =
|
|
64
|
-
return
|
|
40
|
+
function v(e, r, n, s) {
|
|
41
|
+
const t = i(e, r);
|
|
42
|
+
return y({
|
|
65
43
|
queryKey: t,
|
|
66
|
-
queryFn: async ({ queryKey:
|
|
67
|
-
...
|
|
44
|
+
queryFn: async ({ queryKey: o }) => u(e, o[1], s),
|
|
45
|
+
...n
|
|
68
46
|
});
|
|
69
47
|
}
|
|
70
|
-
function
|
|
71
|
-
const s =
|
|
72
|
-
return
|
|
48
|
+
function U(e, r, n) {
|
|
49
|
+
const s = i(e, r);
|
|
50
|
+
return a({
|
|
73
51
|
queryKey: s,
|
|
74
|
-
queryFn: async ({ queryKey: t }) =>
|
|
75
|
-
...
|
|
52
|
+
queryFn: async ({ queryKey: t }) => u(e, t[1]),
|
|
53
|
+
...n
|
|
76
54
|
});
|
|
77
55
|
}
|
|
78
|
-
function
|
|
79
|
-
const s =
|
|
80
|
-
return
|
|
56
|
+
function g(e, r, n) {
|
|
57
|
+
const s = i(e, r);
|
|
58
|
+
return a({
|
|
81
59
|
queryKey: s,
|
|
82
|
-
queryFn: async ({ queryKey: t }) =>
|
|
83
|
-
...
|
|
60
|
+
queryFn: async ({ queryKey: t }) => u(e, t[1], R),
|
|
61
|
+
...n
|
|
84
62
|
});
|
|
85
63
|
}
|
|
86
|
-
const
|
|
64
|
+
const f = process.env.NEXT_PUBLIC_GRAPHQL_URL, d = process.env.NEXT_PUBLIC_API_TOKEN, G = {
|
|
87
65
|
credentials: "include",
|
|
88
66
|
mode: "cors",
|
|
89
67
|
fetch,
|
|
90
68
|
headers: {
|
|
91
|
-
Authorization: `Bearer ${
|
|
69
|
+
Authorization: `Bearer ${d}`
|
|
92
70
|
}
|
|
93
|
-
},
|
|
94
|
-
const
|
|
95
|
-
function s(t,
|
|
96
|
-
return
|
|
71
|
+
}, H = (e = f, r = G) => {
|
|
72
|
+
const n = new c(e, r);
|
|
73
|
+
function s(t, o) {
|
|
74
|
+
return u(t, o, n);
|
|
97
75
|
}
|
|
98
76
|
return {
|
|
99
77
|
queryGql: s,
|
|
100
|
-
client:
|
|
78
|
+
client: n
|
|
101
79
|
};
|
|
102
80
|
};
|
|
103
81
|
export {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
i as
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
82
|
+
A as DirectusQueryLogger,
|
|
83
|
+
R as defaultGraphqlRequestAdmin,
|
|
84
|
+
T as defaultGraphqlRequestClient,
|
|
85
|
+
i as getQueryValues,
|
|
86
|
+
H as initDirectusQuery,
|
|
87
|
+
u as queryGql,
|
|
88
|
+
v as useGqlQuery,
|
|
89
|
+
U as useSuspenseGqlQuery,
|
|
90
|
+
g as useSuspenseGqlQueryAdmin
|
|
111
91
|
};
|
package/lib/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RequestConfig } from 'node_modules/graphql-request/build/legacy/helpers/types';
|
|
2
|
+
|
|
2
3
|
export declare const GRAPHQL_ENDPOINT: string;
|
|
3
4
|
export declare const AUTH_TOKEN: string;
|
|
4
5
|
export declare const defaultConfig: RequestConfig;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
useErrorBoundary: boolean;
|
|
7
|
-
}, client?: GraphQLClient): UseQueryResult<TResult>;
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { GraphQLClient, Variables } from 'graphql-request';
|
|
4
|
+
|
|
5
|
+
export declare function useGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: Omit<UseQueryOptions<TResult, Error, TResult>, 'queryKey' | 'queryFn'>, client?: GraphQLClient): UseQueryResult<TResult, Error>;
|
|
8
6
|
export default useGqlQuery;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { QueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { Variables } from 'graphql-request';
|
|
4
|
+
|
|
4
5
|
export declare function useSuspenseGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: Omit<QueryOptions, 'queryFn'> & {
|
|
5
6
|
enabled: boolean;
|
|
6
7
|
useErrorBoundary: boolean;
|
package/lib/init.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GraphQLClient } from 'graphql-request';
|
|
3
|
-
import
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { GraphQLClient, Variables } from 'graphql-request';
|
|
3
|
+
import { RequestConfig } from 'node_modules/graphql-request/build/legacy/helpers/types';
|
|
4
|
+
|
|
4
5
|
declare const initDirectusQuery: (graphqlEndPoint?: string, requestConfig?: RequestConfig) => {
|
|
5
|
-
queryGql: <TResult, TVariables extends
|
|
6
|
+
queryGql: <TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables) => Promise<TResult>;
|
|
6
7
|
client: GraphQLClient;
|
|
7
8
|
};
|
|
8
9
|
export default initDirectusQuery;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TGQLQueryContextProps, TGQLQueryProviderProps } from './interface';
|
|
2
|
+
|
|
3
|
+
declare const useGql: () => TGQLQueryContextProps;
|
|
4
|
+
export { useGql };
|
|
5
|
+
export declare function GqlQueryContextProvider({ children, client }: Readonly<TGQLQueryProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { GraphQLClient, Variables } from 'graphql-request';
|
|
4
|
+
import { default as React } from 'react';
|
|
5
|
+
|
|
6
|
+
export type TGQLQueryProviderProps = {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
client: GraphQLClient;
|
|
9
|
+
};
|
|
10
|
+
export type TGQLQueryContextProps = {
|
|
11
|
+
useGqlQuery: <TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables) => UseQueryResult;
|
|
12
|
+
};
|
package/lib/query.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { Variables } from 'graphql-request';
|
|
3
|
+
|
|
4
|
+
export declare function queryGql<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables, client?: import('graphql-request').GraphQLClient): Promise<TResult>;
|
|
4
5
|
export declare function getQueryValues<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables): readonly [string, TVariables | undefined];
|
package/lib/request.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { GraphQLClient } from 'graphql-request';
|
|
3
|
+
|
|
3
4
|
export declare const grapqhlGetDefaultEndpoint: () => string;
|
|
4
5
|
export declare const grapqhlGetDefaultAdminEndpoint: () => string;
|
|
5
6
|
export declare const graphqlRequestClient: GraphQLClient;
|
package/logger.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const logger: import(
|
|
1
|
+
export declare const logger: import('../../../stack/logger/src/index.ts').Logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-query",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -24,11 +24,16 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@graphql-codegen/cli": "^5.0.3",
|
|
26
26
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
27
|
-
"@okam/core-lib": "1.
|
|
27
|
+
"@okam/core-lib": "1.17.0",
|
|
28
28
|
"@okam/logger": "1.1.0",
|
|
29
29
|
"@tanstack/react-query": "^5.62.3",
|
|
30
30
|
"graphql-request": "^7.1.2",
|
|
31
|
-
"radashi": "^12.3.0"
|
|
32
|
-
|
|
31
|
+
"radashi": "^12.3.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"react": "^19.0.0"
|
|
33
38
|
}
|
|
34
39
|
}
|
package/server.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './lib/query';
|
|
2
|
+
export { default as initDirectusQuery } from './lib/init';
|
|
3
|
+
export { logger as DirectusQueryLogger } from './logger';
|
|
4
|
+
export { graphqlRequestClient as defaultGraphqlRequestClient, graphqlRequestAdmin as defaultGraphqlRequestAdmin, } from './lib/request';
|