Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: don't repeat InternalIDField definition #6254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/schema/v2/object_identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ export const InternalIDFields: GraphQLFieldConfigMap<any, ResolverContext> = {
},
}

export const InternalIDField: GraphQLFieldConfigMap<any, ResolverContext> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion / non-blocking: Can we also reuse this definition within the GraphQLFieldConfigMaps defined above?

For example:

export const InternalIDFields: GraphQLFieldConfigMap<any, ResolverContext> = {
  id: GlobalIDField,
  internalID: InternalIDField
}

internalID: {
description: "A type-specific ID likely used as a database ID.",
type: new GraphQLNonNull(GraphQLID),
resolve: ({ id }) => id,
},
}

export default {
GlobalIDField,
GravityIDFields,
Expand Down
7 changes: 2 additions & 5 deletions src/schema/v2/viewingRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -68,11 +69,7 @@ export const ViewingRoomType = new GraphQLObjectType<any, ResolverContext>({
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion / non-blocking: Since this is just a single field and we're not spreading multiple fields, pulling in the specific field definition might be fine too:

internalID: InternalIDField

artworkIDs: {
type: new GraphQLNonNull(new GraphQLList(GraphQLString)),
resolve: ({ artwork_ids }) => artwork_ids,
Expand Down
7 changes: 2 additions & 5 deletions src/schema/v2/viewingRoomArtwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GraphQLObjectType,
} from "graphql"
import { ResolverContext } from "types/graphql"
import { InternalIDField } from "./object_identification"

export const ViewingRoomArtworkType = new GraphQLObjectType<
any,
Expand All @@ -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,
Expand Down
14 changes: 3 additions & 11 deletions src/schema/v2/viewingRoomSubsection.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
},
Expand Down