Skip to content

Commit 77a8c04

Browse files
first commit
0 parents  commit 77a8c04

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# GraphQL C++
2+
3+
This is a [GraphQL] server library to simple create your API using [modern C++](http://awesomecpp.com/).
4+
5+
[<img src="http://graphql.org/img/logo.svg" alt="GraphQL" width="230px">][GraphQL]
6+
[<img src="https://isocpp.org/files/img/cpp_logo.png" alt="C++" width="200px">](http://isocpp.org)
7+
8+
### Aim
9+
10+
Help you to build the fastest GraphQL server APIs at an easy, readable and reliable way.
11+
12+
### Current Status
13+
14+
Concept, doing mockup's about who should be the user exeperience.
15+
16+
Review the code in [main.cpp](main.cpp), feel free to do your sugestions creating a [**issue**](https://github.com/DavidUser/GraphQL-Cpp/issues) or [fork](https://github.com/DavidUser/GraphQL-Cpp/fork) and making a [**pull request**](https://github.com/DavidUser/GraphQL-Cpp/pulls).
17+
18+
## About GraphQL
19+
20+
- Please visit [graphql.org][GraphQL]
21+
22+
[GraphQL]: http://graphql.org

custumer.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <string>
2+
#include <vector>
3+
#include "purchase.h"
4+
5+
using std::string;
6+
7+
/// Custumer
8+
/// This represents a custumer
9+
struct Custumer {
10+
string id;
11+
string name;
12+
string email;
13+
unsigned short age;
14+
std::vector<Purchase> purchases;
15+
};

graphql.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <functional>
2+
#include <vector>
3+
#include <string>
4+
using std::string;
5+
6+
class GraphQL
7+
{
8+
public:
9+
// Register a query
10+
template <class T, class ...Resolver>
11+
void Query(string name, Resolver... resolver);
12+
13+
// Digest a GraphQL request
14+
// Returns a JSON response
15+
string Digest(string request);
16+
};

main.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <string>
3+
#include "graphql.h"
4+
5+
#include "custumer.h"
6+
7+
using std::string;
8+
9+
int main(void)
10+
{
11+
// Create a GraphQL digester
12+
GraphQL app;
13+
14+
// regsiter a GraphQL query behaviour
15+
app.Query<Custumer>("custumer", // to custumer node
16+
[](string id) { // query by id
17+
Custumer custumer;
18+
custumer.id = id;
19+
custumer.name = "none";
20+
return custumer; // return the full data
21+
} // GraphQL take care of just return what is needed
22+
);
23+
24+
std::cout << // put on console
25+
app.Digest( // this query result
26+
"{ "
27+
" custumer(id : \"1\") { "
28+
" id "
29+
" name "
30+
" } "
31+
"} ")
32+
<< std::endl;
33+
34+
/* Expected reponse:
35+
{
36+
"data" : {
37+
"custumer" : {
38+
"id" : "1",
39+
"name" : "none"
40+
}
41+
}
42+
}
43+
*/
44+
}
45+

purchase.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <string>
2+
using std::string;
3+
4+
/// Purchase
5+
/// This represents one Purchase of an Custumer
6+
struct Purchase
7+
{
8+
string id;
9+
string product_id;
10+
string total_spent;
11+
};
12+

0 commit comments

Comments
 (0)