From ed3dc10f0c1563ffa83379ab8fb32685881a237c Mon Sep 17 00:00:00 2001 From: Nikita Skalkin Date: Thu, 21 Nov 2024 10:24:12 +0100 Subject: [PATCH] refactor: don't repeat InternalIDField definition --- src/schema/v2/object_identification.ts | 8 ++++++++ src/schema/v2/viewingRoom.ts | 7 ++----- src/schema/v2/viewingRoomArtwork.ts | 7 ++----- src/schema/v2/viewingRoomSubsection.ts | 14 +++----------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/schema/v2/object_identification.ts b/src/schema/v2/object_identification.ts index 19f17fe4f2..bb4b6fa07c 100644 --- a/src/schema/v2/object_identification.ts +++ b/src/schema/v2/object_identification.ts @@ -245,6 +245,14 @@ export const InternalIDFields: GraphQLFieldConfigMap = { }, } +export const InternalIDField: GraphQLFieldConfigMap = { + internalID: { + description: "A type-specific ID likely used as a database ID.", + type: new GraphQLNonNull(GraphQLID), + resolve: ({ id }) => id, + }, +} + export default { GlobalIDField, GravityIDFields, diff --git a/src/schema/v2/viewingRoom.ts b/src/schema/v2/viewingRoom.ts index b717ecfe2b..80f0413864 100644 --- a/src/schema/v2/viewingRoom.ts +++ b/src/schema/v2/viewingRoom.ts @@ -22,6 +22,7 @@ import { dateRange } from "lib/date" import { GravityARImageType } from "./GravityARImageType" import { ViewingRoomSubsectionType } from "./viewingRoomSubsection" import { ViewingRoomArtworkType } from "./viewingRoomArtwork" +import { InternalIDField } from "./object_identification" const LocaleEnViewingRoomRelativeShort = "en-viewing-room-relative-short" defineCustomLocale(LocaleEnViewingRoomRelativeShort, { @@ -68,11 +69,7 @@ export const ViewingRoomType = new GraphQLObjectType({ const { PartnerArtworks } = require("schema/v2/partner/partnerArtworks") return { - internalID: { - description: "A type-specific ID likely used as a database ID.", - type: new GraphQLNonNull(GraphQLID), - resolve: ({ id }) => id, - }, + ...InternalIDField, artworkIDs: { type: new GraphQLNonNull(new GraphQLList(GraphQLString)), resolve: ({ artwork_ids }) => artwork_ids, diff --git a/src/schema/v2/viewingRoomArtwork.ts b/src/schema/v2/viewingRoomArtwork.ts index 8739b0f79a..e51d5b2ab6 100644 --- a/src/schema/v2/viewingRoomArtwork.ts +++ b/src/schema/v2/viewingRoomArtwork.ts @@ -5,6 +5,7 @@ import { GraphQLObjectType, } from "graphql" import { ResolverContext } from "types/graphql" +import { InternalIDField } from "./object_identification" export const ViewingRoomArtworkType = new GraphQLObjectType< any, @@ -13,11 +14,7 @@ export const ViewingRoomArtworkType = new GraphQLObjectType< name: "ViewingRoomArtwork", fields: () => { return { - internalID: { - description: "A type-specific ID likely used as a database ID.", - type: new GraphQLNonNull(GraphQLID), - resolve: ({ id }) => id, - }, + ...InternalIDField, artworkID: { type: new GraphQLNonNull(GraphQLID), resolve: ({ artwork_id }) => artwork_id, diff --git a/src/schema/v2/viewingRoomSubsection.ts b/src/schema/v2/viewingRoomSubsection.ts index 19a2c37251..8630f9e961 100644 --- a/src/schema/v2/viewingRoomSubsection.ts +++ b/src/schema/v2/viewingRoomSubsection.ts @@ -1,11 +1,7 @@ -import { - GraphQLID, - GraphQLNonNull, - GraphQLObjectType, - GraphQLString, -} from "graphql" +import { GraphQLObjectType, GraphQLString } from "graphql" import { ResolverContext } from "types/graphql" import { GravityARImageType } from "./GravityARImageType" +import { InternalIDField } from "./object_identification" export const ViewingRoomSubsectionType = new GraphQLObjectType< any, @@ -14,11 +10,7 @@ export const ViewingRoomSubsectionType = new GraphQLObjectType< name: "ViewingRoomSubsection", fields: () => { return { - internalID: { - description: "A type-specific ID likely used as a database ID.", - type: new GraphQLNonNull(GraphQLID), - resolve: ({ id }) => id, - }, + ...InternalIDField, body: { type: GraphQLString, },