Skip to content

Commit faaa2cd

Browse files
committed
Update README describing clientgen and graphqlclient
1 parent d432a8f commit faaa2cd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ service, you can use the same GraphQL client code to access your native data sou
2323
service online. You might even be able to share some more of that code between a progressive web
2424
app 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 send requests and parse responses
32+
into a `graphql::response::Value` (e.g. with the `graphqljson` library) in your code.
33+
2634
# Getting Started
2735

2836
## Related projects
@@ -116,6 +124,41 @@ adds a runtime dependency on a Boost DLL. The `schemagen` tool won't run without
116124
the install of Boost, vcpkg also takes care of installing the dependencies next to `schemagen.exe` when building the
117125
Windows and UWP shared library targets (the platform triplets which don't end in `-static`).
118126

127+
### clientgen
128+
129+
The `clientgen` utility is based on `schemagen` and shares the same external dependencies. The command line arguments
130+
are almost the same, except it takes an extra file for the request document and there is no equivalent to `--no-stubs` or
131+
`--separate-files`:
132+
```
133+
Usage: clientgen [options] <schema file> <request file> <output filename prefix> <output namespace>
134+
Command line options:
135+
--version Print the version number
136+
-? [ --help ] Print the command line options
137+
-v [ --verbose ] Verbose output including generated header names as
138+
well as sources
139+
-s [ --schema ] arg Schema definition file path
140+
-r [ --request ] arg Request document file path
141+
-o [ --operation ] arg Operation name if the request document contains more
142+
than one
143+
-p [ --prefix ] arg Prefix to use for the generated C++ filenames
144+
-n [ --namespace ] arg C++ sub-namespace for the generated types
145+
--source-dir arg Target path for the <prefix>Client.cpp source file
146+
--header-dir arg Target path for the <prefix>Client.h header file
147+
--no-introspection Do not expect support for Introspection
148+
```
149+
150+
This utility should output one header and one source file for each request document. A request document may contain
151+
more than one operation, in which case you must specify the `--operation` (or `-o`) parameter to indicate which one
152+
should be used to generate the files. If you want to generate client code for more than one operation in the same
153+
document, you will need to run `clientgen` more than once and specify another operation name each time.
154+
155+
The generated code depends on the `graphqlclient` library for serialization of built-in types. If you link the generated
156+
code, you'll also need to link `graphqlclient`, `graphqlpeg` for the pre-parsed, pre-validated request AST, and
157+
`graphqlresponse` for the `graphql::response::Value` implementation.
158+
159+
Sample output for `clientgen` is in the [samples/client](samples/client) directory, and each sample is consumed by
160+
a unit test in [test/ClientTests.cpp](test/ClientTests.cpp).
161+
119162
### tests (`GRAPHQL_BUILD_TESTS=ON`)
120163

121164
- Unit testing: [Google Test](https://github.com/google/googletest) for the unit testing framework. If you don't want to

0 commit comments

Comments
 (0)