Skip to content

Commit a802bb4

Browse files
authored
Merge pull request #567 from NDLANO/subject-image-copyright
Add ImageLicense to SubjectPageVisualElement
2 parents edb59e0 + 784e45a commit a802bb4

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/api/imageApi.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
IImageMetaInformationV3DTO,
1313
ISearchResultV3DTO,
1414
} from "@ndla/types-backend/image-api";
15-
import { GQLQueryImageSearchArgs } from "../types/schema";
15+
import { GQLImageLicense, GQLQueryImageSearchArgs } from "../types/schema";
1616
import { fetch, resolveJson } from "../utils/apiHelpers";
1717

1818
export async function fetchImage(imageId: string, context: Context): Promise<IImageMetaInformationV2DTO | null> {
@@ -51,3 +51,14 @@ export function convertToSimpleImage(image: IImageMetaInformationV2DTO) {
5151
copyright: image.copyright,
5252
};
5353
}
54+
55+
export function convertToImageLicense(imageMeta: IImageMetaInformationV3DTO): GQLImageLicense {
56+
return {
57+
id: imageMeta.id,
58+
title: imageMeta.title.title,
59+
src: imageMeta.image.imageUrl,
60+
altText: imageMeta.alttext.alttext,
61+
contentType: imageMeta.image.contentType,
62+
copyright: imageMeta.copyright,
63+
};
64+
}

src/resolvers/subjectResolvers.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*
77
*/
88

9-
import { ISubjectPageDTO } from "@ndla/types-backend/frontpage-api";
9+
import { ISubjectPageDTO, IVisualElementDTO } from "@ndla/types-backend/frontpage-api";
1010
import { Node } from "@ndla/types-taxonomy";
1111
import {
12+
GQLImageLicense,
1213
GQLQuerySubjectArgs,
1314
GQLQuerySubjectCollectionArgs,
1415
GQLSubject,
@@ -17,6 +18,8 @@ import {
1718
} from "../types/schema";
1819
import { filterMissingArticles } from "../utils/articleHelpers";
1920
import { fetchCompetenceGoalSetCodes } from "../api/searchApi";
21+
import { fetchImageV3 } from "../api";
22+
import { convertToImageLicense } from "../api/imageApi";
2023

2124
export const Query = {
2225
async subject(_: any, { id }: GQLQuerySubjectArgs, context: ContextWithLoaders): Promise<Node> {
@@ -117,4 +120,16 @@ export const resolvers = {
117120
);
118121
},
119122
},
123+
SubjectPageVisualElement: {
124+
async imageLicense(
125+
visualElement: IVisualElementDTO,
126+
_: any,
127+
context: ContextWithLoaders,
128+
): Promise<GQLImageLicense | undefined> {
129+
const imageId = parseInt(visualElement.url.split("/").pop() ?? "");
130+
if (isNaN(imageId)) return undefined;
131+
const image = await fetchImageV3(imageId, context);
132+
return convertToImageLicense(image);
133+
},
134+
},
120135
};

src/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ export const typeDefs = gql`
809809
type: String!
810810
url: String!
811811
alt: String
812+
imageLicense: ImageLicense
812813
}
813814
814815
type SubjectPageAbout {

src/types/schema.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,7 @@ export type GQLSubjectPageBanner = {
19181918
export type GQLSubjectPageVisualElement = {
19191919
__typename?: 'SubjectPageVisualElement';
19201920
alt?: Maybe<Scalars['String']['output']>;
1921+
imageLicense?: Maybe<GQLImageLicense>;
19211922
type: Scalars['String']['output'];
19221923
url: Scalars['String']['output'];
19231924
};
@@ -3898,6 +3899,7 @@ export type GQLSubjectPageBannerResolvers<ContextType = any, ParentType extends
38983899

38993900
export type GQLSubjectPageVisualElementResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['SubjectPageVisualElement'] = GQLResolversParentTypes['SubjectPageVisualElement']> = {
39003901
alt?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
3902+
imageLicense?: Resolver<Maybe<GQLResolversTypes['ImageLicense']>, ParentType, ContextType>;
39013903
type?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
39023904
url?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
39033905
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;

0 commit comments

Comments
 (0)