Skip to content

Commit

Permalink
fix: properly transform CommerceDate
Browse files Browse the repository at this point in the history
  • Loading branch information
MounirDhahri committed Dec 1, 2023
1 parent 36bfa5f commit 3b81699
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 6 additions & 1 deletion _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4535,7 +4535,12 @@ type CommerceFulfillment {
# A tz database time zone, otherwise falls back to "X-TIMEZONE" header. See http://www.iana.org/time-zones, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezone: String
): String!
estimatedDelivery: CommerceDate
estimatedDelivery(
format: String

# A tz database time zone, otherwise falls back to "X-TIMEZONE" header. See http://www.iana.org/time-zones, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezone: String
): String
id: ID!
internalID: ID!
notes: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ const originalSchema = new GraphQLSchema({
type: new GraphQLObjectType({
name: "SomeType",
fields: {
someDateField: {
someCommerceDateTimeField: {
type: new GraphQLScalarType({
name: "CommerceDateTime",
serialize: (x) => x,
}),
},
someCommerceDateField: {
type: new GraphQLScalarType({
name: "CommerceDate",
serialize: (x) => x,
}),
},
},
}),
},
Expand All @@ -41,20 +47,23 @@ describe("ReplaceCommerceDateTimeType", () => {
source: gql`
query {
someRootField {
someDateField(format: "[The year is] YYYY")
someCommerceDateTimeField(format: "[The year is] YYYY")
someCommerceDateField(format: "[The year is] YYYY")
}
}
`,
rootValue: {
someRootField: {
someDateField: "2019-07-16T19:39:10.001Z",
someCommerceDateTimeField: "2019-07-16T19:39:10.001Z",
someCommerceDateField: "2020-09-16T19:39:10.001Z",
},
},
contextValue: {},
})
expect(data).toEqual({
someRootField: {
someDateField: "The year is 2019",
someCommerceDateTimeField: "The year is 2019",
someCommerceDateField: "The year is 2020",
},
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const ReplaceCommerceDateTimeType = (
) => {
let newFieldConfig = fieldToConfig(fieldConfig)

if (fieldConfig.type.toString() === "CommerceDateTime!") {
if (
["CommerceDateTime!", "CommerceDate!"].includes(fieldConfig.type.toString())
) {
newFieldConfig = {
...newFieldConfig,
...dateField,
Expand All @@ -18,7 +20,9 @@ export const ReplaceCommerceDateTimeType = (
return newFieldConfig
}

if (fieldConfig.type.toString() === "CommerceDateTime") {
if (
["CommerceDateTime", "CommerceDate"].includes(fieldConfig.type.toString())
) {
newFieldConfig = {
...newFieldConfig,
...dateField,
Expand Down

0 comments on commit 3b81699

Please sign in to comment.