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
Missing shows data. #226
Missing shows data. #226
Changes from 5 commits
a50ed50
3a89fa1
4d05fab
5a778ea
bde01b2
8e34232
bf3e2ea
27e900d
ee8a07e
20162de
78d9161
45c5105
0e04279
48e016b
d1164c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import moment from 'moment'; | ||
|
||
export function exhibitionPeriod(startAt, endAt) { | ||
const startMoment = moment(startAt); | ||
const endMoment = moment(endAt); | ||
const thisMoment = moment(); | ||
|
||
let startFormat = 'MMMM Do'; | ||
if (startMoment.year() !== endMoment.year()) { | ||
startFormat = startFormat.concat(', YYYY'); | ||
} | ||
|
||
let endFormat = 'Do'; | ||
if (endMoment.year() !== thisMoment.year()) { | ||
endFormat = endFormat.concat(', YYYY'); | ||
} | ||
if (!(startMoment.year() === endMoment.year() && startMoment.month() === endMoment.month())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dzucconi I didn’t end up using those moment.js methods. I had hoped it could have simplified this conditional, but it really didn’t do much, so instead I opted for plain operators, which everyone should be able to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me 👍 |
||
endFormat = 'MMMM '.concat(endFormat); | ||
} | ||
|
||
return `${startMoment.format(startFormat)} - ${endMoment.format(endFormat)}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an en dash: |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moment has some methods that might make some of this logic easier to read: if (start.isSame(end, 'year')) { ... } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I've been shying away from including predetermined date formatting in the schema in favor of exposing a moment formatting interface directly. Though I can see this can't really be handled that way. I'd like to avoid the nonsense we have in Force though where there are many subtly different date string formatting methods on models. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I do get that, but we just keep re-implementing these things. So I’m thinking that maybe it’s time for that shift in moving view models into the ☁️ ?
I’m not familiar with the Force code-base, but did have a hard time figuring out all the date methods when doing some cursory reading for this work. I agree that I’d also like to avoid that, so don’t hold back when reviewing! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah; I'm with it after thinking about it. I think historically this has been a problem because of a lack of consistency site-wide when designs have been specified but there's now a move to actually consolidate. See the image of the spec posted below. It'll be nice to not have to worry about it for sure. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ import { toKey } from '../helpers'; | |
import gravity from '../apis/gravity'; | ||
import httpLoader from './http'; | ||
|
||
export const total = (path, options = {}) => { | ||
export const total = ({ path, options }) => { | ||
const key = toKey(path, assign({}, options, { | ||
size: 1, | ||
size: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change depends on https://github.com/artsy/gravity/pull/9992 being deployed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
total_count: 1, | ||
})); | ||
|
||
|
@@ -20,7 +20,7 @@ export const total = (path, options = {}) => { | |
export const totalLoader = httpLoader(total); | ||
|
||
const load = (path, options = {}) => | ||
totalLoader.load(path, options) | ||
totalLoader.load({ path, options }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work? It ... shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused as to why I was passing this options in the first place: I believe this only accepts a string key? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I found was an example in the DataLoader docs here https://github.com/facebook/dataloader#using-with-graphql, which passes an array: queryLoader.load([
'SELECT toID FROM friends WHERE fromID=? LIMIT ?', user.id, first
]) I figured I’d just give passing an arbitrary single argument a try and its worked. However, now I’m thinking that maybe it’s silently breaking anything? Like caching or something? I’m not familiar atm with what DataLoader does under the hood. |
||
.then(response => response.total); | ||
|
||
export default load; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ import { | |||||||||||||||||||||||||||||||
} from '../lib/helpers'; | ||||||||||||||||||||||||||||||||
import { find } from 'lodash'; | ||||||||||||||||||||||||||||||||
import gravity from '../lib/loaders/gravity'; | ||||||||||||||||||||||||||||||||
import total from '../lib/loaders/total'; | ||||||||||||||||||||||||||||||||
import { exhibitionPeriod } from '../lib/date'; | ||||||||||||||||||||||||||||||||
import cached from './fields/cached'; | ||||||||||||||||||||||||||||||||
import date from './fields/date'; | ||||||||||||||||||||||||||||||||
import markdown from './fields/markdown'; | ||||||||||||||||||||||||||||||||
|
@@ -63,6 +65,11 @@ const PartnerShowType = new GraphQLObjectType({ | |||||||||||||||||||||||||||||||
press_release: markdown(), | ||||||||||||||||||||||||||||||||
start_at: date, | ||||||||||||||||||||||||||||||||
end_at: date, | ||||||||||||||||||||||||||||||||
exhibition_period: { | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Eigen we called this ausstellungsdauer, but I’ve noticed that that was not something that was shared across clients, e.g. Force calls it ‘running dates’. I went with the translation of ‘ausstellungsdauer’, but I’m open to a naming contest. /cc @orta There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Exhibition period' makes more sense than 'running dates' IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hah, just found this discussion - yeah, I think realistically exhibition period is a much better name. |
||||||||||||||||||||||||||||||||
type: GraphQLString, | ||||||||||||||||||||||||||||||||
description: 'A formatted description of the start to end dates', | ||||||||||||||||||||||||||||||||
resolve: ({ start_at, end_at }) => exhibitionPeriod(start_at, end_at), | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
artists: { | ||||||||||||||||||||||||||||||||
type: new GraphQLList(Artist.type), | ||||||||||||||||||||||||||||||||
resolve: ({ artists }) => artists, | ||||||||||||||||||||||||||||||||
|
@@ -131,6 +138,18 @@ const PartnerShowType = new GraphQLObjectType({ | |||||||||||||||||||||||||||||||
.then(exclude(options.exclude, 'id')); | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
artworks_count: { | ||||||||||||||||||||||||||||||||
type: GraphQLInt, | ||||||||||||||||||||||||||||||||
args: { | ||||||||||||||||||||||||||||||||
artist_id: { | ||||||||||||||||||||||||||||||||
type: GraphQLString, | ||||||||||||||||||||||||||||||||
description: 'The slug or ID of an artist in the show.', | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
resolve: ({ id, partner }, options) => { | ||||||||||||||||||||||||||||||||
return total(`partner/${partner.id}/show/${id}/artworks`, options); | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes more sense to me to expose all the counts on a schema as it's own nested object—like: metaphysics/schema/artist/index.js Lines 105 to 119 in 11d272a
Also note the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, will do 👍 |
||||||||||||||||||||||||||||||||
meta_image: { | ||||||||||||||||||||||||||||||||
type: Image.type, | ||||||||||||||||||||||||||||||||
resolve: ({ id, partner, image_versions, image_url }) => { | ||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import moment from 'moment'; | ||
import { exhibitionPeriod } from '../../lib/date'; | ||
|
||
describe('date', () => { | ||
describe('exhibitionPeriod', () => { | ||
it('includes the start and end date', () => { | ||
const period = exhibitionPeriod(moment('2011-01-12'), moment('2014-04-19')) | ||
period.should.equal('January 12th, 2011 - April 19th, 2014'); | ||
}); | ||
|
||
it('does not include the year of the start date if it’s the same year as the end date', () => { | ||
const period = exhibitionPeriod(moment('2011-01-12'), moment('2011-04-19')) | ||
period.should.equal('January 12th - April 19th, 2011'); | ||
}); | ||
|
||
it('does not include the month of the end date if it’s the same as the start date', () => { | ||
const period = exhibitionPeriod(moment('2011-01-12'), moment('2011-01-19')) | ||
period.should.equal('January 12th - 19th, 2011'); | ||
}); | ||
|
||
it('does not include the year of the end date if it’s in the current year', () => { | ||
const period = exhibitionPeriod(moment('2011-01-12'), moment().format('YYYY-04-19')) | ||
period.should.equal('January 12th, 2011 - April 19th'); | ||
}); | ||
|
||
it('does not include a year at all if both start and end date are in the current year', () => { | ||
const period = exhibitionPeriod(moment().format('YYYY-01-12'), moment().format('YYYY-01-19')) | ||
period.should.equal('January 12th - 19th'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @briansw FYI here are the test cases. |
||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spoke with @briansw about where we want to land on unifying the date range formatting: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so:
I’m unsure what the ‘2+ mos’ part is trying to convey, can you clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just that when the show spans two or more months, we need to add the second month, but don't display it when the duration is contained to one month. Here's the description in list format:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When it the date range goes outside of one single month, example |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ describe('total', () => { | |
|
||
total.__Rewire__('gravity', gravity); | ||
|
||
return total('foo/bar') | ||
return total('foo/bar', { extra_option: 1 }) | ||
.then(n => { | ||
gravity.args[0][0] | ||
.should.equal('foo/bar?size=1&total_count=1'); | ||
.should.equal('foo/bar?extra_option=1&size=0&total_count=1'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could have sworn this worked previously. I guess that's the change you made above that I'm confused by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this did not work without my change above. |
||
|
||
n.should.equal(50); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ describe('PartnerShow type', () => { | |
|
||
beforeEach(() => { | ||
const gravity = sinon.stub(); | ||
const total = sinon.stub(); | ||
|
||
gravity.returns(Promise.resolve({ | ||
id: 'new-museum-1-2015-triennial-surround-audience', | ||
|
@@ -16,11 +17,17 @@ describe('PartnerShow type', () => { | |
displayable: true, | ||
})); | ||
|
||
total | ||
.onCall(0).returns(Promise.resolve(42)) | ||
.onCall(1).returns(Promise.resolve(2)); | ||
|
||
PartnerShow.__Rewire__('gravity', gravity); | ||
PartnerShow.__Rewire__('total', total); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The stubbing of Any idea what I’m doing wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dzucconi I’d really like some input on this one, currently its tests are failing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :Taking a look: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
|
||
afterEach(() => { | ||
PartnerShow.__ResetDependency__('gravity'); | ||
PartnerShow.__ResetDependency__('total'); | ||
}); | ||
|
||
it('includes a formattable start and end date', () => { | ||
|
@@ -49,6 +56,25 @@ describe('PartnerShow type', () => { | |
}); | ||
}); | ||
|
||
it('includes a formatted exhibition period', () => { | ||
const query = ` | ||
{ | ||
partner_show(id: "new-museum-1-2015-triennial-surround-audience") { | ||
exhibition_period | ||
} | ||
} | ||
`; | ||
|
||
return graphql(schema, query) | ||
.then(({ data }) => { | ||
data.should.eql({ | ||
partner_show: { | ||
exhibition_period: 'February 25th - May 24th, 2015' | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('includes the html version of markdown', () => { | ||
const query = ` | ||
{ | ||
|
@@ -70,4 +96,42 @@ describe('PartnerShow type', () => { | |
}); | ||
}); | ||
}); | ||
|
||
it('includes the total number of artworks', () => { | ||
const query = ` | ||
{ | ||
partner_show(id: "new-museum-1-2015-triennial-surround-audience") { | ||
artworks_count | ||
} | ||
} | ||
`; | ||
|
||
return graphql(schema, query) | ||
.then(({ data }) => { | ||
data.should.eql({ | ||
partner_show: { | ||
artworks_count: 42, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('includes the number of artworks by a specific artist', () => { | ||
const query = ` | ||
{ | ||
partner_show(id: "new-museum-1-2015-triennial-surround-audience") { | ||
artworks_count(artist_id: "juliana-huxtable") | ||
} | ||
} | ||
`; | ||
|
||
return graphql(schema, query) | ||
.then(({ data }) => { | ||
data.should.eql({ | ||
partner_show: { | ||
artworks_count: 2, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wot? not
ausstellungssauer
- shockingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @speednoisemovement