text: // @flow
  import { GraphQLObjectType, GraphQLNonNull, GraphQLString, GraphQLList }
      from "graphql/type";
  import primaryField from "~/valaa-core/tools/graphql/primaryField";
  import generatedField from "~/valaa-core/tools/graphql/generatedField";
  import dataFieldValue from "~/valaa-core/tools/denormalized/dataFieldValue";
  
  import Data, { dataInterface } from "~/valaa-core/schema/Data";
  
  const OBJECT_DESCRIPTION = "media type";
  
  export default new GraphQLObjectType({
    name: "MediaType",
  
    description: `MIME type in expanded format. See https://tools.ietf.org/html/rfc2045 and
  https://tools.ietf.org/html/rfc6838`,
  
    interfaces: () => [Data],
  
    fields: () => ({
      ...dataInterface(OBJECT_DESCRIPTION).fields(),
  
      ...generatedField("text", new GraphQLNonNull(GraphQLString),
          "Text representation of the media type.",
          mimeFromMediaType
      ),
  
      ...primaryField("type", new GraphQLNonNull(GraphQLString),
          "type string, case insensitive."
      ),
  
      ...primaryField("subtype", new GraphQLNonNull(GraphQLString),
          "subtype string, case insensitive.",
      ),
  
      ...primaryField("parameters", new GraphQLList(GraphQLString),
        `parameters of the media type, as a sequence of "attribute = value" strings.
  Token matching is case insensitive.`,
      ),
    }),
    // typeofEqualTo (value) { return value.kind === POSITION; },
  });
  
  function mimeFromMediaType (source) {
    const params = dataFieldValue(source, "parameters");
    return `${dataFieldValue(source, "type")}/${dataFieldValue(source, "subtype")}${
      !params ? "" :
      Array.isArray(params) ? params.reduce((left, right) => left + right)
        : JSON.stringify(params)}`;
  }
  