@okam/directus-query 1.3.0 → 1.4.1
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 +57 -0
- package/README.md +44 -0
- package/index.js +1 -1
- package/index.mjs +2 -2
- package/lib/hooks/use-suspense-graphql.d.ts +2 -2
- package/package.json +19 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
## 1.3.0 (2024-11-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🚀 Features
|
|
5
|
+
|
|
6
|
+
- **directus-query:** adding server side fallback for graphql endpoint ([f89d662](https://github.com/OKAMca/stack/commit/f89d662))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ❤️ Thank You
|
|
10
|
+
|
|
11
|
+
- Yan Morin
|
|
12
|
+
|
|
13
|
+
## 1.2.0 (2024-10-04)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- updates & cleanup packages and dependancies ([#210](https://github.com/OKAMca/stack/pull/210))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### ❤️ Thank You
|
|
22
|
+
|
|
23
|
+
- Marie-Maxime Tanguay @marie-maxime
|
|
24
|
+
|
|
25
|
+
## 1.1.1 (2024-07-09)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### 🩹 Fixes
|
|
29
|
+
|
|
30
|
+
- **publish:** add building packages step to workflow ([c9ce442](https://github.com/OKAMca/stack/commit/c9ce442))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### ❤️ Thank You
|
|
34
|
+
|
|
35
|
+
- Jérôme Trottier
|
|
36
|
+
|
|
37
|
+
## 1.1.0 (2024-06-28)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### 🚀 Features
|
|
41
|
+
|
|
42
|
+
- add new libs ([#71](https://github.com/OKAMca/stack/pull/71))
|
|
43
|
+
|
|
44
|
+
- add gql query ([#73](https://github.com/OKAMca/stack/pull/73))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### 🩹 Fixes
|
|
48
|
+
|
|
49
|
+
- publishing for new libs ([#125](https://github.com/OKAMca/stack/pull/125))
|
|
50
|
+
|
|
51
|
+
- **directus-query:** fix initDirectusQuery name ([#129](https://github.com/OKAMca/stack/pull/129))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### ❤️ Thank You
|
|
55
|
+
|
|
56
|
+
- Marie-Maxime Tanguay @marie-maxime
|
|
57
|
+
- yanmorinokamca @yanmorinokamca
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# directus-query
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
# Usage with NextJS AppRouter
|
|
6
|
+
|
|
7
|
+
To create a new client, first create a new file with the following content:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { initDirectusQuery } from '@okam/directus-query'
|
|
11
|
+
|
|
12
|
+
const queryClient = initDirectusQuery('https://example.com/api', {
|
|
13
|
+
credentials: 'include',
|
|
14
|
+
mode: 'cors',
|
|
15
|
+
fetch,ù
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export default queryClient
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then, you can use the client to query data from Directus:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const variables = {id: 1}
|
|
28
|
+
const data = await queryClient.queryGql(DOCUMENT, variables)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Default Environment Variables
|
|
32
|
+
Those environment variables are used in graphqlRequestClient (queryGql, useSuspenseGqlQuery) and graphqlRequestAdmin (useSuspenseGqlQueryAdmin)
|
|
33
|
+
|
|
34
|
+
### Server/Client
|
|
35
|
+
```
|
|
36
|
+
NEXT_SERVER_GRAPHQL_URL=http://server.internal/graphql/ # server side only
|
|
37
|
+
NEXT_PUBLIC_GRAPHQL_URL=https://server.okam.one/graphql/ # server fallback and client side
|
|
38
|
+
NEXT_PUBLIC_API_TOKEN=abcdef
|
|
39
|
+
```
|
|
40
|
+
### Admin
|
|
41
|
+
```
|
|
42
|
+
NEXT_GRAPHQL_URL_ADMIN=http://server-admin.okam.one/graphql/ # server side only
|
|
43
|
+
# admin request use the same token NEXT_PUBLIC_API_TOKEN
|
|
44
|
+
```
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@tanstack/react-query"),p=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@tanstack/react-query"),p=require("radashi"),l=require("graphql-request");class u{constructor(s,e,r){this.nameSpace="[STACK]",this.suppressConsole=!1,this.env=process.env.NODE_ENV,this.nameSpace=s??this.nameSpace,this.suppressConsole=r??this.suppressConsole,this.logger=e??this.internalLogger}internalLogger(s,e,r){this.env!=="production"&&console[e||"log"](`${this.nameSpace} ${s}`.trimStart(),r??"")}setLogger(s){this.logger=(e,r,t)=>{this.suppressConsole&&this.internalLogger(e,r,t),s(e,r,t)}}static getInstance(){return u.instance||(u.instance=new u),u.instance}log(s,e,r){this.logger(s,e,r)}}u.getInstance();const h=(n,s,e=!1)=>{const r=new u(n,s,e);return r.log("Logger initialized","info"),r},y=h("[DirectusQuery]"),g=process.env.NEXT_PUBLIC_GRAPHQL_URL,q=process.env.NEXT_SERVER_GRAPHQL_URL,Q=process.env.NEXT_GRAPHQL_URL_ADMIN,_=process.env.NEXT_PUBLIC_API_TOKEN??"",N=process.env.NEXT_PUBLIC_API_TOKEN,E=new l.GraphQLClient(q||g,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${_}`}}),L=new l.GraphQLClient(Q,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${N}`}});new o.QueryClient({queryCache:new o.QueryCache({onError:n=>{y.log("QueryClient Error","error",{error:n})}}),defaultOptions:{queries:{staleTime:5*1e3}}});function i(n,s,e=E){return e.request(n,{...s})}function c(n,s){return[p.get(n,"definitions.0.name.value"),s]}function A(n,s,e,r){const t=c(n,s);return o.useQuery({queryKey:t,queryFn:async({queryKey:a})=>i(n,a[1],r),...e})}function T(n,s,e){const r=c(n,s);return o.useSuspenseQuery({queryKey:r,queryFn:async({queryKey:t})=>i(n,t[1]),...e})}function P(n,s,e){const r=c(n,s);return o.useSuspenseQuery({queryKey:r,queryFn:async({queryKey:t})=>i(n,t[1],L),...e})}const G=process.env.NEXT_PUBLIC_GRAPHQL_URL,d=process.env.NEXT_PUBLIC_API_TOKEN,f={credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${d}`}},C=(n=G,s=f)=>{const e=new l.GraphQLClient(n,s);function r(t,a){return i(t,a,e)}return{queryGql:r,client:e}};exports.DirectusQueryLogger=y;exports.getQueryValues=c;exports.initDirectusQuery=C;exports.queryGql=i;exports.useGqlQuery=A;exports.useSuspenseGqlQuery=T;exports.useSuspenseGqlQueryAdmin=P;
|
package/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { QueryClient as p, QueryCache as h, useQuery as _, useSuspenseQuery as l } from "@tanstack/react-query";
|
|
2
|
-
import { get as g } from "
|
|
2
|
+
import { get as g } from "radashi";
|
|
3
3
|
import { GraphQLClient as c } from "graphql-request";
|
|
4
4
|
class o {
|
|
5
5
|
constructor(n, e, s) {
|
|
6
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
7
|
}
|
|
8
8
|
internalLogger(n, e, s) {
|
|
9
|
-
this.env !== "production" && console[e || "log"](`${this.nameSpace} ${n}`.trimStart(), s);
|
|
9
|
+
this.env !== "production" && console[e || "log"](`${this.nameSpace} ${n}`.trimStart(), s ?? "");
|
|
10
10
|
}
|
|
11
11
|
setLogger(n) {
|
|
12
12
|
this.logger = (e, s, t) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
2
|
import type { QueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import type { Variables } from 'graphql-request';
|
|
4
|
-
export declare function useSuspenseGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: QueryOptions & {
|
|
4
|
+
export declare function useSuspenseGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: Omit<QueryOptions, 'queryFn'> & {
|
|
5
5
|
enabled: boolean;
|
|
6
6
|
useErrorBoundary: boolean;
|
|
7
7
|
}): UseSuspenseQueryResult<TResult>;
|
|
8
|
-
export declare function useSuspenseGqlQueryAdmin<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: QueryOptions): UseSuspenseQueryResult<TResult>;
|
|
8
|
+
export declare function useSuspenseGqlQueryAdmin<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: Omit<QueryOptions, 'queryFn'>): UseSuspenseQueryResult<TResult>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-query",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"import":
|
|
9
|
-
|
|
8
|
+
"import": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"default": "./index.js"
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
},
|
|
12
18
|
"publishConfig": {
|
|
@@ -14,5 +20,15 @@
|
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
16
22
|
"url": "https://github.com/OKAMca/stack.git"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@graphql-codegen/cli": "^5.0.3",
|
|
26
|
+
"@graphql-typed-document-node/core": "3.2.0",
|
|
27
|
+
"@okam/core-lib": "1.16.0",
|
|
28
|
+
"@okam/logger": "1.1.0",
|
|
29
|
+
"@tanstack/react-query": "^5.62.3",
|
|
30
|
+
"graphql-request": "^7.1.2",
|
|
31
|
+
"radashi": "^12.3.0",
|
|
32
|
+
"react": "18.3.1"
|
|
17
33
|
}
|
|
18
34
|
}
|