Skip to content

Question: How to use cppgraphqlgen as Client #348

@sebu06

Description

@sebu06

Hi,
I'm missing a sample to use cppgraphqlgen only as a client for an existing graphql server (Graphene/Django). After a lot of reading, I came up with this, but I'm a little bit stuck on how to set Variables to my query.

   auto svar = graphql::client::query::getObjectclassById::serializeVariables({1});
   // auto query = graphql::client::query::getObjectclassById::GetRequestObject();
   // const auto& name = graphql::client::query::getObjectclassById::GetOperationName();

   auto res = cpr::Post(
       cpr::Url({Config::gqlServer() + "/graphql/"}),
       cpr::Header({{"Content-Type", "application/graphql"}}),
       cpr::Body(graphql::client::query::getObjectclassById::GetRequestText()));

   auto r = graphql::response::parseJSON(res.text);
   auto serviceResponse = graphql::client::parseServiceResponse(std::move(r));
   const auto parsed = graphql::client::query::getObjectclassById::parseResponse(std::move(serviceResponse.data));

   if (parsed.objectclassById) {
      std::cout << parsed.objectclassById->title.value_or("title not set") << std::endl;
   }

Is my use of the library correct so far? How do I set the variables in the query to the server?

Thanks,
Sebastian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions