blitz_query_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
19using namespace blitz_query_cpp;
20
21TEST(Introspection, SimpleSelect)
22{
23std::string scm = R""""(
24schema { query: Query }
25type Query
26{
27Users :[User]
28}
29type User @table(table: "user" schema: "test")
30{
31Id: Int @column(name: "id" IsPK: True)
32Name: String @column(name: "name")
33Age: Int @column(name: "age")
34AccountId :Int @always_projected
35}
36
37directive @table(table: String schema: String) on OBJECT
38directive @column(name: String IsPK: Boolean = False) on FIELD_DEFINITION
39)"""";
40
41std::string query =
42R""""(
43{
44__type(name: "Query") {
45name
46description
47kind
48fields {
49name
50isDeprecated
51args {
52name
53type {
54name
55}
56}
57description
58type {
59kind
60name
61ofType
62{
63name
64kind
65ofType
66{
67name
68}
69}
70}
71}
72}
73}
74)"""";
75
76schema_t my_schema;
77EXPECT_EQ(add_introspection_types(my_schema), true);
78
79schema_parser_t parser;
80bool res = parser.parse(my_schema, scm);
81EXPECT_EQ(res, true);
82EXPECT_EQ(my_schema.query_type_name, "Query");
83EXPECT_EQ(parser.get_error_msg().size(), 0ul);
84
85std::cout << parser.get_error_msg() << std::endl;
86
87options_t options{};
88
89query_context context(query, &my_schema, options);
90
91processing_pipeline<parse_document,
92introspection_query_handler,
93process_errors,
94serialize_result<json_writer<buffer_writer>>
95>
96pipeline;
97
98pipeline.process(context);
99EXPECT_EQ(context.error_msgs.size(), 0ul);
100std::string &result = context.data["result_str"];
101EXPECT_GT(result.size(), 0ul);
102
103std::cout << result << std::endl;
104}