-
Notifications
You must be signed in to change notification settings - Fork 46
/
sample.cpp
57 lines (44 loc) · 1.04 KB
/
sample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "StarWarsData.h"
#include "graphqlservice/JSONResponse.h"
#include <cstdio>
#include <iostream>
#include <iterator>
#include <stdexcept>
using namespace graphql;
int main(int argc, char** argv)
{
auto service = star_wars::GetService();
std::cout << "Created the service..." << std::endl;
try
{
peg::ast query;
if (argc > 1)
{
query = peg::parseFile(argv[1]);
}
else
{
std::istream_iterator<char> start { std::cin >> std::noskipws }, end {};
std::string input { start, end };
query = peg::parseString(std::move(input));
}
if (!query.root)
{
std::cerr << "Unknown error!" << std::endl;
std::cerr << std::endl;
return 1;
}
std::cout << "Executing query..." << std::endl;
std::cout << response::toJSON(
service->resolve({ query, ((argc > 2) ? argv[2] : "") }).get())
<< std::endl;
}
catch (const std::runtime_error& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}