2021-04-16 04:34:29 +00:00
|
|
|
import GraphQL from 'graphql';
|
|
|
|
|
import { createSubqueryResolver } from '../resolvers.js';
|
2016-12-14 04:50:38 +00:00
|
|
|
|
2021-04-16 04:34:29 +00:00
|
|
|
const { GraphQLObjectType, GraphQLNonNull, GraphQLInt, GraphQLFloat } = GraphQL;
|
|
|
|
|
|
|
|
|
|
export const Rating = new GraphQLObjectType({
|
2016-12-14 04:50:38 +00:00
|
|
|
name: 'Rating',
|
|
|
|
|
description: `[Ratings](https://musicbrainz.org/doc/Rating_System) allow users
|
|
|
|
|
to rate MusicBrainz entities. User may assign a value between 1 and 5; these
|
|
|
|
|
values are then aggregated by the server to compute an average community rating
|
|
|
|
|
for the entity.`,
|
|
|
|
|
fields: () => ({
|
|
|
|
|
voteCount: {
|
|
|
|
|
type: new GraphQLNonNull(GraphQLInt),
|
|
|
|
|
description: 'The number of votes that have contributed to the rating.',
|
2021-04-16 04:34:29 +00:00
|
|
|
resolve: (rating) => rating['votes-count'],
|
2016-12-14 04:50:38 +00:00
|
|
|
},
|
|
|
|
|
value: {
|
2017-10-06 03:27:53 +00:00
|
|
|
type: GraphQLFloat,
|
2021-04-16 04:34:29 +00:00
|
|
|
description: 'The average rating value based on the aggregated votes.',
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const rating = {
|
|
|
|
|
type: Rating,
|
|
|
|
|
description: 'The rating users have given to this entity.',
|
|
|
|
|
resolve: createSubqueryResolver({ inc: 'ratings' }),
|
|
|
|
|
};
|