You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-19Lines changed: 54 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,33 @@
1
1
# Introduction
2
2
3
-
[GraphQL](https://graphql.org/) and [React](https://reactjs.org/) go together like peanut butter and jelly, especially if you use a GraphQL client/compiler like [Relay](http://facebook.github.io/relay/en/) or [Apollo](https://github.com/apollographql/apollo-client).
4
-
5
-
But GraphQL services are only implemented on the server. When using React Native or React JS in a hybrid application, you typically have a native application which hosts islands or entire pages of UI rendered with React components, and you might like to display content that you've cached offline or that you otherwise generate on the client without needing to declare a separate data interface or require a server round trip to load it.
6
-
7
-
This project includes a `graphqlservice` library with the core functionality of a GraphQL service and a `schemagen` utility to generate types for your custom GraphQL service schema definition. Once you implement the pure virtual methods on the object interfaces and add hooks to the Relay [Network Layer](https://facebook.github.io/relay/docs/en/network-layer.html)/Apollo [Terminating Link](https://www.apollographql.com/docs/link/overview.html#terminating) to call your service, you can use the same GraphQL client code to access your native data source or a GraphQL service online. You might even be able to share some more of that code between a progressive web app and your native/hybrid app.
3
+
[GraphQL](https://graphql.org/) and [React](https://reactjs.org/) go together like peanut butter
4
+
and jelly, especially if you use a GraphQL client/compiler like [Relay](http://facebook.github.io/relay/en/)
5
+
or [Apollo](https://github.com/apollographql/apollo-client).
6
+
7
+
But GraphQL services are only implemented on the server. When using React Native or React JS in a
8
+
hybrid application, you typically have a native application which hosts islands or entire pages of
9
+
UI rendered with React components, and you might like to display content that you've cached offline
10
+
or that you otherwise generate on the client without needing to declare a separate data interface
11
+
or require a server round trip to load it.
12
+
13
+
This project includes a `graphqlservice` library with the core functionality of a GraphQL service
14
+
and a `schemagen` utility to generate types for your custom GraphQL service schema definition. Once
15
+
you implement the pure virtual methods on the object interfaces and add hooks to the Relay
[Terminating Link](https://www.apollographql.com/docs/link/overview.html#terminating) to call your
18
+
service, you can use the same GraphQL client code to access your native data source or a GraphQL
19
+
service online. You might even be able to share some more of that code between a progressive web
20
+
app and your native/hybrid app.
8
21
9
22
# Getting Started
10
23
11
24
## Installation process
12
25
13
-
First, clone this repo, then make sure you have the dependencies. Acquiring the dependencies is a bit different depending on your platform.
26
+
First, clone this repo, then make sure you have the dependencies. Acquiring the dependencies is a
27
+
bit different depending on your platform.
14
28
15
-
I've tested this on Windows with Visual Studio 2017 and Linux using an Ubuntu instance running in WSL.
29
+
I've tested this on Windows with Visual Studio 2017 and Linux using an Ubuntu instance running in
30
+
WSL.
16
31
17
32
I plan on adding a vcpkg package for this project, and then you can install everything with `vcpkg install cppgraphqlgen`.
18
33
@@ -24,49 +39,68 @@ I picked a few projects as dependencies:
24
39
- GraphQL parsing: [Parsing Expression Grammar Template Library (PEGTL)](https://github.com/taocpp/PEGTL), which is part of [The Art of C++](https://taocpp.github.io/) library collection.
25
40
- Unit testing: [Google Test](https://github.com/google/googletest) for the unit testing framework.
26
41
27
-
The build system for this project uses [CMake](http://www.cmake.org/). You'll need to have all 3 dependencies installed on your system along with CMake to build this project.
42
+
The build system for this project uses [CMake](http://www.cmake.org/). You'll need to have all 3
43
+
dependencies installed on your system along with CMake to build this project.
28
44
29
45
### Using vcpkg
30
46
31
-
Vcpkg can install the dependencies from source on either platform, and that's what I'm using on Windows. Use `vcpkg install rapidjson pegtl gtest` to get all of them.
47
+
Vcpkg can install the dependencies from source on either platform, and that's what I'm using on
48
+
Windows. Use `vcpkg install rapidjson pegtl gtest` to get all of them.
32
49
33
50
This approach works well on Linux. I've done all of my testing for Linux with WSL using vcpkg.
34
51
35
52
### Windows with NuGet
36
53
37
-
All of these packages dependencies should also be available in NuGet packages if you don't want to use [vcpkg](https://github.com/Microsoft/vcpkg) but still want to use a package manager.
54
+
All of these packages dependencies should also be available in NuGet packages if you don't want to
55
+
use [vcpkg](https://github.com/Microsoft/vcpkg) but still want to use a package manager.
38
56
39
57
### Linux or Windows from GitHub
40
58
41
-
Clone each of the repos from GitHub and follow the installation instructions in the README.md files.
59
+
Clone each of the repos from GitHub and follow the installation instructions in the README.md
60
+
files.
42
61
43
62
## API references
44
63
45
-
See [GraphQLService.h](GraphQLService.h) for the base types implemented in the `facebook::graphql::service` namespace. Take a look at [Today.h](Today.h) and [Today.cpp](Today.cpp) to see a sample implementation of a custom schema defined in [schema.today.graphql](schema.today.graphql) for testing purposes.
64
+
See [GraphQLService.h](include/graphqlservice/GraphQLService.h) for the base types implemented in
65
+
the `facebook::graphql::service` namespace. Take a look at [Today.h](Today.h) and [Today.cpp](Today.cpp)
66
+
to see a sample implementation of a custom schema defined in [schema.today.graphql](samples/schema.today.graphql)
67
+
for testing purposes.
46
68
47
-
All of the generated files are in the [samples](samples/) directory. If you modify the code generator in SchemaGenerator.* and rebuild, `make install` will update them. Please remember to include updating the samples in any pull requests which change them.
69
+
All of the generated files are in the [samples](samples/) directory. If you modify the code
70
+
generator in SchemaGenerator.* and rebuild, `make install` will update them. Please remember to
71
+
include updating the samples in any pull requests which change them.
48
72
49
73
# Build and Test
50
74
51
75
## Windows
52
76
53
-
There are a couple of options for building on Windows. You can either run CMake from the command line, or you can use the CMake integration in Visual Studio. They behave a little differently, but I prefer building and running tests in Visual Studio, then optionally performing a Release build and install from the command line.
77
+
There are a couple of options for building on Windows. You can either run CMake from the command
78
+
line, or you can use the CMake integration in Visual Studio. They behave a little differently, but
79
+
I prefer building and running tests in Visual Studio, then optionally performing a Release build
80
+
and install from the command line.
54
81
55
82
### Visual Studio
56
83
57
-
Use the Open Folder command to open the root of the repo. If you've installed the dependencies with vcpkg and run its Visual Studio integration command, Visual Studio should know how to build each of the targets in this project automatically. I've only been able to get x86-debug to work so far in Visual Studio though, it doesn't switch properly between the Debug and Release dependencies installed by vcpkg on my machine.
84
+
Use the Open Folder command to open the root of the repo. If you've installed the dependencies with
85
+
vcpkg and run its Visual Studio integration command, Visual Studio should know how to build each of
86
+
the targets in this project automatically. I've only been able to get x86-debug to work so far in
87
+
Visual Studio though, it doesn't switch properly between the Debug and Release dependencies
88
+
installed by vcpkg on my machine.
58
89
59
90
### Command Line
60
91
61
92
To build from the command line, run:
62
93
63
-
`cmake -DCMAKE_TOOLCHAIN_FILE=<...path to vcpkg root...>/scripts/buildsystems/vcpkg.cmake .` once to populate the Visual Studio solution files, then:
94
+
`cmake -DCMAKE_TOOLCHAIN_FILE=<...path to vcpkg root...>/scripts/buildsystems/vcpkg.cmake .` once
95
+
to populate the Visual Studio solution files, then:
64
96
65
97
`msbuild cppgraphql.sln` to perform the build.
66
98
67
-
You can also build optional `.vcxproj` project files with msbuild to perform the associated task, e.g. installing or running tests.
99
+
You can also build optional `.vcxproj` project files with msbuild to perform the associated task,
100
+
e.g. installing or running tests.
68
101
69
-
If you want to make a Release build, add the `/p:Configuration=Release` argument to the `msbuild` command line.
102
+
If you want to make a Release build, add the `/p:Configuration=Release` argument to the `msbuild`
103
+
command line.
70
104
71
105
## Linux
72
106
@@ -84,7 +118,8 @@ You can then optionally install the public outputs by running:
84
118
85
119
Run the unit tests with `tests` from the build output directory.
86
120
87
-
If you want to try an interactive version, you can run `test_today` and paste in queries against the same mock service or load a query from a file on the command line.
121
+
If you want to try an interactive version, you can run `test_today` and paste in queries against
122
+
the same mock service or load a query from a file on the command line.
0 commit comments