<commit_before>open Async_kernel
open Async_unix

let yojson =
  ( module struct
    type t = Yojson.Basic.json [@@warning "-3"]

    let pp formatter t =
      Format.pp_print_text formatter (Yojson.Basic.pretty_to_string t)

    let equal = ( = )
  end : Alcotest.TESTABLE
    with type t = Yojson.Basic.json )
  [@@warning "-3"]

let test_query schema ctx query expected =
  Thread_safe.block_on_async_exn (fun () ->
      match Graphql_parser.parse query with
      | Error err -> failwith err
      | Ok doc ->
          (Graphql_async.Schema.execute schema ctx doc >>= function
           | Ok (`Response data) -> Async_kernel.return data
           | Ok (`Stream stream) ->
               Async_kernel.Pipe.to_list stream >>| fun lst ->
               `List
                 Core_kernel.(
                   List.map lst ~f:(fun x -> Option.value_exn (Result.ok x)))
           | Error err -> Async_kernel.return err)
          >>| fun result ->
          Alcotest.check yojson "invalid execution result" expected result)

let schema =
  Graphql_async.Schema.(<commit_msg>Use Core instead of Core_kernel<commit_after>open Async_kernel
open Async_unix

let yojson =
  ( module struct
    type t = Yojson.Basic.json [@@warning "-3"]

    let pp formatter t =
      Format.pp_print_text formatter (Yojson.Basic.pretty_to_string t)

    let equal = ( = )
  end : Alcotest.TESTABLE
    with type t = Yojson.Basic.json )
  [@@warning "-3"]

let test_query schema ctx query expected =
  Thread_safe.block_on_async_exn (fun () ->
      match Graphql_parser.parse query with
      | Error err -> failwith err
      | Ok doc ->
          (Graphql_async.Schema.execute schema ctx doc >>= function
           | Ok (`Response data) -> Async_kernel.return data
           | Ok (`Stream stream) ->
               Async_kernel.Pipe.to_list stream >>| fun lst ->
               `List
                 Core.(
                   List.map lst ~f:(fun x -> Option.value_exn (Result.ok x)))
           | Error err -> Async_kernel.return err)
          >>| fun result ->
          Alcotest.check yojson "invalid execution result" expected result)

let schema =
  Graphql_async.Schema.(
{'fraction_non_alphanumeric': 0.10235131396957123, 'fraction_numerical': 0.0018441678192715537, 'mean_word_length': 2.177159590043924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '4418157', 'n_tokens_mistral': 665, 'n_tokens_neox': 640, 'n_words': 185}