@@ -23,6 +23,15 @@ 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
28+ a ` graphqlclient ` library and a ` clientgen ` utility to generate types matching a GraphQL request
29+ document, its variables, and all of the serialization code you need to talk to a ` graphqlservice `
30+ implementation. If you want to consume another service, you will need access to the schema definition
31+ (rather than the Introspection query results), and you will need be able to send requests along with
32+ any variables to the service and parse its responses into a ` graphql::response::Value ` (e.g. with the
33+ ` graphqljson ` library) in your code.
34+
2635# Getting Started
2736
2837## Related projects
@@ -116,6 +125,41 @@ adds a runtime dependency on a Boost DLL. The `schemagen` tool won't run without
116125the install of Boost, vcpkg also takes care of installing the dependencies next to ` schemagen.exe ` when building the
117126Windows and UWP shared library targets (the platform triplets which don't end in ` -static ` ).
118127
128+ ### clientgen
129+
130+ The ` clientgen ` utility is based on ` schemagen ` and shares the same external dependencies. The command line arguments
131+ are almost the same, except it takes an extra file for the request document and there is no equivalent to ` --no-stubs ` or
132+ ` --separate-files ` :
133+ ```
134+ Usage: clientgen [options] <schema file> <request file> <output filename prefix> <output namespace>
135+ Command line options:
136+ --version Print the version number
137+ -? [ --help ] Print the command line options
138+ -v [ --verbose ] Verbose output including generated header names as
139+ well as sources
140+ -s [ --schema ] arg Schema definition file path
141+ -r [ --request ] arg Request document file path
142+ -o [ --operation ] arg Operation name if the request document contains more
143+ than one
144+ -p [ --prefix ] arg Prefix to use for the generated C++ filenames
145+ -n [ --namespace ] arg C++ sub-namespace for the generated types
146+ --source-dir arg Target path for the <prefix>Client.cpp source file
147+ --header-dir arg Target path for the <prefix>Client.h header file
148+ --no-introspection Do not expect support for Introspection
149+ ```
150+
151+ This utility should output one header and one source file for each request document. A request document may contain
152+ more than one operation, in which case you must specify the ` --operation ` (or ` -o ` ) parameter to indicate which one
153+ should be used to generate the files. If you want to generate client code for more than one operation in the same
154+ document, you will need to run ` clientgen ` more than once and specify another operation name each time.
155+
156+ The generated code depends on the ` graphqlclient ` library for serialization of built-in types. If you link the generated
157+ code, you'll also need to link ` graphqlclient ` , ` graphqlpeg ` for the pre-parsed, pre-validated request AST, and
158+ ` graphqlresponse ` for the ` graphql::response::Value ` implementation.
159+
160+ Sample output for ` clientgen ` is in the [ samples/client] ( samples/client ) directory, and each sample is consumed by
161+ a unit test in [ test/ClientTests.cpp] ( test/ClientTests.cpp ) .
162+
119163### tests (` GRAPHQL_BUILD_TESTS=ON ` )
120164
121165- Unit testing: [ Google Test] ( https://github.com/google/googletest ) for the unit testing framework. If you don't want to
0 commit comments