2020-01-07 03:23:28 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { makeExtendSchemaPlugin, gql } = require('graphile-utils');
|
|
|
|
|
2021-09-11 22:05:45 +00:00
|
|
|
function isFavorited(parent) {
|
|
|
|
if (!parent['@stashes'] || (parent['@stashes'].length > 0 && typeof parent['@stashes'][0]['@stash'].primary === 'undefined')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent['@stashes'].some(({ '@stash': stash }) => stash.primary);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isStashed(parent, args) {
|
|
|
|
if (!parent['@stashes'] || (parent['@stashes'].length > 0 && typeof parent['@stashes'][0]['@stash'].primary === 'undefined')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.includeFavorites) {
|
|
|
|
return parent['@stashes'].length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent['@stashes'].some(({ '@stash': stash }) => !stash.primary);
|
|
|
|
}
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const schemaExtender = makeExtendSchemaPlugin(_build => ({
|
2020-05-14 02:26:05 +00:00
|
|
|
typeDefs: gql`
|
2021-03-19 02:27:48 +00:00
|
|
|
extend type Release {
|
2021-06-19 16:09:58 +00:00
|
|
|
isFavorited: Boolean @requires(columns: ["stashesScenesBySceneId"])
|
|
|
|
isStashed(includeFavorites: Boolean = false): Boolean @requires(columns: ["stashesScenesBySceneId"])
|
2021-03-19 02:27:48 +00:00
|
|
|
}
|
2021-09-11 22:05:45 +00:00
|
|
|
|
|
|
|
extend type Movie {
|
|
|
|
isFavorited: Boolean @requires(columns: ["stashesMovies"])
|
|
|
|
isStashed(includeFavorites: Boolean = false): Boolean @requires(columns: ["stashesMovies"])
|
|
|
|
}
|
2020-01-07 03:23:28 +00:00
|
|
|
`,
|
2020-05-14 02:26:05 +00:00
|
|
|
resolvers: {
|
|
|
|
Release: {
|
2021-09-11 22:05:45 +00:00
|
|
|
isFavorited,
|
|
|
|
isStashed,
|
|
|
|
},
|
|
|
|
Movie: {
|
|
|
|
isFavorited,
|
|
|
|
isStashed,
|
2020-05-14 02:26:05 +00:00
|
|
|
},
|
|
|
|
},
|
2020-01-07 03:23:28 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
module.exports = [schemaExtender];
|