blitz_query_cpp

Форк
0
/
introspection_query_tests.cpp 
104 строки · 2.6 Кб
1
#include <gtest/gtest.h>
2
#include <gmock/gmock.h>
3
#include <type_system/schema.hpp>
4
#include <type_system/schema_parser.hpp>
5
#include <processing/introspection_query_handler.hpp>
6
#include <processing/parse_document.hpp>
7
#include <processing/serialize_result.hpp>
8
#include <processing/processing_pipeline.hpp>
9
#include <processing/process_errors.hpp>
10
#include <data/sql/postgresql_renderer.hpp>
11
#include <data/sql/postgresql_data_reader.hpp>
12
#include <serialization/json/json_serializer.hpp>
13
#include <serialization/buffer_writer.hpp>
14
#include <struct/query_context.hpp>
15
#include <type_system/builtin_types.hpp>
16

17
#include <string>
18

19
using namespace blitz_query_cpp;
20

21
TEST(Introspection, SimpleSelect)
22
{
23
    std::string scm = R""""(
24
        schema { query: Query }
25
        type Query
26
        {
27
           Users :[User]
28
        }
29
        type User @table(table: "user" schema: "test")
30
        {
31
           Id: Int @column(name: "id" IsPK: True)
32
           Name: String @column(name: "name")
33
           Age: Int  @column(name: "age")
34
           AccountId :Int @always_projected
35
        }
36

37
        directive @table(table: String schema: String) on OBJECT
38
        directive @column(name: String IsPK: Boolean = False) on FIELD_DEFINITION
39
        )"""";
40

41
    std::string query =
42
        R""""(
43
{
44
  __type(name: "Query") {
45
    name
46
    description
47
    kind
48
    fields {
49
      name
50
      isDeprecated
51
      args {
52
        name
53
        type {
54
          name
55
        }
56
      }
57
      description
58
      type {
59
        kind
60
        name
61
        ofType
62
        {
63
          name
64
          kind
65
          ofType
66
          {
67
            name
68
          }
69
        }
70
      }
71
    }
72
  }
73
}
74
        )"""";
75

76
    schema_t my_schema;
77
    EXPECT_EQ(add_introspection_types(my_schema), true);
78

79
    schema_parser_t parser;
80
    bool res = parser.parse(my_schema, scm);
81
    EXPECT_EQ(res, true);
82
    EXPECT_EQ(my_schema.query_type_name, "Query");
83
    EXPECT_EQ(parser.get_error_msg().size(), 0ul);
84
  
85
    std::cout << parser.get_error_msg() << std::endl;
86
    
87
    options_t options{};
88

89
    query_context context(query, &my_schema, options);
90

91
    processing_pipeline<parse_document,
92
                        introspection_query_handler,
93
                        process_errors,
94
                        serialize_result<json_writer<buffer_writer>>
95
                       >
96
        pipeline;
97

98
    pipeline.process(context);
99
    EXPECT_EQ(context.error_msgs.size(), 0ul);
100
    std::string &result = context.data["result_str"];
101
    EXPECT_GT(result.size(), 0ul);
102

103
    std::cout << result << std::endl;
104
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.