Skip to content

Commit c49ec34

Browse files
committed
Write responses.md content
1 parent 6eca5ff commit c49ec34

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

doc/response.md

Whitespace-only changes.

doc/responses.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Query Responses
2+
3+
## Value Types
4+
5+
As the comment in
6+
[GraphQLResponse.h](../include/graphqlservice/GraphQLResponse.h) says, GraphQL
7+
responses are not technically JSON-specific, although that is probably the most
8+
common way of representing them. These are the primitive types that may be
9+
represented in GraphQL, as of the
10+
[June 2018 spec](https://facebook.github.io/graphql/June2018/#sec-Serialization-Format):
11+
12+
```c++
13+
enum class Type : uint8_t
14+
{
15+
Map, // JSON Object
16+
List, // JSON Array
17+
String, // JSON String
18+
Null, // JSON null
19+
Boolean, // JSON true or false
20+
Int, // JSON Number
21+
Float, // JSON Number
22+
EnumValue, // JSON String
23+
Scalar, // JSON any type
24+
};
25+
```
26+
27+
## Common Accessors
28+
29+
Anywhere that a GraphQL result, a scalar type, or a GraphQL value literal is
30+
used, it's represented in `cppgraphqlgen` using an instance of
31+
`graphql::response::Value`. These can be constructed with any of the types in
32+
the `graphql::response::Type` enum, and depending on the type with which they
33+
are initialized, different accessors will be enabled.
34+
35+
Every type implements specializations for some subset of `get()` which does
36+
not allocate any memory, `set(...)` which takes an r-value, and `release()`
37+
which transfers ownership along with any extra allocations to the caller.
38+
Which of these methods are supported and what C++ types they use are
39+
determined by the `ValueTypeTraits<ValueType>` template and its
40+
specializations.
41+
42+
## Map and List
43+
44+
`Map` and `List` types enable collection methods like `reserve(size_t)`,
45+
`size()`, and `emplace_back(...)`. `Map` additionally implements `begin()`
46+
and `end()` for range-based for loops and `find(const std::string&)` and
47+
`operator[](const std::string&)` for key-based lookups. `List` has an
48+
`operator[](size_t)` for index-based instead of key-based lookups.

0 commit comments

Comments
 (0)