adding in qt cli project instead of using raw c++ and/or golang FFI
This commit is contained in:
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
-1
Submodule external/cppgraphqlgen deleted from 0df2b32d94
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
BasedOnStyle: Microsoft
|
||||
TabWidth: 2
|
||||
IndentWidth: 2
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
*.qbs.user*
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
# Directories with generated files
|
||||
.moc/
|
||||
.obj/
|
||||
.pch/
|
||||
.rcc/
|
||||
.uic/
|
||||
/build*/
|
||||
@@ -0,0 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(qt-cli LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
|
||||
|
||||
add_executable(qt-cli
|
||||
main.cpp
|
||||
)
|
||||
target_link_libraries(qt-cli Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS qt-cli
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
build/Qt_6_8_2_for_macOS-Debug/compile_commands.json
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/qnetworkaccessmanager.h>
|
||||
|
||||
struct WaitlistEntry
|
||||
{
|
||||
QString firstName;
|
||||
QString lastName;
|
||||
QString email;
|
||||
};
|
||||
|
||||
QVector<WaitlistEntry> parseGraphQLResponse(const QByteArray &responseData)
|
||||
{
|
||||
QVector<WaitlistEntry> waitlist;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(responseData);
|
||||
if (!doc.isObject())
|
||||
return waitlist;
|
||||
|
||||
QJsonObject obj = doc.object();
|
||||
QJsonArray entries = obj["data"].toObject()["getWaitlist"].toArray();
|
||||
|
||||
for (const QJsonValue &value : entries)
|
||||
{
|
||||
QJsonObject entryObj = value.toObject();
|
||||
WaitlistEntry entry{entryObj["firstName"].toString(), entryObj["lastName"].toString(),
|
||||
entryObj["email"].toString()};
|
||||
waitlist.append(entry);
|
||||
}
|
||||
return waitlist;
|
||||
}
|
||||
|
||||
void sendGraphQLQuery(QNetworkAccessManager &manager)
|
||||
{
|
||||
QUrl url("https://helios.dev.flowy.live/query");
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Authorization", "talksik");
|
||||
|
||||
// Define GraphQL query
|
||||
QJsonObject json;
|
||||
json["query"] = R"(
|
||||
query {
|
||||
getWaitlist {
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
// Convert to JSON and send request
|
||||
QNetworkReply *reply = manager.post(request, QJsonDocument(json).toJson());
|
||||
|
||||
// Handle response asynchronously
|
||||
QObject::connect(reply, &QNetworkReply::finished, [reply]() {
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
auto response = reply->readAll();
|
||||
|
||||
auto parsedEntries = parseGraphQLResponse(response);
|
||||
|
||||
for (const auto &entry : parsedEntries)
|
||||
{
|
||||
qDebug() << "Entry: " << entry.email << Qt::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Error:" << reply->errorString();
|
||||
}
|
||||
reply->deleteLater();
|
||||
|
||||
QCoreApplication::quit();
|
||||
});
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
// Set up code that uses the Qt event loop here.
|
||||
// Call a.quit() or a.exit() to quit the application.
|
||||
// A not very useful example would be including
|
||||
// #include <QTimer>
|
||||
// near the top of the file and calling
|
||||
// QTimer::singleShot(5000, &a, &QCoreApplication::quit);
|
||||
// which quits the application after 5 seconds.
|
||||
|
||||
// If you do not need a running Qt event loop, remove the call
|
||||
// to a.exec() or use the Non-Qt Plain C++ Application template.
|
||||
qDebug() << "Sending GraphQL query...";
|
||||
QNetworkAccessManager manager;
|
||||
sendGraphQLQuery(manager);
|
||||
qDebug() << "Waiting for response...";
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user