<commit_before>import _ from 'lodash';
import qs from 'qs';
import Image from './image';
import Sale from './sale';
import Partner from './partner';
import gravity from '../lib/loaders/gravity';
import {
  GraphQLObjectType,
  GraphQLBoolean,
  GraphQLString,
  GraphQLNonNull,
  GraphQLList,
  GraphQLInt
} from 'graphql';

export let ArtworkPredicates = {
  is_contactable: (artwork, sales) => {
    return artwork.forsale && !_.isEmpty(artwork.partner) && !artwork.acquireable && !sales.length
  },
  is_in_auction: (artwork, sales) => {
    return _.any(sales, 'is_auction')
  }
}

let ArtworkType = new GraphQLObjectType({
  name: 'Artwork',
  fields: () => {
    let Artist = require('./artist');

    return {
      cached: {
        type: GraphQLInt,
        resolve: ({ cached }) => new Date().getTime() - cached
      },
      id: {
        type: GraphQLString
      },
      href: {
        type: GraphQLString,
        resolve: (artwork) => `/artwork/${artwork.id}`
      },
      title: {
        type: GraphQLString
      },
      category: {
        type: GraphQLString
      },
      medium: {
        type: GraphQLString
      },
      date: {
        type: GraphQLString
      },
      is_contactable: {
        type: GraphQLBoolean,
        description: 'Are we able to display a contact form on artwork pages?',
        resolve: (artwork) => {
          return new Promise(resolve => {
            gravity(`related/sales`, { size: 1, active: true, artwork: [id] })
              .then(sales => {
                resolve(ArtworkPredicates.is_contactable(artwork, sales))
              });
          });
        }
      },
      is_in_auction: {
        type: GraphQLBoolean,
        description: 'Is this artwork part of an auction?',
        resolve: (artwork) => {
          return new Promise(resolve => {
            gravity(`related/sales`, { size: 1, active: true, artwork: [artwork.id] })
              .then(sales => {
                resolve(ArtworkPredicates.is_in_auction(artwork, sales))<commit_msg>add partner to artwork schema<commit_after>import _ from 'lodash';
import qs from 'qs';
import Image from './image';
import Sale from './sale';
import Partner from './partner';
import gravity from '../lib/loaders/gravity';
import {
  GraphQLObjectType,
  GraphQLBoolean,
  GraphQLString,
  GraphQLNonNull,
  GraphQLList,
  GraphQLInt
} from 'graphql';

export let ArtworkPredicates = {
  is_contactable: (artwork, sales) => {
    return artwork.forsale && !_.isEmpty(artwork.partner) && !artwork.acquireable && !sales.length
  },
  is_in_auction: (artwork, sales) => {
    return _.any(sales, 'is_auction')
  }
}

let ArtworkType = new GraphQLObjectType({
  name: 'Artwork',
  fields: () => {
    let Artist = require('./artist');

    return {
      cached: {
        type: GraphQLInt,
        resolve: ({ cached }) => new Date().getTime() - cached
      },
      id: {
        type: GraphQLString
      },
      href: {
        type: GraphQLString,
        resolve: (artwork) => `/artwork/${artwork.id}`
      },
      title: {
        type: GraphQLString
      },
      category: {
        type: GraphQLString
      },
      medium: {
        type: GraphQLString
      },
      date: {
        type: GraphQLString
      },
      partner:{
        type: Partner.type,
        resolve: (artwork) => {
          return artwork.partner
        }
      },
      is_contactable: {
        type: GraphQLBoolean,
        description: 'Are we able to display a contact form on artwork pages?',
        resolve: (artwork) => {
          return new Promise(resolve => {
            gravity(`related/sales`, { size: 1, active: true, artwork: [id] })
              .then(sales => {
                resolve(ArtworkPredicates.is_contactable(artwork, sales))
              });
          });
        }
      },
      is_in_auction: {
        type: GraphQLBoolean,
        description: 'Is this artwork part of an auction?',
        resolve: (artwork) => {
          return new Promise(resolve => {
            gravity(`related/sales`, { size: 1, active: true, artwork: [artwork.id] })
              .then(sales => {
                resolve(ArtworkPredicates.is_in_auction(artwork, sales))
{'fraction_non_alphanumeric': 0.13154138915318744, 'fraction_numerical': 0.0009514747859181732, 'mean_word_length': 2.138059701492537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1154699', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1254, 'n_words': 300}