Repository navigation
Description
This is where I'm going to start tracking features for 4.0, the next major version of cppgraphqlgen. This will be a breaking change for existing consumers, so it's an opportunity to cleanup deprecated methods and simplify some of the APIs. I'm also going to adopt C++20 features if they are well enough supported on Windows, Linux, and macOS.
- Stand up a branch for 4.0 and start making PRs against that: https://github.com/microsoft/cppgraphqlgen/tree/next.
- C++20: Co-routines Implemented in https://github.com/microsoft/cppgraphqlgen/tree/next.
- Finer grained asynchrony Substitute a custom
awaitableinstead of passing astd::launchenum value to allow plugging in a custom thread pool for example. - C++20: Concepts In progress, used for type-erasure (see below), but still more use cases to consider.
- Type Erasure instead of inheritance Implemented in https://github.com/microsoft/cppgraphqlgen/tree/next. Solves const methods prevent storing context in subclasses #171 and makes the design much more decoupled. Depends on C++20 Concepts for the conditional handling of stubs which may be unimplemented on the target type.
- Use specific types for interfaces and unions instead of
service::ObjectGenerate type-erased objects for interface types, and returnstd::variant<>for the options in a union. - Simplified code gen by removing options or making new defaults (e.g.
--no-stubsby default, type erased headers instead of inheritance, etc.). - Add CMake functions to module config which help with codegen targets (Unable to use cppgraphqlgen #170) Particularly
schemagen --separate-files. Might be able to make--separate-filesthe only option to simplifyschemagenand improve incremental build times. - Otherwise modernize CMake Bump the minimum required version as necessary, remove fallbacks and global config variables for earlier versions. Partially implemented in https://github.com/microsoft/cppgraphqlgen/tree/next.
- Make separate .cpp files include only the
...Object.hheaders that they reference in their return types. Tweak headers to make compilation faster #156 - Update to the recently released https://spec.graphql.org/October2021/ version of GraphQL itself.
- Export a target for RapidJSON internal details Could be done with a minor version update, but should be implemented in 4.0 at the latest: Export writeResponse and SubscriptionKey based delivery #169.
- Allow returning
std::shared_ptr<T>from getters and avoid/defer memory copies inresponse::ValueSee discussion below. Type-Erasure can make this cleaner since you can actually make that the return type of the getter, but it should work in 3.0 as well where the getters all returnservice::FieldResult. - Update docs
I've decided to postpone adopting these C++20 features because support is still uneven, and several of them require using compiler flags to enable them:
- C++20: Modules Pending, requires support in CMake, should make compilation of templates faster.
- C++20: Ranges Pending, should modernize a lot of begin/end iterator usage.
- C++20: std::fmt instead of std::ostringstream Pending, may require update to MSVC for standards errata.
This proved too complicated. Since FieldResult (now AwaitableScalar/AwaitableObject) uses the modified type wrapped in std::vector and std::optional, it can't just wrap the result in a known service::Object type-erased wrapper. To make this work, the field accessor return type would need to be parameterized with all of the same modifiers as ModifiedResult instead of the C++ type, which would make deciphering the correct type to use in a field accessor implementation much harder:
- Implicitly convert to type-erased objects in
service::FieldResultWe should be able to just return thestd::shared_ptr<T>and letservice::FieldResultwrap it, since it knows the expected type-erased object type. Even better, could it implicitly handle conversions of the value_type instd::vectororstd::optional, and nest the convertible types that way? The logic inservice::ModifiedResultseems to suggest it's possible.
I'll update this list as new features crop up and as I/we make progress on it.
Activity
gitmodimo commentedon Dec 1, 2021
I have few suggestions for next version (apart from previously mentioned #169 #171). While implementing solution based on this library I can see few places where we can do better.
Major changes:
For example if we have big array of integers and we want to serve it with current approach we have to copy the array each time. If we allow returning references eg. by expanding variant within FieldResult to hold shared_ptr/weak_ptr/reference (or even access functor), we can skip the copy and gain significant performance boost.
Minor changes:
I can do some groundwork on first two proposals since I need them anyway. However it would be a waste if they would not be used/implemented another way. Bill Avery (@wravery) what is you view on all this?
EDIT:
On the second thought 2. does not seem to be feasible since PEG needs to understand syntax of custom type?
wravery commentedon Dec 1, 2021
I'll need to think about how this could be generalized some more. At some point, it needs to effectively copy or move the value into the response document, and eventually it needs to be converted to a
response::Valueand typically serialized to a JSON string buffer. Returning by value at least allows the construction of theresponse::Valueto use move semantics and avoid an implicit copy there.I have another experimental branch where I've been using type erasure instead of inheriting from the generated schema types: https://github.com/microsoft/cppgraphqlgen/tree/next. This already solves #171, since the getter signatures are no longer inherited. They just need to satisfy a concept which says that you can call a method with that name and implicitly convert any parameters that were passed, and the return type needs to be explicitly convertible to
service::FieldResult. You don't need to match the exact return or argument types, or theconst/noexceptspecifiers. It's still very experimental, but I think if we want to enable flexible return types like references, it should probably be built on top of this.Yes, custom scalars are opaque to the schema. There are a couple of examples in the GraphQL spec, of things like geolocation coordinates or a complex DateTime type, but it's up to the service and client implementations to use consistent conventions when handling them.
Makes sense. 👍🏼
Yes, this grew out of maintaining backwards compatibility with the original synchronous APIs, I've been waiting for 4.0 to clean up the disparity. I'm also planning on replacing the launch policy with a custom awaitable (with defaults that behave as before), so it should be possible for consumers to plug in their own thread pools or task engine.
You're welcome to work on any of these 😄, but let me merge some of my progress in my personal fork with a new branch in the upstream repo first. Then we'll have a common base commit. I'll add a task to the list for this issue so you know when it's ready. Done: https://github.com/microsoft/cppgraphqlgen/tree/next
wravery commentedon Dec 1, 2021
It turns out this already works in this branch. 😄 Since
service::FieldResultuses perfect forwarding in a template constructor, it's able to construct its_valuemember with either aconstreference or an r-value reference and move semantics.Although the
service::FieldResultwill still perform a copy in this case, it makes the getters a lot more reusable, especially now that theservice::FieldParamsargument is optional. For instance, I was able to remove and replace a bunch of redundant accessor methods in thestar_warsdirectory:with calls directly to the simplified getter which now has the same signature:
gitmodimo commentedon Dec 2, 2021
I tried compiling it, however at this point I am stuck at gcc 10.2 which does not seem to cope with coroutines :( .
GraphQLService.cpp:1878:1: internal compiler error: in captures_temporary, at cp/coroutines.cc:2799For now I will stick to version 3.
I tried profiling my use case to verify copying is the issue. You are correct. I think I now better understand how all of this works. Copying is not the bottleneck. Building response document is. It is extremely expensive. Since usually we only convert it to JSON maybe we skip the step of building this document? Or at least enable such approach.
The way I see it at this point (I am still new to all this codebase) is we create SAXVisitor (functionally similar to SelectionVisitor) that takes as template argument generic SAX interface (ex. like one in RapidJson) and instead of building response invokes relevant SAX methods (beginObject, endObject, Key, Int etc.).
That way we skip building response document and build JSON response on the fly very efficiently. Additionally JSON implementation is nicely separated by SAX interface common to all JSON libraries.
wravery commentedon Dec 2, 2021
The
response::toJSONfunction in the defaultRapidJSONversion ofgraphqljsondoes use a SAX interface to perform the serialization. We never actually build a full JSON DOM usingRapidJSON. The role ofresponse::Valueis to be a higher level abstraction of a JSON value, since GraphQL doesn't actually specify that the results are JSON. I'm not even sure the spec requires that they are serializable, which is something thatclientgencan take advantage of (in-process, or with shared memory) to convertresponse::Valueto strongly typed DTOs without any JSON library involved.I think if we want to completely avoid copying, and the implementer is sure that they can keep the values alive long enough to return references, then there might be a way to let
response::Valueandservice::FieldResulthold onto additionalstd::varianttypes forstd::cref<T>and defer copying until it reachesresponse::toJSON. It would need to be plumbed through a lot of template code which expects return-by-value and move semantics, though. It would also be almost impossible to reason about theresponse::Valuelifetime, so to be safe it should really usestd::shared_ptr<T>. Even though that adds some of its own overhead, it's the only way to prevent a mess of dangling references.This would be a very big change indeed, but it may not even be a breaking change. If it's integrated at the
service::FieldResultlevel, so getters can start returningstd::shared_ptr<T>and implicitly constructing theservice::FieldResultfrom that, then I think it would work in 3.0 as well. I'll add it to the list for consideration in 4.0, and then if it works, maybe we could backport it to a final minor version release of 3.0.gitmodimo commentedon Dec 3, 2021
I now understand how it works. I must say all this is very cleverly thought through.
I also narrowed down the performance hit I receive. Consider big vector of scalar types. During conversion it explodes in to vector of futures (each validating the same wrappedParams) and each element is then stored in
Value.It seems a way forward for me is to define custom scalar type in schema and use it instead of this big array. To do so I need to extend Value type to hold my arbitrary data and provide accessor for it. My first idea is to extend variant and allow it to store some abstract
std::unique_ptr<CustomScalarBase>. Then it is up to user what is stored inside of it, whether it is reference or shared_ptr.EDIT:
I tried and it fixed all my performance issues. Here is relevant commit in my fork. This generally allows putting custom types in Value. I am not sure this can be easily extended for arguments? Diving into PEG is beyond me at this point.
In my current solution I am abusing this new custom type to handle my array as a whole in order to gain performance. Maybe future version could recognise 'nondivisible' types like arrays(ones that query cannot dissect it in any way) and generate code to handle them as a whole?
wravery commentedon Dec 7, 2021
I think there are a couple of ways to handle this:
CustomTypeBaseto implementtoJSONandparseJSON, or simpler,CustomTypewithstd::shared_ptr<response::Value>.Using a
std::shared_ptr<response::Value>would let all of the existing code work, it would just need to dereference theshared_ptr. Instead of keeping a type that needs to be transformed eventually into aresponse::Valueand returning that from the getter, the implementer could build and cache the result in astd::shared_ptr<response::Value>member and hand out copies of theshared_ptr.It should be pretty straightforward to implement this for scalars since they already return a
response::Valueand convert it withservice::ModifiedResult<>. Making other return types take either a std::shared_ptr or the embedded type might be trickier (again, helped by flexible return types in 4.0 with type erasure).wravery commentedon Dec 7, 2021
gitmodimo , if you can get a minor version upgrade, it looks like this works in gcc 10.3.0. That's what the Linux CI build uses on the
nextbranch:gitmodimo commentedon Dec 10, 2021
Unfortunately it is too big of undertaking. I am using precompiled set of tools from vendor. The tool are targeting aarch64 and at this point replacing toolchain is not viable.
I went with virtual function approach. I defined my CustomType abstract class (outside of library):
And then I implemented my custom type holding array of doubles as a reference:
Then in a getter I return
return response::Value{std::make_unique<floatArray>(line.x)};.All this works very efficiently. Of course I had to reimplement writeResponse to handle my custom types:
Not sure how much of this fits inside of the library. At this point I tried to keep library modifications to minimum. This seems flexible enough to handle all unusual cases.
Currently in my application I rely on two changes Value storing virtual CustomTypeBase and SubscriptionKey based delivery. I would really appreciate if future version of the library would incorporate equivalent functionalities (SubscriptionKey based delivery is already on todo list).
YJPrakash commentedon Dec 29, 2021
I want to eagerly write a GraphQL API service from the CPP program for flat files. I struggle, when using make utility to compile cppgraphql codes in my project. Please take a look at it from StackOverflow question: https://stackoverflow.com/questions/70496296/which-is-best-way-to-write-graphql-api-for-flat-file-management .
environment setup:
OS: Ubuntu 20.04.3 LTS
ARCH: amd64
cppgraphqlgen service: 3.6.0
PEGTL version: 3.2.0
following errors I get when I am compiling. What should I need to follow for work without cmake?
gcc -pthread -rdynamic -I/usr/include/node '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-D__STDC_FORMAT_MACROS' '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DBUILDING_NODE_EXTENSION' -c nothing.c -o nothing.o g++ -Os -O3 -fPIC -Ofast -std=gnu++17 '-DNODE_GYP_MODULE_NAME=HelloClient' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-D__STDC_FORMAT_MACROS' '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DBUILDING_NODE_EXTENSION' -frtti -fexceptions -pthread -Wall -Wextra -Wno-unused-parameter -fno-omit-frame-pointer -std=gnu++1y -fexceptions -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/separategraphql.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/graphqljson.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/separateschema.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/graphqlintrospection.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/graphqlservice.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/graphqlresponse.a -L/home/jeya/cpp-graphql-projects/cppgraphqlgen/src/graphqlpeg.a -I/usr/include/node-addon-api -I/usr/include/node hello/HelloClient.cpp -o hello/HelloClient.o In file included from /usr/local/include/graphqlservice/GraphQLClient.h:21, from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLResponse.h:153:59: error: ‘std::string_view’ has not been declared 153 | GRAPHQLRESPONSE_EXPORT MapType::const_iterator find(std::string_view name) const; | ^~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLResponse.h:156:38: error: declaration of ‘operator[]’ as non-function 156 | GRAPHQLRESPONSE_EXPORT const Value& operator[](std::string_view name) const; | ^~~~~~~~ /usr/local/include/graphqlservice/GraphQLResponse.h:156:47: error: expected ‘;’ at end of member declaration 156 | GRAPHQLRESPONSE_EXPORT const Value& operator[](std::string_view name) const; | ^ | ; /usr/local/include/graphqlservice/GraphQLResponse.h:156:65: error: expected ‘)’ before ‘name’ 156 | GRAPHQLRESPONSE_EXPORT const Value& operator[](std::string_view name) const; | ~ ^~~~~ | ) /usr/local/include/graphqlservice/GraphQLResponse.h:164:42: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:164:42: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:164:86: error: template argument 1 is invalid 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:164:42: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:164:42: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:164:86: error: template argument 1 is invalid 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:164:25: error: invalid use of template-name ‘std::enable_if_t’ without an argument list 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~~~ In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits:2554:11: note: ‘template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type’ declared here 2554 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; | ^~~~~~~~~~~ In file included from /usr/local/include/graphqlservice/GraphQLClient.h:21, from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLResponse.h:164:36: error: expected ‘,’ or ‘...’ before ‘<’ token 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:170:33: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 170 | typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:170:33: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’? 170 | typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~~~~~~~ | is_same /usr/local/include/graphqlservice/GraphQLResponse.h:170:77: error: template argument 1 is invalid 170 | typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:170:78: error: expected identifier before ‘,’ token 170 | typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:170:78: error: expected unqualified-id before ‘,’ token /usr/local/include/graphqlservice/GraphQLResponse.h:182:37: error: ‘is_rvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_rvalue_reference’? 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~~~~~~~~~~~~~~~~~~~ | is_rvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:182:37: error: ‘is_rvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_rvalue_reference’? 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~~~~~~~~~~~~~~~~~~~ | is_rvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:182:72: error: template argument 1 is invalid 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:182:37: error: ‘is_rvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_rvalue_reference’? 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~~~~~~~~~~~~~~~~~~~ | is_rvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:182:37: error: ‘is_rvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_rvalue_reference’? 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~~~~~~~~~~~~~~~~~~~ | is_rvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:182:72: error: template argument 1 is invalid 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:182:20: error: invalid use of template-name ‘std::enable_if_t’ without an argument list 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~~~~~~~~~ In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits:2554:11: note: ‘template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type’ declared here 2554 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; | ^~~~~~~~~~~ In file included from /usr/local/include/graphqlservice/GraphQLClient.h:21, from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLResponse.h:182:31: error: expected ‘,’ or ‘...’ before ‘<’ token 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:182:2: error: ‘template<class ReferenceType> void graphql::response::Value::set(int)’ cannot be overloaded with ‘template<class ValueType> void graphql::response::Value::set(int)’ 182 | set(typename std::enable_if_t<std::is_rvalue_reference_v<ReferenceType>, ReferenceType> value) | ^~~ /usr/local/include/graphqlservice/GraphQLResponse.h:164:7: note: previous declaration ‘template<class ValueType> void graphql::response::Value::set(int)’ 164 | void set(typename std::enable_if_t<std::is_same_v<std::decay_t<ValueType>, ValueType>, | ^~~ /usr/local/include/graphqlservice/GraphQLResponse.h:191:8: error: ‘is_lvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_lvalue_reference’? 191 | std::is_lvalue_reference_v< | ^~~~~~~~~~~~~~~~~~~~~ | is_lvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:191:8: error: ‘is_lvalue_reference_v’ is not a member of ‘std’; did you mean ‘is_lvalue_reference’? 191 | std::is_lvalue_reference_v< | ^~~~~~~~~~~~~~~~~~~~~ | is_lvalue_reference /usr/local/include/graphqlservice/GraphQLResponse.h:192:17: error: template argument 1 is invalid 192 | ReferenceType> && std::is_const_v<typename std::remove_reference_t<ReferenceType>>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:192:19: error: expected identifier before ‘&&’ token 192 | ReferenceType> && std::is_const_v<typename std::remove_reference_t<ReferenceType>>, | ^~ /usr/local/include/graphqlservice/GraphQLResponse.h:192:37: error: expected initializer before ‘<’ token 192 | ReferenceType> && std::is_const_v<typename std::remove_reference_t<ReferenceType>>, | ^ /usr/local/include/graphqlservice/GraphQLResponse.h:235:24: error: ‘variant’ in namespace ‘std’ does not name a template type 235 | using TypeData = std::variant<MapData, ListType, StringData, NullData, BooleanType, IntType, | ^~~~~~~ /usr/local/include/graphqlservice/GraphQLResponse.h:235:19: note: ‘std::variant’ is only available from C++17 onwards 235 | using TypeData = std::variant<MapData, ListType, StringData, NullData, BooleanType, IntType, | ^~~ /usr/local/include/graphqlservice/GraphQLResponse.h:238:2: error: ‘TypeData’ does not name a type 238 | TypeData _data; | ^~~~~~~~ /usr/local/include/graphqlservice/GraphQLResponse.h: In member function ‘void graphql::response::Value::set(int)’: /usr/local/include/graphqlservice/GraphQLResponse.h:184:46: error: ‘value’ was not declared in this scope; did you mean ‘Value’? 184 | set<std::decay_t<ReferenceType>>(std::move(value)); | ^~~~~ | Value In file included from /usr/local/include/graphqlservice/GraphQLClient.h:23, from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/internal/Version.h: At global scope: /usr/local/include/graphqlservice/internal/Version.h:13:16: error: ‘string_view’ in namespace ‘std’ does not name a type 13 | constexpr std::string_view FullVersion { "3.6.0" }; | ^~~~~~~~~~~ /usr/local/include/graphqlservice/internal/Version.h:13:11: note: ‘std::string_view’ is only available from C++17 onwards 13 | constexpr std::string_view FullVersion { "3.6.0" }; | ^~~ In file included from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLClient.h:43:31: error: ‘variant’ in namespace ‘std’ does not name a template type 43 | using ErrorPathSegment = std::variant<response::StringType, response::IntType>; | ^~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:43:26: note: ‘std::variant’ is only available from C++17 onwards 43 | using ErrorPathSegment = std::variant<response::StringType, response::IntType>; | ^~~ /usr/local/include/graphqlservice/GraphQLClient.h:50:14: error: ‘ErrorPathSegment’ was not declared in this scope 50 | std::vector<ErrorPathSegment> path; | ^~~~~~~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:50:30: error: template argument 1 is invalid 50 | std::vector<ErrorPathSegment> path; | ^ /usr/local/include/graphqlservice/GraphQLClient.h:50:30: error: template argument 2 is invalid /usr/local/include/graphqlservice/GraphQLClient.h:84:9: error: ‘optional’ is not a member of ‘std’ 84 | std::optional<typename VariableTraits<U, Other...>::type>, | ^~~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:84:9: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:84:9: error: ‘optional’ is not a member of ‘std’ /usr/local/include/graphqlservice/GraphQLClient.h:84:9: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:84:60: error: wrong number of template arguments (2, should be 3) 84 | std::optional<typename VariableTraits<U, Other...>::type>, | ^ In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits:2558:11: note: provided for ‘template<bool _Cond, class _Iftrue, class _Iffalse> using conditional_t = typename std::conditional::type’ 2558 | using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type; | ^~~~~~~~~~~~~ In file included from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLClient.h:84:61: error: expected identifier before ‘,’ token 84 | std::optional<typename VariableTraits<U, Other...>::type>, | ^ /usr/local/include/graphqlservice/GraphQLClient.h: In static member function ‘static std::enable_if_t<(graphql::client::TypeModifier::Nullable == Modifier), graphql::response::Value> graphql::client::ModifiedVariable<Type>::serialize(typename graphql::client::ModifiedVariable<Type>::VariableTraits<Type, Modifier, Other ...>::type&&)’: /usr/local/include/graphqlservice/GraphQLClient.h:118:25: error: ‘nullopt’ is not a member of ‘std’ 118 | nullableValue = std::nullopt; | ^~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h: At global scope: /usr/local/include/graphqlservice/GraphQLClient.h:183:9: error: ‘optional’ is not a member of ‘std’ 183 | std::optional<typename ResponseTraits<U, Other...>::type>, | ^~~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:183:9: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:183:9: error: ‘optional’ is not a member of ‘std’ /usr/local/include/graphqlservice/GraphQLClient.h:183:9: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:183:60: error: wrong number of template arguments (2, should be 3) 183 | std::optional<typename ResponseTraits<U, Other...>::type>, | ^ In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits:2558:11: note: provided for ‘template<bool _Cond, class _Iftrue, class _Iffalse> using conditional_t = typename std::conditional::type’ 2558 | using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type; | ^~~~~~~~~~~~~ In file included from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLClient.h:183:61: error: expected identifier before ‘,’ token 183 | std::optional<typename ResponseTraits<U, Other...>::type>, | ^ /usr/local/include/graphqlservice/GraphQLClient.h:208:8: error: ‘optional’ is not a member of ‘std’ 208 | std::optional<typename ResponseTraits<Type, Other...>::type>> | ^~~~~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:208:8: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:208:8: error: ‘optional’ is not a member of ‘std’ /usr/local/include/graphqlservice/GraphQLClient.h:208:8: note: ‘std::optional’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLClient.h:208:58: error: template argument 2 is invalid 208 | std::optional<typename ResponseTraits<Type, Other...>::type>> | ^~~~ /usr/local/include/graphqlservice/GraphQLClient.h:208:62: error: expected identifier before ‘>’ token 208 | std::optional<typename ResponseTraits<Type, Other...>::type>> | ^~ /usr/local/include/graphqlservice/GraphQLClient.h:208:62: error: expected unqualified-id before ‘>’ token In file included from hello/HelloClient.h:12, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLParse.h:37:46: error: ‘string_view’ is not a member of ‘std’ 37 | GRAPHQLPEG_EXPORT ast parseSchemaString(std::string_view input); | ^~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLParse.h:37:46: note: ‘std::string_view’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLParse.h:38:44: error: ‘string_view’ is not a member of ‘std’ 38 | GRAPHQLPEG_EXPORT ast parseSchemaFile(std::string_view filename); | ^~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLParse.h:38:44: note: ‘std::string_view’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLParse.h:40:40: error: ‘string_view’ is not a member of ‘std’ 40 | GRAPHQLPEG_EXPORT ast parseString(std::string_view input); | ^~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLParse.h:40:40: note: ‘std::string_view’ is only available from C++17 onwards /usr/local/include/graphqlservice/GraphQLParse.h:41:38: error: ‘string_view’ is not a member of ‘std’ 41 | GRAPHQLPEG_EXPORT ast parseFile(std::string_view filename); | ^~~~~~~~~~~ /usr/local/include/graphqlservice/GraphQLParse.h:41:38: note: ‘std::string_view’ is only available from C++17 onwards In file included from hello/HelloClient.cpp:6: hello/HelloClient.h:46:7: error: ‘optional’ in namespace ‘std’ does not name a template type 46 | std::optional<response::StringType> hello {}; | ^~~~~~~~ hello/HelloClient.h:46:2: note: ‘std::optional’ is only available from C++17 onwards 46 | std::optional<response::StringType> hello {}; | ^~~ hello/HelloClient.cpp: In lambda function: hello/HelloClient.cpp:39:47: error: no match for call to ‘(graphql::peg::ast) (const string&)’ 39 | auto ast = peg::parseString(GetRequestText()); | ^ hello/HelloClient.cpp: In function ‘graphql::client::query::Query::Response graphql::client::query::Query::parseResponse(graphql::response::Value&&)’: hello/HelloClient.cpp:60:24: error: unable to find string literal operator ‘operator""sv’ with ‘const char [6]’, ‘long unsigned int’ arguments 60 | if (member.first == R"js(hello)js"sv) | ^~~~~~~~~~~~~~~~ hello/HelloClient.cpp:62:12: error: ‘struct graphql::client::query::Query::Response’ has no member named ‘hello’ 62 | result.hello = ModifiedResponse<response::StringType>::parse<TypeModifier::Nullable>(std::move(member.second)); | ^~~~~ hello/HelloClient.cpp:62:114: error: no matching function for call to ‘graphql::client::ModifiedResponse<std::__cxx11::basic_string<char> >::parse<graphql::client::TypeModifier::Nullable>(std::remove_reference<graphql::response::Value&>::type)’ 62 | result.hello = ModifiedResponse<response::StringType>::parse<TypeModifier::Nullable>(std::move(member.second)); | ^ In file included from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLClient.h:200:2: note: candidate: ‘template<graphql::client::TypeModifier Modifier, graphql::client::TypeModifier ...Other> static std::enable_if_t<((graphql::client::TypeModifier::None == Modifier) && (sizeof... (Other) == 0)), Type> graphql::client::ModifiedResponse<Type>::parse(graphql::response::Value&&) [with graphql::client::TypeModifier Modifier = Modifier; graphql::client::TypeModifier ...Other = {Other ...}; Type = std::__cxx11::basic_string<char>]’ 200 | parse(response::Value&& response) | ^~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:200:2: note: template argument deduction/substitution failed: In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits: In substitution of ‘template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::__cxx11::basic_string<char>]’: /usr/local/include/graphqlservice/GraphQLClient.h:200:2: required by substitution of ‘template<graphql::client::TypeModifier Modifier, graphql::client::TypeModifier ...Other> static std::enable_if_t<((graphql::client::TypeModifier::None == Modifier) && (sizeof... (Other) == 0)), std::__cxx11::basic_string<char> > graphql::client::ModifiedResponse<std::__cxx11::basic_string<char> >::parse<Modifier, Other ...>(graphql::response::Value&&) [with graphql::client::TypeModifier Modifier = graphql::client::TypeModifier::Nullable; graphql::client::TypeModifier ...Other = {}]’ hello/HelloClient.cpp:62:114: required from here /usr/include/c++/10/type_traits:2554:11: error: no type named ‘type’ in ‘struct std::enable_if<false, std::__cxx11::basic_string<char> >’ 2554 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; | ^~~~~~~~~~~ In file included from hello/HelloClient.h:11, from hello/HelloClient.cpp:6: /usr/local/include/graphqlservice/GraphQLClient.h:224:2: note: candidate: ‘template<graphql::client::TypeModifier Modifier, graphql::client::TypeModifier ...Other> static std::enable_if_t<(graphql::client::TypeModifier::List == Modifier), std::vector<typename graphql::client::ModifiedResponse<Type>::ResponseTraits<Type, Other ...>::type> > graphql::client::ModifiedResponse<Type>::parse(graphql::response::Value&&) [with graphql::client::TypeModifier Modifier = Modifier; graphql::client::TypeModifier ...Other = {Other ...}; Type = std::__cxx11::basic_string<char>]’ 224 | parse(response::Value&& response) | ^~~~~ /usr/local/include/graphqlservice/GraphQLClient.h:224:2: note: template argument deduction/substitution failed: In file included from /usr/include/c++/10/bits/move.h:57, from /usr/include/c++/10/bits/stl_function.h:60, from /usr/include/c++/10/functional:49, from /usr/include/node-addon-api/napi.h:5, from hello/HelloClient.cpp:5: /usr/include/c++/10/type_traits: In substitution of ‘template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >]’: /usr/local/include/graphqlservice/GraphQLClient.h:224:2: required by substitution of ‘template<graphql::client::TypeModifier Modifier, graphql::client::TypeModifier ...Other> static std::enable_if_t<(graphql::client::TypeModifier::List == Modifier), std::vector<typename graphql::client::ModifiedResponse<std::__cxx11::basic_string<char> >::ResponseTraits<std::__cxx11::basic_string<char>, Other ...>::type, std::allocator<typename graphql::client::ModifiedResponse<std::__cxx11::basic_string<char> >::ResponseTraits<std::__cxx11::basic_string<char>, Other ...>::type> > > graphql::client::ModifiedResponse<std::__cxx11::basic_string<char> >::parse<Modifier, Other ...>(graphql::response::Value&&) [with graphql::client::TypeModifier Modifier = graphql::client::TypeModifier::Nullable; graphql::client::TypeModifier ...Other = {}]’ hello/HelloClient.cpp:62:114: required from here /usr/include/c++/10/type_traits:2554:11: error: no type named ‘type’ in ‘struct std::enable_if<false, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > > >’ 2554 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; | ^~~~~~~~~~~ make: *** [makefile:91: hello/HelloClient.o] Error 1 jeya@client11:~/cpp-graphql-projects/node-samples-cppgraphqlgen$ g++ --version g++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.wravery commentedon Dec 29, 2021
It looks like you have 2 different
-std=...parameters when you invokeg++.YJPrakash commentedon Dec 30, 2021
Thank you Bill Avery (@wravery) . after changing that modification in my make file. I am getting the output without the error of the HelloClient program. Please check my question also in stackoverflow. In your samples of cppgraphiql doesn't run with dependency of electron-cppgraphql. Other than that. In my project we were using Napi.h. How to rewrite your samples for TodayMock with Napi.h. I am creating HelloMock like TodayMock from samples code placed in project directory. I commented Napi.h codings in "hello.cpp". But in this time i got the following errors
makefile
HelloMock.h
HelloMock.cpp
hello.cpp
Error:
Using Schema
schema.hello.graphql
query.hello.graphql
Excpected output
How to resolve that error message and how to get the final expected output?
wravery commentedon Dec 30, 2021
I went ahead and moved this to a new issue: #191