@@ -23,21 +23,17 @@ service, you can use the same GraphQL client code to access your native data sou
2323service online. You might even be able to share some more of that code between a progressive web
2424app and your native/hybrid app.
2525
26- If what you're after is a way to consume a GraphQL service from C++, as of
27- [ v3.6.0] ( https://github.com/microsoft/cppgraphqlgen/releases/tag/v3.6.0 ) this project also includes
26+ If what you're after is a way to consume a GraphQL service from C++, this project also includes
2827a ` graphqlclient ` library and a ` clientgen ` utility to generate types matching a GraphQL request
2928document, its variables, and all of the serialization code you need to talk to a ` graphqlservice `
3029implementation. If you want to consume another service, you will need access to the schema definition
3130(rather than the Introspection query results), and you will need be able to send requests along with
3231any variables to the service and parse its responses into a ` graphql::response::Value ` (e.g. with the
3332` graphqljson ` library) in your code.
3433
35- # Getting Started
36-
3734## Related projects
3835
3936The most complete examples I've built are related to [ GqlMAPI] ( https://github.com/microsoft/gqlmapi ) :
40-
4137- [ eMAPI] ( https://github.com/microsoft/eMAPI ) : Windows-only Electron app which lets you access
4238the [ MAPI] ( https://en.wikipedia.org/wiki/MAPI ) interface used by
4339[ Microsoft Outlook] ( https://en.wikipedia.org/wiki/Microsoft_Outlook ) . Its goal is to be a spiritual
@@ -57,7 +53,6 @@ I created a couple of sample projects that worked with earlier versions of `cppg
5753demonstrate integrating the [ schema.today.graphql] ( ./samples/schema.today.graphql ) service into an
5854Electron app. They're still available under my personal account, but I haven't updated them
5955recently:
60-
6156- [ electron-cppgraphql] ( https://github.com/wravery/electron-cppgraphql ) : Node Native Module which compiles
6257against the version of the Node headers included in Electron. This was the starting point for
6358` electron-gqlmapi ` , and it is still useful as a sample because it does not depend on a platform-specific
@@ -68,39 +63,53 @@ exposes an instance of [GraphiQL](https://github.com/graphql/graphiql) on top of
6863Feel free to use either or both of these as a starting point to integrate your own generated
6964service with ` Node ` , ` Electron ` , or ` Tauri ` . PRs with links to your own samples are always welcome.
7065
71- ## Installation process
72-
73- I've tested this on Windows with both Visual Studio 2017 and 2019, and on Linux using an Ubuntu 20.04 LTS instance running in
74- WSL with both gcc 9.3.0 and clang 10.0.0. The key compiler requirement is support for C++17 including std::filesystem, earlier
75- versions of gcc and clang may not have enough support for that.
66+ # Getting Started
7667
77- The easiest way to get all of these and to build ` cppgraphqlgen ` in one step is to use
78- [ microsoft/vcpkg] ( https://github.com/microsoft/vcpkg ) . To install with vcpkg, make sure you've pulled the latest version
79- and then run ` vcpkg install cppgraphqlgen ` (or ` cppgraphqlgen:x64-windows ` , ` cppgraphqlgen:x86-windows-static ` , etc.
80- depending on your platform). To install just the dependencies and work in a clone of this repo, you'll need some subset
81- of ` vcpkg install pegtl boost-program-options rapidjson gtest ` . It works for Windows, Linux, and Mac,
82- but if you want to try building for another platform (e.g. Android or iOS), you'll need to do more of this manually.
68+ ## Installation process
8369
84- Manual installation will work best if you clone the GitHub repos for each of the dependencies and follow the installation
85- instructions for each project. You might also be able to find pre-built packages depending on your platform, but the
86- versions need to match.
70+ The minimum OS and toolchain versions I've tested with this version of ` cppgraphqlgen ` are:
71+ - Microsoft Windows: Visual Studio 2019
72+ - Linux: Ubuntu 20.04 LTS with gcc 10.3.0
73+ - macOS: 11 (Big Sur) with AppleClang 13.0.0.
74+
75+ The key compiler requirement is support for C++20 including coroutines and concepts. Some of these compiler
76+ versions still treat coroutine support as experimental, and the CMake configuration can auto-detect that,
77+ but earlier versions of gcc and clang do not seem to have enough support for C++20.
78+
79+ The easiest way to build and install ` cppgraphqlgen ` is to use [ microsoft/vcpkg] ( https://github.com/microsoft/vcpkg ) .
80+ See the [ Getting Started] ( https://github.com/microsoft/vcpkg#getting-started ) section of the ` vcpkg ` README
81+ for details. Once you have that configured, run ` vcpkg install cppgraphqlgen ` (or ` cppgraphqlgen:x64-windows ` ,
82+ ` cppgraphqlgen:x86-windows-static ` , etc. depending on your platform). That will build and install all of the
83+ dependencies for ` cppgraphqlgen ` , and then build ` cppgraphqlgen ` itself without any other setup. The ` cppgraphqlgen `
84+ package (and its dependencies) are advertised to the ` CMake ` ` find_package ` function through the
85+ ` -DCMAKE_TOOLCHAIN_FILE=<...>/scripts/buildsystems/vcpkg.cmake ` parameter/variable. There are more details about
86+ this in the ` vcpkg ` documentation.
87+
88+ If you want to build ` cppgraphqlgen ` yourself, you can do that with ` CMake ` from a clone or archive of this repo.
89+ See the [ Build and Test] ( #build-and-test ) section below for instructions. You will need to install the dependencies
90+ first where ` find_package ` can find them. If ` vcpkg ` works otherwise, you can do that with `vcpkg install pegtl
91+ boost-program-options rapidjson gtest`. Some of these are optional, if for example you do not build the tests. If
92+ ` vcpkg ` does not work, please see the documentation for each of those dependencies, as well as your
93+ platform/toolchain documentation for perferred installation mechanisms. You may need to build some or all of them
94+ separately from source.
8795
8896## Software dependencies
8997
9098The build system for this project uses [ CMake] ( http://www.cmake.org/ ) . You will need to have CMake (at least version
91- 3.8 .0) installed, and the library dependencies need to be where CMake can find them. Otherwise you need to disable the
99+ 3.15 .0) installed, and the library dependencies need to be where CMake can find them. Otherwise you need to disable the
92100options which depend on them.
93101
94- I also picked a few other projects as dependencies, most of which are optional when consuming this project. If you
95- redistribute any binaries built from these libraries, you should still follow the terms of their individual licenses. As
96- of this writing, this library and all of its redistributable dependencies are available under the MIT license, which
97- means you need to include an acknowledgement along with the license text.
102+ Besides the MIT license for this project, if you redistribute any source code or binaries built from these library
103+ dependencies, you should still follow the terms of their individual licenses. As of this writing, this library and
104+ all of its dependencies are available under either the MIT License or the Boost Software License (BSL). Both
105+ licenses roughly mean that you may redistribute them freely as long as you include an acknowledgement along with
106+ the license text. Please see the license or copyright notice which comes with each project for more details.
98107
99108### graphqlpeg
100109
101- - GraphQL parsing: [ Parsing Expression Grammar Template Library (PEGTL)] ( https://github.com/taocpp/PEGTL ) release 3.2.0 ,
110+ - GraphQL parsing: [ Parsing Expression Grammar Template Library (PEGTL)] ( https://github.com/taocpp/PEGTL ) release 3.2.2 ,
102111which is part of [ The Art of C++] ( https://taocpp.github.io/ ) library collection. I've added this as a sub-module, so you
103- do not need to install this separately. If you already have 3.2.0 installed where CMake can find it, it will use that
112+ do not need to install this separately. If you already have 3.2.2 installed where CMake can find it, it will use that
104113instead of the sub-module and avoid installing another copy of PEGTL.
105114
106115### graphqlservice
@@ -179,7 +188,7 @@ The generated code depends on the `graphqlclient` library for serialization of b
179188code, you'll also need to link ` graphqlclient ` , ` graphqlpeg ` for the pre-parsed, pre-validated request AST, and
180189` graphqlresponse ` for the ` graphql::response::Value ` implementation.
181190
182- Sample output for ` clientgen ` is in the [ samples/client] ( samples/client ) directory , and each sample is consumed by
191+ Sample output for ` clientgen ` is in the sub-directories of [ samples/client] ( samples/client ) , and each sample is consumed by
183192a unit test in [ test/ClientTests.cpp] ( test/ClientTests.cpp ) .
184193
185194### tests (` GRAPHQL_BUILD_TESTS=ON ` )
@@ -191,9 +200,21 @@ configuration.
191200## API references
192201
193202See [ GraphQLService.h] ( include/graphqlservice/GraphQLService.h ) for the base types implemented in
194- the ` graphql::service ` namespace. Take a look at [ TodayMock.h] ( samples/today/TodayMock.h ) and
195- [ TodayMock.cpp] ( samples/today/TodayMock.cpp ) to see a sample implementation of a custom schema defined
196- in [ schema.today.graphql] ( samples/schema.today.graphql ) for testing purposes.
203+ the ` graphql::service ` namespace.
204+
205+ Take a look at the [ samples/learn] ( samples/learn ) directory, starting with
206+ [ StarWarsData.cpp] ( samples/learn/StarWarsData.cpp ) to see a sample implementation of a custom schema defined in
207+ [ schema.learn.graphql] ( samples/learn/schema/schema.learn.graphql ) . This is the same schema and sample data used in the
208+ GraphQL tutorial on https://graphql.org/learn/ . This directory builds an interactive command line application which
209+ can execute query and mutation operations against the sample data in memory.
210+
211+ There are several helper functions for ` CMake ` declared in
212+ [ cmake/cppgraphqlgen-functions.cmake] ( cmake/cppgraphqlgen-functions.cmake ) , which is automatically included if you use
213+ ` find_package(cppgraphqlgen) ` in your own ` CMake ` project. See
214+ [ samples/learn/schema/CMakeLists.txt] ( samples/learn/schema/CMakeLists.txt ) and
215+ [ samples/learn/CMakeLists.txt] ( samples/learn/CMakeLists.txt ) , or the ` CMakeLists.txt ` files in some of the
216+ other samples sub-directories for examples of how to use them to automatically rerun the code generators and update
217+ the files in your source directory.
197218
198219### Additional Documentation
199220
@@ -209,14 +230,28 @@ There are some more targeted documents in the [doc](./doc) directory:
209230
210231### Samples
211232
212- All of the generated files are in the [ samples] ( samples/ ) directory. There are two different versions of
213- the generated code, one which creates a single pair of files (` samples/unified/ ` ), and one which uses the
214- ` --separate-files ` flag with ` schemagen ` to generate individual header and source files (` samples/separate/ ` )
215- for each of the object types which need to be implemeneted. The only difference between
216- [ TodayMock.h] ( samples/today/TodayMock.h ) with and without ` IMPL_SEPARATE_TODAY ` defined should be that the
217- ` --separate-files ` option generates a [ TodayObjects.h] ( samples/separate/TodayObjects.h ) convenience header
218- which includes all of the inidividual object header along with the rest of the schema in
219- [ TodaySchema.h] ( samples/separate/TodaySchema.h ) .
233+ All of the samples are under [ samples] ( samples/ ) , with nested sub-directories for generated files:
234+ - [ samples/today] ( samples/today/ ) : There are two different samples generated from
235+ [ schema.today.graphql] ( samples/today/schema.today.graphql ) in this directory. The default
236+ [ schema] ( samples/today/schema/ ) target includes Introspection support (which is the default), while the
237+ [ nointrospection] ( samples/today/nointrospection/ ) target demonstrates how to disable Introspection support
238+ with the ` schemagen --no-introspection ` parameter. The mock implementation of the service for both schemas is in
239+ [ samples/today/TodayMock.h] ( samples/today/TodayMock.h ) and [ samples/today/TodayMock.cpp] ( samples/today/TodayMock.cpp ) .
240+ It builds an interactive ` sample ` /` sample_nointrospection ` and ` benchmark ` /` benchmark_nointrospection ` target for
241+ each version, and it uses each of them in several unit tests.
242+ - [ samples/client] ( samples/client/ ) : Several sample queries built with ` clientgen ` against the
243+ [ schema.today.graphql] ( samples/today/schema.today.graphql ) schema shared with [ samples/today] ( samples/today/ ) . It
244+ includes a ` client_benchmark ` executable for comparison with benchmark executables using the same hardcoded query
245+ in [ samples/today/] . The benchmark links with the default [ schema] ( samples/today/schema/ ) target in
246+ [ samples/today] ( samples/today/ ) to handle the benchmark query.
247+ - [ samples/learn] ( samples/learn/ ) : Simpler standalone which builds a ` learn_star_wars ` executable that follows
248+ the tutorial examples on https://graphql.org/learn/ .
249+ - [ samples/validation] ( samples/validation/ ) : This schema is based on the examples and counter-examples from the
250+ [ Validation] ( https://spec.graphql.org/October2021/#sec-Validation ) section of the October 2021 GraphQL spec. There
251+ is no implementation of this schema, it relies entirely generated stubs (created with ` schemagen --stubs ` ) to build
252+ successfully without defining more than placeholder objects fo the Query, Mutation, and Subscription operations in
253+ [ samples/validation/ValidationMock.h] ( samples/validation/ValidationMock.h ) . It is used to test the validation logic
254+ with every example or counter-example in the spec in [ test/ValidationTests.cpp] ( test/ValidationTests.cpp ) .
220255
221256# Build and Test
222257
@@ -233,7 +268,7 @@ can run all of them from there.
233268
234269Your experience will vary depending on your build toolchain. The same instructions should work for any platform that
235270CMake supports. These basic steps will build and run the tests. You can add options to build in another target directory,
236- change the config from ` Debug ` (default) to ` Release ` , use another build tool like ` Ninja ` , etc. If you are using vcpkg
271+ change the config from ` Debug ` (default) to ` Release ` , use another build tool like ` Ninja ` , etc. If you are using ` vcpkg `
237272to install the dependencies, remember to specify the ` -DCMAKE_TOOLCHAIN_FILE=... ` option when you run the initial build
238273configuration.
239274
@@ -248,8 +283,8 @@ You can then optionally install the public outputs by configuring it with `Relea
248283
249284## Interactive tests
250285
251- If you want to try an interactive version, you can run ` samples/sample ` and paste in queries against
252- the same mock service or load a query from a file on the command line.
286+ If you want to try an interactive version, you can run ` samples/today/ sample ` or ` samples/today/sample_nointrospection `
287+ and paste in queries against the same mock service or load a query from a file on the command line.
253288
254289## Reporting Security Issues
255290
0 commit comments