@laioutr/app-hygraph 1.2.0 → 1.3.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/dist/codegen/index.d.mts +18 -0
- package/dist/codegen/index.mjs +41 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/queries/index.d.mts +1 -0
- package/dist/queries/index.mjs +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/server/client/hygraph.d.ts +3 -7
- package/dist/runtime/server/client/hygraph.js +2 -2
- package/dist/runtime/server/hygraph-utils/mediaMapper.d.ts +6 -2
- package/dist/runtime/server/hygraph-utils/mediaMapper.js +2 -2
- package/dist/runtime/server/middleware/defineHygraph.js +3 -1
- package/dist/runtime/server/types/hygraph.d.ts +18 -0
- package/dist/runtime/server/types/hygraph.js +0 -0
- package/package.json +33 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CodegenConfig } from '@graphql-codegen/cli';
|
|
2
|
+
|
|
3
|
+
interface HygraphCodegenOptions {
|
|
4
|
+
/** Hygraph Content API endpoint URL. Defaults to process.env.HYGRAPH_CONTENT_API_URL */
|
|
5
|
+
schemaUrl?: string;
|
|
6
|
+
/** Hygraph API token. Defaults to process.env.HYGRAPH_TOKEN */
|
|
7
|
+
token?: string;
|
|
8
|
+
/** Glob pattern for GraphQL document files. Defaults to 'src/runtime/server/queries/**\/*.ts' */
|
|
9
|
+
documents?: string;
|
|
10
|
+
/** Output file path for generated types. Defaults to 'src/runtime/server/generated/graphql.ts' */
|
|
11
|
+
outputPath?: string;
|
|
12
|
+
/** Additional custom scalar mappings (merged with Hygraph defaults) */
|
|
13
|
+
scalars?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
declare const defineHygraphCodegen: (options?: HygraphCodegenOptions) => CodegenConfig;
|
|
16
|
+
|
|
17
|
+
export { defineHygraphCodegen };
|
|
18
|
+
export type { HygraphCodegenOptions };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const DEFAULT_SCALARS = {
|
|
2
|
+
DateTime: "string",
|
|
3
|
+
Date: "string",
|
|
4
|
+
Json: "Record<string, unknown>",
|
|
5
|
+
Long: "number",
|
|
6
|
+
RichTextAST: "Record<string, unknown>",
|
|
7
|
+
Hex: "string",
|
|
8
|
+
RGBAHue: "string",
|
|
9
|
+
RGBATransparency: "number"
|
|
10
|
+
};
|
|
11
|
+
const defineHygraphCodegen = (options = {}) => {
|
|
12
|
+
const schemaUrl = options.schemaUrl ?? process.env.HYGRAPH_CONTENT_API_URL;
|
|
13
|
+
const token = options.token ?? process.env.HYGRAPH_TOKEN;
|
|
14
|
+
const documents = options.documents ?? "src/runtime/server/queries/**/*.ts";
|
|
15
|
+
const outputPath = options.outputPath ?? "src/runtime/server/generated/graphql.ts";
|
|
16
|
+
return {
|
|
17
|
+
overwrite: true,
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
[schemaUrl]: {
|
|
21
|
+
headers: {
|
|
22
|
+
Authorization: `Bearer ${token}`
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
documents,
|
|
28
|
+
generates: {
|
|
29
|
+
[outputPath]: {
|
|
30
|
+
plugins: ["typescript", "typescript-operations"],
|
|
31
|
+
config: {
|
|
32
|
+
skipTypename: true,
|
|
33
|
+
maybeValue: "T | null",
|
|
34
|
+
scalars: { ...DEFAULT_SCALARS, ...options.scalars }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { defineHygraphCodegen };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AssetFragment } from '../../dist/runtime/server/queries/asset.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AssetFragment } from '../../dist/runtime/server/queries/asset.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { hygraphClientFactory } from './server/client/hygraph.js';
|
|
2
|
+
export { defineHygraph } from './server/middleware/defineHygraph.js';
|
|
3
|
+
export { mapHygraphMedia, filenameToAlt, stripFileExtension } from './server/hygraph-utils/mediaMapper.js';
|
|
4
|
+
export type { HygraphAsset, HygraphClientConfig, HygraphResponse } from './server/types/hygraph.js';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
message: string;
|
|
5
|
-
}>;
|
|
6
|
-
}
|
|
7
|
-
export declare const hygraphClientFactory: () => {
|
|
1
|
+
import type { HygraphClientConfig, HygraphResponse } from '../types/hygraph.js';
|
|
2
|
+
export type { HygraphResponse };
|
|
3
|
+
export declare const hygraphClientFactory: (explicitConfig?: HygraphClientConfig) => {
|
|
8
4
|
request: <TData = unknown>(query: string, variables?: unknown) => Promise<HygraphResponse<TData>>;
|
|
9
5
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
export const hygraphClientFactory = () => {
|
|
3
|
-
const config = useRuntimeConfig()["@laioutr/app-hygraph"];
|
|
2
|
+
export const hygraphClientFactory = (explicitConfig) => {
|
|
3
|
+
const config = explicitConfig ?? useRuntimeConfig()["@laioutr/app-hygraph"];
|
|
4
4
|
const request = async (query, variables = null) => {
|
|
5
5
|
const res = await fetch(config.contentApiUrl, {
|
|
6
6
|
method: "POST",
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { MediaImage } from '@laioutr-core/core-types/common';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HygraphAsset } from '../types/hygraph.js';
|
|
3
|
+
/** Remove the file extension from a file name. */
|
|
4
|
+
export declare const stripFileExtension: (fileName: string) => string;
|
|
5
|
+
/** Convert a file name to a readable alt text. */
|
|
6
|
+
export declare const filenameToAlt: (fileName: string) => string;
|
|
3
7
|
/**
|
|
4
8
|
* Map a Hygraph asset to a Media object.
|
|
5
9
|
*/
|
|
6
|
-
export declare const mapHygraphMedia: (asset:
|
|
10
|
+
export declare const mapHygraphMedia: (asset: HygraphAsset) => MediaImage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const stripFileExtension = (fileName) => fileName.replace(/\.[^.]+$/, "");
|
|
2
|
-
const filenameToAlt = (fileName) => stripFileExtension(fileName).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/^\w/, (c) => c.toUpperCase()).trim();
|
|
1
|
+
export const stripFileExtension = (fileName) => fileName.replace(/\.[^.]+$/, "");
|
|
2
|
+
export const filenameToAlt = (fileName) => stripFileExtension(fileName).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/^\w/, (c) => c.toUpperCase()).trim();
|
|
3
3
|
export const mapHygraphMedia = (asset) => ({
|
|
4
4
|
type: "image",
|
|
5
5
|
sources: [
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { defineOrchestr } from "#imports";
|
|
2
2
|
import { hygraphClientFactory } from "../client/hygraph.js";
|
|
3
3
|
export const defineHygraph = defineOrchestr.meta({
|
|
4
|
-
app: "@laioutr/app-hygraph"
|
|
4
|
+
app: "@laioutr/app-hygraph",
|
|
5
|
+
logoUrl: "/app-hygraph/logo.svg",
|
|
6
|
+
label: "Hygraph"
|
|
5
7
|
}).use(async (ctx, next) => next({ context: { hygraph: hygraphClientFactory() } }));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface HygraphAsset {
|
|
2
|
+
url: string;
|
|
3
|
+
fileName: string;
|
|
4
|
+
mimeType?: string | null;
|
|
5
|
+
width?: number | null;
|
|
6
|
+
height?: number | null;
|
|
7
|
+
handle: string;
|
|
8
|
+
}
|
|
9
|
+
export interface HygraphClientConfig {
|
|
10
|
+
contentApiUrl: string;
|
|
11
|
+
token: string;
|
|
12
|
+
}
|
|
13
|
+
export interface HygraphResponse<TData> {
|
|
14
|
+
data: TData;
|
|
15
|
+
errors?: Array<{
|
|
16
|
+
message: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laioutr/app-hygraph",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Laioutr Hygraph App",
|
|
5
5
|
"repository": "your-org/@laioutr/app-hygraph",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,18 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/types.d.mts",
|
|
11
11
|
"import": "./dist/module.mjs"
|
|
12
|
+
},
|
|
13
|
+
"./runtime": {
|
|
14
|
+
"types": "./dist/runtime/index.d.ts",
|
|
15
|
+
"import": "./dist/runtime/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./codegen": {
|
|
18
|
+
"types": "./dist/codegen/index.d.mts",
|
|
19
|
+
"import": "./dist/codegen/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./queries": {
|
|
22
|
+
"types": "./dist/queries/index.d.mts",
|
|
23
|
+
"import": "./dist/queries/index.mjs"
|
|
12
24
|
}
|
|
13
25
|
},
|
|
14
26
|
"main": "./dist/module.mjs",
|
|
@@ -16,6 +28,15 @@
|
|
|
16
28
|
"*": {
|
|
17
29
|
".": [
|
|
18
30
|
"./dist/types.d.mts"
|
|
31
|
+
],
|
|
32
|
+
"runtime": [
|
|
33
|
+
"./dist/runtime/index.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"codegen": [
|
|
36
|
+
"./dist/codegen/index.d.mts"
|
|
37
|
+
],
|
|
38
|
+
"queries": [
|
|
39
|
+
"./dist/queries/index.d.mts"
|
|
19
40
|
]
|
|
20
41
|
}
|
|
21
42
|
},
|
|
@@ -69,7 +90,17 @@
|
|
|
69
90
|
"@laioutr-core/canonical-types": ">=0.22.13",
|
|
70
91
|
"@laioutr-core/core-types": ">=0.28.8",
|
|
71
92
|
"@laioutr-core/frontend-core": ">=0.28.8",
|
|
72
|
-
"@laioutr-core/kit": ">=0.28.8"
|
|
93
|
+
"@laioutr-core/kit": ">=0.28.8",
|
|
94
|
+
"@graphql-codegen/cli": "^6.0.0",
|
|
95
|
+
"graphql": "^16.0.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"@graphql-codegen/cli": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"graphql": {
|
|
102
|
+
"optional": true
|
|
103
|
+
}
|
|
73
104
|
},
|
|
74
105
|
"engines": {
|
|
75
106
|
"node": ">=22.12.0",
|