Skip to content

Commit

Permalink
Merge pull request #348 from mzikherman/commercial_filtering_followed…
Browse files Browse the repository at this point in the history
…_artists

@broskoski => Schema for followed artists filter
  • Loading branch information
broskoski committed Jul 12, 2016
2 parents d424456 + fabff66 commit ff83277
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions schema/aggregations/filter_artworks_aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const ArtworksAggregation = new GraphQLEnumType({
TOTAL: {
value: 'total',
},
FOLLOWED_ARTISTS: {
value: 'followed_artists',
},
},
});

Expand Down
22 changes: 19 additions & 3 deletions schema/filter_artworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@ export const FilterArtworksType = new GraphQLObjectType({
name: 'FilterArtworks',
fields: () => ({
hits: {
description: 'Artwork results.',
type: new GraphQLList(Artwork.type),
},
total: {
type: GraphQLInt,
resolve: ({ aggregations }) => aggregations.total.value,
},
followed_artists_total: {
type: GraphQLInt,
resolve: ({ aggregations }) => aggregations.followed_artists.value,
},
aggregations: {
description: 'Returns aggregation counts for the given filter query.',
type: new GraphQLList(ArtworksAggregationResultsType),
resolve: ({ aggregations }) =>
map(omit(aggregations, ['total']), (counts, slice) => ({ slice, counts })),
resolve: ({ aggregations }) => {
const whitelistedAggregations = omit(aggregations, ['total', 'followed_artists']);
return map(whitelistedAggregations, (counts, slice) => ({ slice, counts }));
},
},
}),
});
Expand All @@ -53,6 +61,9 @@ const FilterArtworks = {
extra_aggregation_gene_ids: {
type: new GraphQLList(GraphQLString),
},
include_artworks_by_followed_artists: {
type: GraphQLBoolean,
},
for_sale: {
type: GraphQLBoolean,
},
Expand Down Expand Up @@ -96,7 +107,12 @@ const FilterArtworks = {
type: GraphQLString,
},
},
resolve: (root, options) => gravity('filter/artworks', options),
resolve: (root, options, { rootValue: { accessToken } }) => {
if (accessToken) {
return gravity.with(accessToken)('filter/artworks', options);
}
return gravity('filter/artworks', options);
},
};

export default FilterArtworks;

0 comments on commit ff83277

Please sign in to comment.