Skip to content

Plans for cppgraphqlgen 4.0 #172

Closed

Description

@wravery

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 awaitable instead of passing a std::launch enum 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::Object Generate type-erased objects for interface types, and return std::variant<> for the options in a union.
  • Simplified code gen by removing options or making new defaults (e.g. --no-stubs by 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-files the only option to simplify schemagen and 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.h headers 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 in response::Value See 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 return service::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::FieldResult We should be able to just return the std::shared_ptr<T> and let service::FieldResult wrap it, since it knows the expected type-erased object type. Even better, could it implicitly handle conversions of the value_type in std::vector or std::optional, and nest the convertible types that way? The logic in service::ModifiedResult seems to suggest it's possible.

I'll update this list as new features crop up and as I/we make progress on it.

Activity

  1. added this to the 4.0 milestone on Nov 27, 2021
  2. gitmodimo commented on Dec 1, 2021

    @gitmodimo

    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:

    1. Allow returning values by reference.
      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.
    2. GraphQL defines custom scalar types. It would be very useful for user to allow creation custom scalar types in cppgraphqlgen. I see this implemented as abstract subtype of BaseType with all methods needed to convert it to and back from Json. This will remove a lot of tedious coding of implementing a big structure that is always used as whole anyway.

    Minor changes:

    1. SubscriptionKey should be available in ResolverContext::Subscription, ResolverContext::NotifySubscribe and ResolverContext::NotifyUnsubscribe contexts by default. For now I extended context to hold this value.
    2. Events ResolverContext::NotifySubscribe and ResolverContext::NotifyUnsubscribe should be issued regardless of launch policy. This change of behaviour is very misleading. Alternatively provide separate method for NotifySubscribe/Unsubscribe.

    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?

  3. wravery commented on Dec 1, 2021

    @wravery
    ContributorAuthor
    1. Allow returning values by reference.
      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.

    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::Value and typically serialized to a JSON string buffer. Returning by value at least allows the construction of the response::Value to 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 the const/noexcept specifiers. 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.

    1. GraphQL defines custom scalar types. It would be very useful for user to allow creation custom scalar types in cppgraphqlgen. I see this implemented as abstract subtype of BaseType with all methods needed to convert it to and back from Json. This will remove a lot of tedious coding of implementing a big structure that is always used as whole anyway.

    EDIT: On the second thought 2. does not seem to be feasible since PEG needs to understand syntax of custom type?

    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.

    1. SubscriptionKey should be available in ResolverContext::Subscription, ResolverContext::NotifySubscribe and ResolverContext::NotifyUnsubscribe contexts by default. For now I extended context to hold this value.

    Makes sense. 👍🏼

    1. Events ResolverContext::NotifySubscribe and ResolverContext::NotifyUnsubscribe should be issued regardless of launch policy. This change of behaviour is very misleading. Alternatively provide separate method for NotifySubscribe/Unsubscribe.

    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.

    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?

    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

  4. wravery commented on Dec 1, 2021

    @wravery
    ContributorAuthor

    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 the const/noexcept specifiers. 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.

    It turns out this already works in this branch. 😄 Since service::FieldResult uses perfect forwarding in a template constructor, it's able to construct its _value member with either a const reference or an r-value reference and move semantics.

    Although the service::FieldResult will still perform a copy in this case, it makes the getters a lot more reusable, especially now that the service::FieldParams argument is optional. For instance, I was able to remove and replace a bunch of redundant accessor methods in the star_wars directory:

    const response::StringType& id() const noexcept;

    with calls directly to the simplified getter which now has the same signature:

    const response::StringType& getId() const noexcept;
  5. gitmodimo commented on Dec 2, 2021

    @gitmodimo

    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.

    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:2799

    For now I will stick to version 3.

    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::Value and typically serialized to a JSON string buffer.

    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.

  6. wravery commented on Dec 2, 2021

    @wravery
    ContributorAuthor

    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.

    The response::toJSON function in the default RapidJSON version of graphqljson does use a SAX interface to perform the serialization. We never actually build a full JSON DOM using RapidJSON. The role of response::Value is 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 that clientgen can take advantage of (in-process, or with shared memory) to convert response::Value to 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::Value and service::FieldResult hold onto additional std::variant types for std::cref<T> and defer copying until it reaches response::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 the response::Value lifetime, so to be safe it should really use std::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::FieldResult level, so getters can start returning std::shared_ptr<T> and implicitly constructing the service::FieldResult from 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.

  7. gitmodimo commented on Dec 3, 2021

    @gitmodimo

    The role of response::Value is to be a higher level abstraction of a JSON value, since GraphQL doesn't actually specify that the results are JSON.

    I now understand how it works. I must say all this is very cleverly thought through.

    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::Value and service::FieldResult hold onto additional std::variant types for std::cref and defer copying until it reaches response::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 the response::Value lifetime, so to be safe it should really use std::shared_ptr. Even though that adds some of its own overhead, it's the only way to prevent a mess of dangling references.

    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?

  8. wravery commented on Dec 7, 2021

    @wravery
    ContributorAuthor

    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?

    I think there are a couple of ways to handle this:

    • Define pure-virtual methods on CustomTypeBase to implement toJSON and parseJSON, or simpler,
    • Replace CustomType with std::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 the shared_ptr. Instead of keeping a type that needs to be transformed eventually into a response::Value and returning that from the getter, the implementer could build and cache the result in a std::shared_ptr<response::Value> member and hand out copies of the shared_ptr.

    It should be pretty straightforward to implement this for scalars since they already return a response::Value and convert it with service::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).

  9. wravery commented on Dec 7, 2021

    @wravery
    ContributorAuthor

    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:2799

    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 next branch:

    -- The C compiler identification is GNU 10.3.0
    -- The CXX compiler identification is GNU 10.3.0
    
  10. gitmodimo commented on Dec 10, 2021

    @gitmodimo

    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 next branch:

    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 think there are a couple of ways to handle this:
    Define pure-virtual methods on CustomTypeBase to implement toJSON and parseJSON, or simpler,
    Replace CustomType with std::shared_ptrresponse::Value.

    I went with virtual function approach. I defined my CustomType abstract class (outside of library):

    struct CustomType:public graphql::response::CustomTypeBase{
    	virtual void writeJson(rapidjson::Writer<rapidjson::StringBuffer>& writer) const=0;
    };
    
    

    And then I implemented my custom type holding array of doubles as a reference:

    struct floatArray:public webgui::CustomType{
    	floatArray(const std::vector<double> &_vector):vector(_vector){
    
    	}
    
    	void writeJson(rapidjson::Writer<rapidjson::StringBuffer>& writer) const override{
    		writer.StartArray();
    		for(auto d:vector)
    			writer.Double(d);
    		writer.EndArray();
    	}
    	const std::vector<double> &vector;
    };
    

    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:

    case Type::Custom:
    		{
    			auto custom = response.release<graphql::response::CustomType>();
    			auto ptr=static_unique_pointer_cast<CustomType>(std::move(custom));
    			ptr->writeJson(writer);
    			break;
    		}
    

    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).

  11. YJPrakash commented on Dec 29, 2021

    @YJPrakash

    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.
    
  12. wravery commented on Dec 29, 2021

    @wravery
    ContributorAuthor

    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

    It looks like you have 2 different -std=... parameters when you invoke g++.

  13. YJPrakash commented on Dec 30, 2021

    @YJPrakash

    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

    CFLAGS = -Os -O3 -fPIC -Ofast -std=gnu++17
    
    CC = gcc
    CXX = g++
    
    LDFLAGS := \
    	-pthread \
    	-rdynamic
    
    DEFS := \
    	'-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'
    
    # Flags passed to all source files.
    GYP_CFLAGS := \
    	-frtti \
    	-fexceptions \
    	-pthread \
    	-Wall \
    	-Wextra \
    	-Wno-unused-parameter \
    	-fno-omit-frame-pointer
    
    # Flags passed to only C files.
    CFLAGS_C :=
    
    # Flags passed to only C++ files.
    CFLAGS_CC := \
    	-std=gnu++1y \
    	-fexceptions
    
    INC_NAPI := -I/usr/include/node-addon-api
    INC_NODE := -I/usr/include/node
    # INC := -I./separate
    # INC := -I./separate -I../cppgraphqlgen/include -I../cppgraphqlgen/PEGTL/include
    
    # INC_NAPI = -I/usr/lib/node_modules/node-addon-api
    # INC_NODE := -I/usr/include/node
    
    CGI_LIB = -lcgicc
    
    # LIBS := /home/jeya/cpp-graphql-projects/cppgraphqlgen/src
    LIBS := /usr/local/lib
    GRPHQL := -L${LIBS}/libgraphqlclient.a -L${LIBS}/libgraphqljson.a  -L${LIBS}/libgraphqlintrospection.a  -L${LIBS}/libgraphqlservice.a  -L${LIBS}/libgraphqlresponse.a  -L${LIBS}/libgraphqlpeg.a
    NOTH_A = nothing.a
    
    # OBJ = nothing.o ./today/sampleQryParse.o ./hello/HelloClient.o ./hello/hello.o
    
    # ENODE = ${NOTH_A} ./today/sampleQryParse.node ./hello/HelloClient.node ./hello/hello.o
    
    OBJ = nothing.o ./hello/HelloClient.o
    
    ENODE = nothing.a ./hello/HelloClient.node ./hello/hello
    
    # GREET_DEMO = ./greet-demo
    # CLASS_DEMO = ./class-demo
    DEMO := ./today
    HELLO := ./hello
    target: ${OBJ} ${ENODE}
    
    clean:
    	rm -rf *.o *.node *.a
    	rm -rf ${DEMO}/*.o ${DEMO}/*.node
    	rm -rf ${HELLO}/*.o ${HELLO}/*.node
    
    ./today/sampleQryParse.o: ./today/sampleQryParse.cpp
    	${CXX} ${CFLAGS} -shared '-DNODE_GYP_MODULE_NAME=sampleQryParse' ${GYP_CFLAGS} ${INC_NODE} ${INC_NAPI} -c $< -o $@
    
    ./today/sampleQryParse.node: ./today/sampleQryParse.o
    	${CXX} -shared -Wl,-soname=sampleQryParse.node -Wl,--start-group ./today/sampleQryParse.o ${NOTH_A} ${GRPHQL} -Wl,--end-group -o $@
    
    ./hello/hello.o: ./hello/hello.cpp
    	${CXX} ${CFLAGS} '-DNODE_GYP_MODULE_NAME=hello' ${DEFS} ${GYP_CFLAGS} ${INC_NAPI} ${INC_NODE} -c $< -o $@
    
    ./hello/hello.node: ./hello/hello.o
    	${CXX} ${CFLAGS} ./hello/hello.o -shared -Wl,-soname=hello.node -Wl,--start-group -lpthread ${GRPHQL} ${NOTH_A} -Wl,--end-group -o $@
    
    ./hello/hello: ./hello/hello.cpp
    	${CXX} ${CFLAGS} ./hello/hello.cpp -shared -Wl,-soname=hello -Wl,--start-group -lpthread ${GRPHQL} -Wl,--end-group -o $@
    
    # ./hello/HelloClient: ./hello/HelloClient.cpp
    # 	${CXX} ${CFLAGS} $< -o $@
    
    ./hello/HelloClient.o: ./hello/HelloClient.cpp
    	${CXX} ${CFLAGS} '-DNODE_GYP_MODULE_NAME=HelloClient' ${DEFS} ${GYP_CFLAGS} ${INC_NAPI} ${INC_NODE} -c $< -o $@
    
    ./hello/HelloClient.node: ./hello/HelloClient.o
    	${CXX} ${CFLAGS} -shared -Wl,-soname=HelloClient.node -Wl,--start-group ./hello/HelloClient.o ${GRPHQL} -lpthread ${NOTH_A} -Wl,--end-group -o $@
    
    ./today/sampleOne.o: ./today/sample.cpp
    	${CXX} ${CFLAGS} -c $< -o $@
    
    ./today/sampleOne:
    	${CXX} ${CFLAGS} ./today/sample.cpp -shared -Wl,-soname=sampleOne.node -Wl,--start-group ${GRPHQL} -lpthread ${NOTH_A} -Wl,--end-group -o $@
    
    nothing.a: nothing.o
    	ar crs nothing.a $<
    
    nothing.o: nothing.c
    	${CC} ${LDFLAGS} ${INC_NODE} ${DEFS} -c $< -o $@ 
    
    

    HelloMock.h

    #pragma once
    
    #ifndef HELLOMOCK_H
    #define HELLOMOCK_H
    
    #include "HelloSchema.h"
    
    #include <atomic>
    #include <stack>
    
    namespace graphql::hello
    {
        class Hello;
    
        class Query
        {
            using helloLoader = std::function<std::vector<std::shared_ptr<Hello>>()>;
            public:
                explicit Query(helloLoader &&getHelloMsg);
                virtual service::FieldResult<std::optional<response::StringType>> getHelloMsg(service::FieldParams &&params) const final;
            private:
                // Lazy load the fields in each query
                void loadMsg(const std::shared_ptr<service::RequestState> &state) const;
                mutable helloLoader _getHelloMsg;
                mutable std::vector<std::shared_ptr<Hello>> _hello;
        };
    
        class Hello
        {
            public:
                explicit Hello(std::string&& greet);
                virtual service::FieldResult<std::optional<response::StringType>> getGreetMsg() final;
                virtual service::FieldResult<std::optional<response::StringType>> getForceError(
                    service::FieldParams &&) const final
                {
                    throw std::runtime_error(R"ex(this error was forced)ex");
                }
    
            private:
                std::string _greet;
    
            
        };
    
    }
    
    #endif // HELLOMOCK_H
    
    

    HelloMock.cpp

    #include "HelloMock.h"
    
    #include <algorithm>
    #include <iostream>
    
    namespace graphql::hello
    {
    
        Hello::Hello(std::string&& greet) : _greet(greet)
        {
        }
        service::FieldResult<std::optional<response::StringType>> Hello::getGreetMsg()
        {
            return _greet;
        }
    
        Query::Query(helloLoader&& getHelloMsg)
        {
        }
        void Query::loadMsg(const std::shared_ptr<service::RequestState> &state) const
        {
            if (_getHelloMsg)
            {
                _hello = _getHelloMsg();
                _getHelloMsg = nullptr;
            }
        }
    
        // std::shared_ptr<Hello> Query::findHelloMsg(
        //     const service::FieldParams &params, const response::IdType &id) const
        // {
        //     loadMsg(params.state);
    
        //     for (const auto &hello : _hello)
        //     {
        //         if (hello->id() == id)
        //         {
        //             return appointment;
        //         }
        //     }
    
        //     return nullptr;
        // }
    
    } // namespace graphql::hello
    
    

    hello.cpp

    // #include <napi.h>
    #include "HelloMock.h"
    
    #include "graphqlservice/JSONResponse.h"
    #include <cstdio>
    #include <iostream>
    #include <iterator>
    #include <stdexcept>
    
    using namespace graphql;
    
    // Napi::String parseQuery(const Napi::CallbackInfo &info)
    int main(int argc, char **argv)
    {
        // Napi::Env env = info.Env();
        /* From HelloMock*/
        response::StringType helloKey;
    
        std::string fakeHelloKey("hello");
        helloKey.resize(fakeHelloKey.size());
        std::copy(fakeHelloKey.cbegin(), fakeHelloKey.cend(), helloKey.begin());
        
        std::cout << "Created the service..." << std::endl;
    
        auto query = std::make_shared<hello::Query>(
            [&fakeHelloKey]() -> std::vector<std::shared_ptr<hello::Hello>>
            {
                std::cout << "Called getHelloMsg..." << std::endl;
                return {std::make_shared<hello::Hello>("Hello World!")};
            }
        );
            
        auto service = std::make_shared<hello::Operations>(query);
        std::cout << "Created the service..." << std::endl;
    
        try
        {
            peg::ast query;
            // std::string qry = info[0].As<std::string>();
            // query = peg::parseString(std::move(qry));
            if (argc > 1)
            {
                query = peg::parseFile(argv[1]);
            }
            else
            {
                std::istream_iterator<char> start{std::cin >> std::noskipws}, end{};
                std::string input{start, end};
    
                query = peg::parseString(std::move(input));
            }
            if (!query.root)
            {
                std::cerr << "Unknown error!" << std::endl;
                std::cerr << std::endl;
                // return Napi::String::New(env, "1");
                return 1;
            }
    
            std::cout << "Executing query..." << std::endl;
    
            // std::stringstream out;
            // out << response::toJSON(service
            //                             ->resolve(nullptr,
            //                                       query,
            //                                       "",
            //                                       response::Value(response::Type::Map))
            //                             .get());
            // std::string res = out.str();
            // return Napi::String::New(env, res);
            std::cout << response::toJSON(service
                                              ->resolve(nullptr,
                                                        query,
                                                        ((argc > 2) ? argv[2] : ""),
                                                        response::Value(response::Type::Map))
                                              .get())
                      << std::endl;
        }
        catch (const std::runtime_error &ex)
        {
            std::cerr << ex.what() << std::endl;
            // return Napi::String::New(env, "1");
            return 1;
        }
    
        // return Napi::String::New(env, "0");
        return 0;
    }
    
    // Napi::Object Init(Napi::Env env, Napi::Object exports)
    // {
    //     exports.Set("parseQuery", Napi::Function::New(env, parseQuery));
    //     return exports;
    // }
    
    // NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init);
    

    Error:

    ar crs nothing.a nothing.o
    g++ -Os -O3 -fPIC -Ofast -std=gnu++17 -shared -Wl,-soname=HelloClient.node -Wl,--start-group ./hello/HelloClient.o -L/usr/local/lib/libgraphqlclient.a -L/usr/local/lib/libgraphqljson.a  -L/usr/local/lib/libgraphqlintrospection.a  -L/usr/local/lib/libgraphqlservice.a  -L/usr/local/lib/libgraphqlresponse.a  -L/usr/local/lib/libgraphqlpeg.a -lpthread nothing.a -Wl,--end-group -o hello/HelloClient.node
    g++ -Os -O3 -fPIC -Ofast -std=gnu++17 ./hello/hello.cpp -shared -Wl,-soname=hello -Wl,--start-group -lpthread -L/usr/local/lib/libgraphqlclient.a -L/usr/local/lib/libgraphqljson.a  -L/usr/local/lib/libgraphqlintrospection.a  -L/usr/local/lib/libgraphqlservice.a  -L/usr/local/lib/libgraphqlresponse.a  -L/usr/local/lib/libgraphqlpeg.a -Wl,--end-group -o hello/hello
    In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                     from /usr/include/c++/10/bits/allocator.h:46,
                     from /usr/include/c++/10/memory:64,
                     from /usr/local/include/graphqlservice/GraphQLParse.h:21,
                     from /usr/local/include/graphqlservice/GraphQLService.h:21,
                     from /usr/local/include/graphqlservice/internal/Schema.h:9,
                     from ./hello/HelloSchema.h:11,
                     from ./hello/HelloMock.h:6,
                     from ./hello/hello.cpp:2:
    /usr/include/c++/10/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = graphql::hello::Operations; _Args = {std::shared_ptr<graphql::hello::Query>&}; _Tp = graphql::hello::Operations]’:
    /usr/include/c++/10/bits/alloc_traits.h:512:17:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = graphql::hello::Operations; _Args = {std::shared_ptr<graphql::hello::Query>&}; _Tp = graphql::hello::Operations; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<graphql::hello::Operations>]’
    /usr/include/c++/10/bits/shared_ptr_base.h:551:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {std::shared_ptr<graphql::hello::Query>&}; _Tp = graphql::hello::Operations; _Alloc = std::allocator<graphql::hello::Operations>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/10/bits/shared_ptr_base.h:682:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = graphql::hello::Operations; _Alloc = std::allocator<graphql::hello::Operations>; _Args = {std::shared_ptr<graphql::hello::Query>&}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/10/bits/shared_ptr_base.h:1371:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<graphql::hello::Operations>; _Args = {std::shared_ptr<graphql::hello::Query>&}; _Tp = graphql::hello::Operations; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
    /usr/include/c++/10/bits/shared_ptr.h:408:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<graphql::hello::Operations>; _Args = {std::shared_ptr<graphql::hello::Query>&}; _Tp = graphql::hello::Operations]’
    /usr/include/c++/10/bits/shared_ptr.h:859:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = graphql::hello::Operations; _Alloc = std::allocator<graphql::hello::Operations>; _Args = {std::shared_ptr<graphql::hello::Query>&}]’
    /usr/include/c++/10/bits/shared_ptr.h:875:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = graphql::hello::Operations; _Args = {std::shared_ptr<graphql::hello::Query>&}]’
    ./hello/hello.cpp:33:61:   required from here
    /usr/include/c++/10/ext/new_allocator.h:150:4: error: no matching function for call to ‘graphql::hello::Operations::Operations(std::shared_ptr<graphql::hello::Query>&)’
      150 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
          |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from ./hello/HelloMock.h:6,
                     from ./hello/hello.cpp:2:
    ./hello/HelloSchema.h:52:11: note: candidate: ‘graphql::hello::Operations::Operations(std::shared_ptr<graphql::hello::object::Query>)’
       52 |  explicit Operations(std::shared_ptr<object::Query> query);
          |           ^~~~~~~~~~
    ./hello/HelloSchema.h:52:53: note:   no known conversion for argument 1 from ‘shared_ptr<graphql::hello::Query>’ to ‘shared_ptr<graphql::hello::object::Query>’
       52 |  explicit Operations(std::shared_ptr<object::Query> query);
          |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
    make: *** [makefile:89: hello/hello] Error 1
    
    

    Using Schema

    schema.hello.graphql

    type Query {
        hello: String
    }
    

    query.hello.graphql

    # Copyright (c) Microsoft Corporation. All rights reserved.
    # Licensed under the MIT License.
    
    query {
        hello
    }
    

    Excpected output

    {"data":{"hello":"Hello World!"}}
    

    How to resolve that error message and how to get the final expected output?

  14. wravery commented on Dec 30, 2021

    @wravery
    ContributorAuthor

    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.

    I went ahead and moved this to a new issue: #191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions