<commit_before>package org.coursera.naptime.ari.graphql.schema

import com.linkedin.data.DataMap
import org.coursera.naptime.ResourceName
import org.coursera.naptime.ari.graphql.SangriaGraphQlContext
import org.coursera.naptime.schema.Resource
import sangria.execution.ExecutionError
import sangria.schema.Context
import sangria.schema.Field
import sangria.schema.ObjectType
import sangria.schema.OptionType
import sangria.schema.Value

import scala.collection.JavaConverters._

object NaptimeResourceField {

  type IdExtractor = (Context[SangriaGraphQlContext, DataMap]) => Any

  val COMPLEXITY_COST = 10.0D

  def build(
      schemaMetadata: SchemaMetadata,
      resourceName: String,
      fieldName: String,
      idExtractor: Option[IdExtractor] = None): Field[SangriaGraphQlContext, DataMap] = {
    Field.apply[SangriaGraphQlContext, DataMap, Any, Any](
      name = fieldName,
      fieldType = getType(schemaMetadata, resourceName),
      resolve = getResolver(resourceName, fieldName, idExtractor),
      complexity = Some((ctx, args, childScore) => {
        COMPLEXITY_COST * childScore
      }))
  }


  private[schema] def getType(
      schemaMetadata: SchemaMetadata,
      resourceName: String): OptionType[DataMap] = {
    val resource = schemaMetadata.getResource(resourceName)
    val schema = schemaMetadata.getSchema(resource).getOrElse {
      throw SchemaGenerationException(s"Cannot find schema for $resourceName")<commit_msg>Pull in arguments from multiget on singular related field (#152)<commit_after>package org.coursera.naptime.ari.graphql.schema

import com.linkedin.data.DataMap
import org.coursera.naptime.ResourceName
import org.coursera.naptime.ari.graphql.SangriaGraphQlContext
import org.coursera.naptime.ari.graphql.SangriaGraphQlSchemaBuilder
import org.coursera.naptime.schema.HandlerKind
import org.coursera.naptime.schema.Resource
import sangria.execution.ExecutionError
import sangria.schema.Context
import sangria.schema.Field
import sangria.schema.ObjectType
import sangria.schema.OptionType
import sangria.schema.Value

import scala.collection.JavaConverters._

object NaptimeResourceField {

  type IdExtractor = (Context[SangriaGraphQlContext, DataMap]) => Any

  val COMPLEXITY_COST = 10.0D

  def build(
      schemaMetadata: SchemaMetadata,
      resourceName: String,
      fieldName: String,
      idExtractor: Option[IdExtractor] = None): Field[SangriaGraphQlContext, DataMap] = {

    val resource = schemaMetadata.getResource(resourceName)
    val arguments = resource.handlers.find(_.kind == HandlerKind.MULTI_GET).map { handler =>
      SangriaGraphQlSchemaBuilder
        .generateHandlerArguments(handler, includePagination = false)
        .filterNot(_.name == "ids")
    }.getOrElse(List.empty)

    Field.apply[SangriaGraphQlContext, DataMap, Any, Any](
      name = fieldName,
      fieldType = getType(schemaMetadata, resourceName),
      resolve = getResolver(resourceName, fieldName, idExtractor),
      arguments = arguments,
      complexity = Some((ctx, args, childScore) => {
        COMPLEXITY_COST * childScore
      }))
  }


  private[schema] def getType(
      schemaMetadata: SchemaMetadata,
      resourceName: String): OptionType[DataMap] = {
    val resource = schemaMetadata.getResource(resourceName)
    val schema = schemaMetadata.getSchema(resource).getOrElse {
      throw SchemaGenerationException(s"Cannot find schema for $resourceName")
{'fraction_non_alphanumeric': 0.08897316219369895, 'fraction_numerical': 0.0026254375729288216, 'mean_word_length': 4.593800978792822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5941185', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1013, 'n_words': 201}