-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
58 lines (50 loc) · 1.74 KB
/
main.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
58
#include <iostream>
#include <string>
#include "graphql.h"
#include "custumer.h"
using std::string;
int main(void) {
// Create a GraphQL digester
GraphQL app;
// Have 2 ways to declare a GraphQL query,
// Search by the name of class and member (with sugar sintax)
// Recomended because it's type safe and named at compile type
// regsiter a GraphQL query behaviour
app.Query QL_MEMBER(Custumer, id,
{ // query by id
Custumer custumer;
custumer.id = id;
custumer.name = "none";
return custumer; // return the full data
} // GraphQL take care of just return what is needed
);
// Raw C++17 with customizable renaming members (without sugar sintax)
// regsiter a GraphQL query behaviour
app.Query<Custumer>("custumer", "id", // Set query name of type and member
[](string id) { // query by id
Custumer custumer;
custumer.id = id;
custumer.name = "none";
return custumer; // return the full data
} // GraphQL take care of just return what is needed
);
std::cout << // put on console
app.Digest( // this query result
"{ "
" custumer(id : \"1\") { "
" id "
" name "
" } "
"} ")
<< std::endl;
/* Expected reponse:
{
"data" : {
"custumer" : {
"id" : "1",
"name" : "none"
}
}
}
*/
}