@laioutr/app-hygraph 1.5.0 → 1.6.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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/server/generated/graphql.d.ts +4 -1
- package/dist/runtime/server/hygraph-utils/locale.d.ts +11 -0
- package/dist/runtime/server/hygraph-utils/locale.js +12 -0
- package/dist/runtime/server/hygraph-utils/mediaMapper.d.ts +2 -2
- package/dist/runtime/server/hygraph-utils/mediaMapper.js +32 -14
- package/dist/runtime/server/orchestr/blog/blogCollectionBySlug.query.js +4 -2
- package/dist/runtime/server/orchestr/blog/blogCollectionBySlug.template.js +5 -2
- package/dist/runtime/server/orchestr/blog/blogCollectionPosts.link.js +5 -2
- package/dist/runtime/server/orchestr/blog/blogPostBySlug.query.js +4 -2
- package/dist/runtime/server/queries/blog.d.ts +4 -4
- package/dist/runtime/server/queries/blog.js +15 -9
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -8059,6 +8059,7 @@ export type BlogsQueryVariables = Exact<{
|
|
|
8059
8059
|
skip?: InputMaybe<Scalars['Int']['input']>;
|
|
8060
8060
|
first?: InputMaybe<Scalars['Int']['input']>;
|
|
8061
8061
|
collectionId?: InputMaybe<Scalars['ID']['input']>;
|
|
8062
|
+
locales: Array<Locale> | Locale;
|
|
8062
8063
|
}>;
|
|
8063
8064
|
export type BlogsQuery = {
|
|
8064
8065
|
blogs: Array<{
|
|
@@ -8086,6 +8087,7 @@ export type BlogsQuery = {
|
|
|
8086
8087
|
};
|
|
8087
8088
|
export type BlogPostBySlugQueryVariables = Exact<{
|
|
8088
8089
|
slug: Scalars['String']['input'];
|
|
8090
|
+
locales: Array<Locale> | Locale;
|
|
8089
8091
|
}>;
|
|
8090
8092
|
export type BlogPostBySlugQuery = {
|
|
8091
8093
|
blog?: {
|
|
@@ -8108,6 +8110,7 @@ export type BlogPostBySlugQuery = {
|
|
|
8108
8110
|
};
|
|
8109
8111
|
export type BlogCollectionBySlugQueryVariables = Exact<{
|
|
8110
8112
|
slug: Scalars['String']['input'];
|
|
8113
|
+
locales: Array<Locale> | Locale;
|
|
8111
8114
|
}>;
|
|
8112
8115
|
export type BlogCollectionBySlugQuery = {
|
|
8113
8116
|
blogCollection?: {
|
|
@@ -8117,7 +8120,7 @@ export type BlogCollectionBySlugQuery = {
|
|
|
8117
8120
|
} | null;
|
|
8118
8121
|
};
|
|
8119
8122
|
export type BlogCollectionsQueryVariables = Exact<{
|
|
8120
|
-
|
|
8123
|
+
locales: Array<Locale> | Locale;
|
|
8121
8124
|
}>;
|
|
8122
8125
|
export type BlogCollectionsQuery = {
|
|
8123
8126
|
blogCollections: Array<{
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Locale } from '../generated/graphql.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build the Hygraph `locales` argument from the request's clientEnv locale.
|
|
4
|
+
*
|
|
5
|
+
* The first entry is the requested locale; `Locale.En` is appended as fallback
|
|
6
|
+
* (since `en` is the system locale in Hygraph) so that documents which are not
|
|
7
|
+
* yet translated still resolve with their default-locale fields instead of
|
|
8
|
+
* returning null fields. If the requested locale is already `en`, no fallback
|
|
9
|
+
* is added.
|
|
10
|
+
*/
|
|
11
|
+
export declare const resolveHygraphLocales: (clientLocale: string) => Locale[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Locale } from "../generated/graphql.js";
|
|
2
|
+
const getMatchingLocales = (locale) => {
|
|
3
|
+
const validLocales = Object.values(Locale);
|
|
4
|
+
return locale.replace("_", "-").split("-").map((val) => val.toLowerCase()).filter((val) => validLocales.includes(val));
|
|
5
|
+
};
|
|
6
|
+
export const resolveHygraphLocales = (clientLocale) => {
|
|
7
|
+
const matchingLocales = getMatchingLocales(clientLocale);
|
|
8
|
+
if (matchingLocales.length === 0) {
|
|
9
|
+
return [Locale.En];
|
|
10
|
+
}
|
|
11
|
+
return [...matchingLocales, Locale.En];
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Media } from '@laioutr-core/core-types/common';
|
|
2
2
|
import type { HygraphAsset } from '../types/hygraph.js';
|
|
3
3
|
/** Remove the file extension from a file name. */
|
|
4
4
|
export declare const stripFileExtension: (fileName: string) => string;
|
|
@@ -7,4 +7,4 @@ export declare const filenameToAlt: (fileName: string) => string;
|
|
|
7
7
|
/**
|
|
8
8
|
* Map a Hygraph asset to a Media object.
|
|
9
9
|
*/
|
|
10
|
-
export declare const mapHygraphMedia: (asset: HygraphAsset) =>
|
|
10
|
+
export declare const mapHygraphMedia: (asset: HygraphAsset) => Media;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
export const stripFileExtension = (fileName) => fileName.replace(/\.[^.]+$/, "");
|
|
2
2
|
export const filenameToAlt = (fileName) => stripFileExtension(fileName).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/^\w/, (c) => c.toUpperCase()).trim();
|
|
3
|
-
export const mapHygraphMedia = (asset) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
export const mapHygraphMedia = (asset) => {
|
|
4
|
+
const mimeType = typeof asset.mimeType === "string" ? asset.mimeType : "";
|
|
5
|
+
if (mimeType.startsWith("video/")) {
|
|
6
|
+
return {
|
|
7
|
+
type: "video",
|
|
8
|
+
sources: [
|
|
9
|
+
{
|
|
10
|
+
provider: "hygraph",
|
|
11
|
+
src: asset.url,
|
|
12
|
+
width: asset.width ?? void 0,
|
|
13
|
+
height: asset.height ?? void 0,
|
|
14
|
+
format: mimeType.slice("video/".length)
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
alt: filenameToAlt(asset.fileName)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
type: "image",
|
|
22
|
+
sources: [
|
|
23
|
+
{
|
|
24
|
+
// SVGs are returned as none so Nuxt Image won't turn them into PNG file links.
|
|
25
|
+
provider: mimeType === "image/svg+xml" ? "none" : "hygraph",
|
|
26
|
+
src: asset.url,
|
|
27
|
+
width: asset.width ?? void 0,
|
|
28
|
+
height: asset.height ?? void 0,
|
|
29
|
+
responsive: "static"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
alt: filenameToAlt(asset.fileName)
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { BlogCollectionBySlug } from "@laioutr-core/canonical-types/blog";
|
|
2
2
|
import { blogCollectionToken } from "../../const/passthroughTokens.js";
|
|
3
|
+
import { resolveHygraphLocales } from "../../hygraph-utils/locale.js";
|
|
3
4
|
import { defineHygraph } from "../../middleware/defineHygraph.js";
|
|
4
5
|
import { BLOG_COLLECTION_BY_SLUG_QUERY } from "../../queries/blog.js";
|
|
5
6
|
export default defineHygraph.queryHandler({
|
|
6
7
|
implements: BlogCollectionBySlug,
|
|
7
|
-
run: async ({ context, input, passthrough }) => {
|
|
8
|
+
run: async ({ context, input, passthrough, clientEnv }) => {
|
|
8
9
|
const result = await context.hygraph.request(BLOG_COLLECTION_BY_SLUG_QUERY, {
|
|
9
|
-
slug: input.slug
|
|
10
|
+
slug: input.slug,
|
|
11
|
+
locales: resolveHygraphLocales(clientEnv.locale)
|
|
10
12
|
});
|
|
11
13
|
const collection = result.data.blogCollection;
|
|
12
14
|
if (!collection) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BlogCollectionBySlug } from "@laioutr-core/canonical-types/blog";
|
|
2
|
+
import { resolveHygraphLocales } from "../../hygraph-utils/locale.js";
|
|
2
3
|
import { defineHygraph } from "../../middleware/defineHygraph.js";
|
|
3
4
|
import { BLOG_COLLECTIONS_QUERY } from "../../queries/blog.js";
|
|
4
5
|
export default defineHygraph.queryTemplateProvider({
|
|
5
6
|
for: BlogCollectionBySlug,
|
|
6
|
-
run: async ({ context }) => {
|
|
7
|
-
const result = await context.hygraph.request(BLOG_COLLECTIONS_QUERY
|
|
7
|
+
run: async ({ context, clientEnv }) => {
|
|
8
|
+
const result = await context.hygraph.request(BLOG_COLLECTIONS_QUERY, {
|
|
9
|
+
locales: resolveHygraphLocales(clientEnv.locale)
|
|
10
|
+
});
|
|
8
11
|
return result.data.blogCollections.map((collection) => ({
|
|
9
12
|
input: { slug: collection.slug },
|
|
10
13
|
label: collection.title
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { BlogCollectionPostsLink } from "@laioutr-core/canonical-types/blog";
|
|
2
2
|
import { blogPostsToken } from "../../const/passthroughTokens.js";
|
|
3
|
+
import { resolveHygraphLocales } from "../../hygraph-utils/locale.js";
|
|
3
4
|
import { defineHygraph } from "../../middleware/defineHygraph.js";
|
|
4
5
|
import { BLOGS_QUERY } from "../../queries/blog.js";
|
|
5
6
|
export default defineHygraph.linkHandler({
|
|
6
7
|
implements: BlogCollectionPostsLink,
|
|
7
|
-
run: async ({ context, entityIds, pagination, passthrough }) => {
|
|
8
|
+
run: async ({ context, entityIds, pagination, passthrough, clientEnv }) => {
|
|
9
|
+
const locales = resolveHygraphLocales(clientEnv.locale);
|
|
8
10
|
const results = await Promise.all(
|
|
9
11
|
entityIds.map(
|
|
10
12
|
(id) => context.hygraph.request(BLOGS_QUERY, {
|
|
11
13
|
skip: pagination.offset,
|
|
12
14
|
first: pagination.limit,
|
|
13
|
-
collectionId: id
|
|
15
|
+
collectionId: id,
|
|
16
|
+
locales
|
|
14
17
|
})
|
|
15
18
|
)
|
|
16
19
|
);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { BlogPostBySlug, BlogPostBySlugNotFoundError } from "@laioutr-core/canonical-types/blog";
|
|
2
2
|
import { blogPostsToken } from "../../const/passthroughTokens.js";
|
|
3
|
+
import { resolveHygraphLocales } from "../../hygraph-utils/locale.js";
|
|
3
4
|
import { defineHygraph } from "../../middleware/defineHygraph.js";
|
|
4
5
|
import { BLOG_POST_BY_SLUG_QUERY } from "../../queries/blog.js";
|
|
5
6
|
export default defineHygraph.queryHandler({
|
|
6
7
|
implements: BlogPostBySlug,
|
|
7
|
-
run: async ({ context, input, passthrough }) => {
|
|
8
|
+
run: async ({ context, input, passthrough, clientEnv }) => {
|
|
8
9
|
const result = await context.hygraph.request(BLOG_POST_BY_SLUG_QUERY, {
|
|
9
|
-
slug: input.slug
|
|
10
|
+
slug: input.slug,
|
|
11
|
+
locales: resolveHygraphLocales(clientEnv.locale)
|
|
10
12
|
});
|
|
11
13
|
const post = result.data.blog;
|
|
12
14
|
if (!post) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const BLOGS_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query Blogs($skip: Int, $first: Int, $collectionId: ID) {\n blogs(skip: $skip
|
|
2
|
-
export declare const BLOG_POST_BY_SLUG_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query BlogPostBySlug($slug: String!) {\n blog(where: { slug: $slug }) {\n ...Blog\n }\n }\n";
|
|
3
|
-
export declare const BLOG_COLLECTION_BY_SLUG_QUERY = "\n #graphql\n query BlogCollectionBySlug($slug: String!) {\n blogCollection(where: { slug: $slug }) {\n id\n slug\n title\n }\n }\n";
|
|
4
|
-
export declare const BLOG_COLLECTIONS_QUERY = "\n #graphql\n query BlogCollections {\n blogCollections {\n slug\n title\n }\n }\n";
|
|
1
|
+
export declare const BLOGS_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query Blogs($skip: Int, $first: Int, $collectionId: ID, $locales: [Locale!]!) {\n blogs(\n skip: $skip\n first: $first\n orderBy: createdAt_DESC\n where: { blogCollection: { id: $collectionId } }\n locales: $locales\n ) {\n ...Blog\n }\n blogsConnection(where: { blogCollection: { id: $collectionId } }, locales: $locales) {\n aggregate {\n count\n }\n }\n }\n";
|
|
2
|
+
export declare const BLOG_POST_BY_SLUG_QUERY = "\n #graphql\n \n #graphql\n \n #graphql\n fragment Asset on Asset {\n url\n fileName\n mimeType\n width\n height\n handle\n }\n\n fragment Blog on Blog {\n id\n title\n slug\n content {\n html\n }\n image {\n ...Asset\n }\n publishedAt\n }\n\n query BlogPostBySlug($slug: String!, $locales: [Locale!]!) {\n blog(where: { slug: $slug }, locales: $locales) {\n ...Blog\n }\n }\n";
|
|
3
|
+
export declare const BLOG_COLLECTION_BY_SLUG_QUERY = "\n #graphql\n query BlogCollectionBySlug($slug: String!, $locales: [Locale!]!) {\n blogCollection(where: { slug: $slug }, locales: $locales) {\n id\n slug\n title\n }\n }\n";
|
|
4
|
+
export declare const BLOG_COLLECTIONS_QUERY = "\n #graphql\n query BlogCollections($locales: [Locale!]!) {\n blogCollections(locales: $locales) {\n slug\n title\n }\n }\n";
|
|
@@ -23,11 +23,17 @@ export const BLOGS_QUERY = (
|
|
|
23
23
|
`
|
|
24
24
|
#graphql
|
|
25
25
|
${BlogFragment}
|
|
26
|
-
query Blogs($skip: Int, $first: Int, $collectionId: ID) {
|
|
27
|
-
blogs(
|
|
26
|
+
query Blogs($skip: Int, $first: Int, $collectionId: ID, $locales: [Locale!]!) {
|
|
27
|
+
blogs(
|
|
28
|
+
skip: $skip
|
|
29
|
+
first: $first
|
|
30
|
+
orderBy: createdAt_DESC
|
|
31
|
+
where: { blogCollection: { id: $collectionId } }
|
|
32
|
+
locales: $locales
|
|
33
|
+
) {
|
|
28
34
|
...Blog
|
|
29
35
|
}
|
|
30
|
-
blogsConnection {
|
|
36
|
+
blogsConnection(where: { blogCollection: { id: $collectionId } }, locales: $locales) {
|
|
31
37
|
aggregate {
|
|
32
38
|
count
|
|
33
39
|
}
|
|
@@ -40,8 +46,8 @@ export const BLOG_POST_BY_SLUG_QUERY = (
|
|
|
40
46
|
`
|
|
41
47
|
#graphql
|
|
42
48
|
${BlogFragment}
|
|
43
|
-
query BlogPostBySlug($slug: String!) {
|
|
44
|
-
blog(where: { slug: $slug }) {
|
|
49
|
+
query BlogPostBySlug($slug: String!, $locales: [Locale!]!) {
|
|
50
|
+
blog(where: { slug: $slug }, locales: $locales) {
|
|
45
51
|
...Blog
|
|
46
52
|
}
|
|
47
53
|
}
|
|
@@ -51,8 +57,8 @@ export const BLOG_COLLECTION_BY_SLUG_QUERY = (
|
|
|
51
57
|
/* GraphQL */
|
|
52
58
|
`
|
|
53
59
|
#graphql
|
|
54
|
-
query BlogCollectionBySlug($slug: String!) {
|
|
55
|
-
blogCollection(where: { slug: $slug }) {
|
|
60
|
+
query BlogCollectionBySlug($slug: String!, $locales: [Locale!]!) {
|
|
61
|
+
blogCollection(where: { slug: $slug }, locales: $locales) {
|
|
56
62
|
id
|
|
57
63
|
slug
|
|
58
64
|
title
|
|
@@ -64,8 +70,8 @@ export const BLOG_COLLECTIONS_QUERY = (
|
|
|
64
70
|
/* GraphQL */
|
|
65
71
|
`
|
|
66
72
|
#graphql
|
|
67
|
-
query BlogCollections {
|
|
68
|
-
blogCollections {
|
|
73
|
+
query BlogCollections($locales: [Locale!]!) {
|
|
74
|
+
blogCollections(locales: $locales) {
|
|
69
75
|
slug
|
|
70
76
|
title
|
|
71
77
|
}
|