@okam/directus-query 0.0.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/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib/hooks';
2
+ export * from './lib/query';
3
+ export { default as initDiretusQuery } from './lib/init';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@tanstack/react-query"),l=require("radash"),a=require("graphql-request"),y=process.env.NEXT_PUBLIC_GRAPHQL_URL,q=process.env.NEXT_GRAPHQL_URL_ADMIN,Q=process.env.NEXT_PUBLIC_API_TOKEN,_=process.env.NEXT_PUBLIC_API_TOKEN,A=new a.GraphQLClient(y,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${Q}`}}),N=new a.GraphQLClient(q,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${_}`}});new t.QueryClient({queryCache:new t.QueryCache({onError:e=>{console.error(e)}}),defaultOptions:{queries:{staleTime:5*1e3}}});function o(e,r,n=A){return n.request(e,{...r})}function c(e,r){return[l.get(e,"definitions.0.name.value"),r]}function p(e,r,n,s){const u=c(e,r);return t.useQuery({queryKey:u,queryFn:async({queryKey:i})=>o(e,i[1],s),...n})}function T(e,r,n){const s=c(e,r);return t.useSuspenseQuery({queryKey:s,queryFn:async({queryKey:u})=>o(e,u[1]),...n})}function G(e,r,n){const s=c(e,r);return t.useSuspenseQuery({queryKey:s,queryFn:async({queryKey:u})=>o(e,u[1],N),...n})}const d=process.env.NEXT_PUBLIC_GRAPHQL_URL,h=process.env.NEXT_PUBLIC_API_TOKEN,P={credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${h}`}},L=(e=d,r=P)=>{const n=new a.GraphQLClient(e,r);function s(u,i){return o(u,i,n)}return{queryGql:s,client:n}};exports.getQueryValues=c;exports.initDiretusQuery=L;exports.queryGql=o;exports.useGqlQuery=p;exports.useSuspenseGqlQuery=T;exports.useSuspenseGqlQueryAdmin=G;
package/index.mjs ADDED
@@ -0,0 +1,87 @@
1
+ import { QueryClient as l, QueryCache as _, useQuery as y, useSuspenseQuery as a } from "@tanstack/react-query";
2
+ import { get as q } from "radash";
3
+ import { GraphQLClient as c } from "graphql-request";
4
+ const N = process.env.NEXT_PUBLIC_GRAPHQL_URL, A = process.env.NEXT_GRAPHQL_URL_ADMIN, T = process.env.NEXT_PUBLIC_API_TOKEN, p = process.env.NEXT_PUBLIC_API_TOKEN, P = new c(N, {
5
+ credentials: "include",
6
+ mode: "cors",
7
+ fetch,
8
+ headers: {
9
+ Authorization: `Bearer ${T}`
10
+ }
11
+ }), Q = new c(A, {
12
+ credentials: "include",
13
+ mode: "cors",
14
+ fetch,
15
+ headers: {
16
+ Authorization: `Bearer ${p}`
17
+ }
18
+ });
19
+ new l({
20
+ queryCache: new _({
21
+ onError: (e) => {
22
+ console.error(e);
23
+ }
24
+ }),
25
+ defaultOptions: {
26
+ queries: {
27
+ staleTime: 5 * 1e3
28
+ }
29
+ }
30
+ });
31
+ function u(e, r, n = P) {
32
+ return n.request(e, {
33
+ ...r
34
+ });
35
+ }
36
+ function i(e, r) {
37
+ return [q(e, "definitions.0.name.value"), r];
38
+ }
39
+ function G(e, r, n, s) {
40
+ const t = i(e, r);
41
+ return y({
42
+ queryKey: t,
43
+ queryFn: async ({ queryKey: o }) => u(e, o[1], s),
44
+ ...n
45
+ });
46
+ }
47
+ function v(e, r, n) {
48
+ const s = i(e, r);
49
+ return a({
50
+ queryKey: s,
51
+ queryFn: async ({ queryKey: t }) => u(e, t[1]),
52
+ ...n
53
+ });
54
+ }
55
+ function C(e, r, n) {
56
+ const s = i(e, r);
57
+ return a({
58
+ queryKey: s,
59
+ queryFn: async ({ queryKey: t }) => u(e, t[1], Q),
60
+ ...n
61
+ });
62
+ }
63
+ const f = process.env.NEXT_PUBLIC_GRAPHQL_URL, E = process.env.NEXT_PUBLIC_API_TOKEN, L = {
64
+ credentials: "include",
65
+ mode: "cors",
66
+ fetch,
67
+ headers: {
68
+ Authorization: `Bearer ${E}`
69
+ }
70
+ }, R = (e = f, r = L) => {
71
+ const n = new c(e, r);
72
+ function s(t, o) {
73
+ return u(t, o, n);
74
+ }
75
+ return {
76
+ queryGql: s,
77
+ client: n
78
+ };
79
+ };
80
+ export {
81
+ i as getQueryValues,
82
+ R as initDiretusQuery,
83
+ u as queryGql,
84
+ G as useGqlQuery,
85
+ v as useSuspenseGqlQuery,
86
+ C as useSuspenseGqlQueryAdmin
87
+ };
@@ -0,0 +1,4 @@
1
+ import type { RequestConfig } from 'graphql-request/build/esm/types';
2
+ export declare const GRAPHQL_ENDPOINT: string;
3
+ export declare const AUTH_TOKEN: string;
4
+ export declare const defaultConfig: RequestConfig;
@@ -0,0 +1,2 @@
1
+ export * from './use-graphql';
2
+ export * from './use-suspense-graphql';
@@ -0,0 +1,8 @@
1
+ import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import type { QueryOptions, UseQueryResult } from '@tanstack/react-query';
3
+ import type { GraphQLClient, Variables } from 'graphql-request';
4
+ export declare function useGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: QueryOptions & {
5
+ enabled: boolean;
6
+ useErrorBoundary: boolean;
7
+ }, client?: GraphQLClient): UseQueryResult<TResult>;
8
+ export default useGqlQuery;
@@ -0,0 +1,8 @@
1
+ import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import type { QueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
3
+ import type { Variables } from 'graphql-request';
4
+ export declare function useSuspenseGqlQuery<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: QueryOptions & {
5
+ enabled: boolean;
6
+ useErrorBoundary: boolean;
7
+ }): UseSuspenseQueryResult<TResult>;
8
+ export declare function useSuspenseGqlQueryAdmin<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: QueryOptions): UseSuspenseQueryResult<TResult>;
package/lib/init.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import { GraphQLClient } from 'graphql-request';
3
+ import type { Variables } from 'graphql-request';
4
+ import type { RequestConfig } from 'graphql-request/build/esm/types';
5
+ declare const initDiretusQuery: (graphqlEndPoint?: string, requestConfig?: RequestConfig) => {
6
+ queryGql: <TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables | undefined) => Promise<TResult>;
7
+ client: GraphQLClient;
8
+ };
9
+ export default initDiretusQuery;
package/lib/query.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import type { Variables } from 'graphql-request';
3
+ export declare function queryGql<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables, client?: import("graphql-request").GraphQLClient): Promise<TResult>;
4
+ export declare function getQueryValues<TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables): readonly [string, TVariables | undefined];
@@ -0,0 +1,6 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import { GraphQLClient } from 'graphql-request';
3
+ export declare const graphqlRequestClient: GraphQLClient;
4
+ export declare const graphqlRequestAdmin: GraphQLClient;
5
+ export declare const queryClient: QueryClient;
6
+ export default graphqlRequestClient;
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@okam/directus-query",
3
+ "version": "0.0.1",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./index.mjs",
9
+ "require": "./index.js"
10
+ }
11
+ }
12
+ }