Update to cppgraphqlgen 4.0 and latest gqlmapi

This commit is contained in:
Bill Avery 2021-12-30 13:43:04 -08:00
Родитель 2026d208cf
Коммит daaea8d4b8
4 изменённых файлов: 220 добавлений и 80 удалений

68
package-lock.json сгенерированный
Просмотреть файл

@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
"name": "electron-gqlmapi",
"version": "1.0.2",
"cpu": [
"x64"
@ -16,6 +17,15 @@
"dependencies": {
"electron": "~11.5.0"
},
"bin": {
"electron-gqlmapi.node": "bin/electron-gqlmapi.node",
"gqlmapi.dll": "bin/gqlmapi.dll",
"graphqlintrospection.dll": "bin/graphqlintrospection.dll",
"graphqljson.dll": "bin/graphqljson.dll",
"graphqlpeg.dll": "bin/graphqlpeg.dll",
"graphqlresponse.dll": "bin/graphqlresponse.dll",
"graphqlservice.dll": "bin/graphqlservice.dll"
},
"devDependencies": {
"@jest-runner/electron": "^3.0.0",
"cmake-js": "^6.1.0",
@ -2953,9 +2963,9 @@
}
},
"node_modules/ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"engines": {
"node": ">=8"
@ -9054,9 +9064,9 @@
"dev": true
},
"node_modules/json-schema": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
"integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=",
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
"integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==",
"dev": true
},
"node_modules/json-schema-traverse": {
@ -9095,18 +9105,18 @@
}
},
"node_modules/jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
"integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz",
"integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==",
"dev": true,
"engines": [
"node >=0.6.0"
],
"dependencies": {
"assert-plus": "1.0.0",
"extsprintf": "1.3.0",
"json-schema": "0.2.3",
"json-schema": "0.4.0",
"verror": "1.10.0"
},
"engines": {
"node": ">=0.6.0"
}
},
"node_modules/keyv": {
@ -11776,9 +11786,9 @@
"dev": true
},
"node_modules/tmpl": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz",
"integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=",
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
"integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==",
"dev": true
},
"node_modules/to-fast-properties": {
@ -14914,9 +14924,9 @@
}
},
"ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true
},
"ansi-styles": {
@ -19854,9 +19864,9 @@
"dev": true
},
"json-schema": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
"integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=",
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
"integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==",
"dev": true
},
"json-schema-traverse": {
@ -19889,14 +19899,14 @@
}
},
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
"integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz",
"integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==",
"dev": true,
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.3.0",
"json-schema": "0.2.3",
"json-schema": "0.4.0",
"verror": "1.10.0"
}
},
@ -22029,9 +22039,9 @@
"dev": true
},
"tmpl": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz",
"integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=",
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
"integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==",
"dev": true
},
"to-fast-properties": {

124
src/.clang-format Normal file
Просмотреть файл

@ -0,0 +1,124 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 0
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 500
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Always
...

Просмотреть файл

@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 17)
include(FetchContent)
FetchContent_Declare(gqlmapi
GIT_REPOSITORY "https://github.com/microsoft/gqlmapi"
GIT_TAG "a893cc4f3c1cb5eb66f7db36ed5db3d8783b0026"
GIT_TAG "953f8c0a1c4d069c34716dfe97ede4d3ff1ddcaa"
GIT_PROGRESS TRUE)
FetchContent_GetProperties(gqlmapi)
if(NOT gqlmapi_POPULATED)

Просмотреть файл

@ -8,20 +8,13 @@
#include <nan.h>
#include <iostream>
#include <memory>
#include <map>
#include <thread>
#include <memory>
#include <queue>
#include <thread>
using v8::Function;
using v8::FunctionTemplate;
using v8::Promise;
using v8::Local;
using v8::String;
using v8::Int32;
using v8::Value;
using Nan::AsyncQueueWorker;
using Nan::AsyncProgressQueueWorker;
using Nan::AsyncQueueWorker;
using Nan::Callback;
using Nan::DecodeWrite;
using Nan::Encoding;
@ -31,6 +24,13 @@ using Nan::New;
using Nan::Null;
using Nan::Set;
using Nan::To;
using v8::Function;
using v8::FunctionTemplate;
using v8::Int32;
using v8::Local;
using v8::Promise;
using v8::String;
using v8::Value;
using namespace graphql;
@ -70,16 +70,15 @@ struct SubscriptionPayloadQueue : std::enable_shared_from_this<SubscriptionPaylo
lock.unlock();
condition.notify_one();
if (deferUnsubscribe
&& serviceSingleton)
if (deferUnsubscribe && serviceSingleton)
{
serviceSingleton->unsubscribe(std::launch::deferred, *deferUnsubscribe).get();
serviceSingleton->unsubscribe({ *deferUnsubscribe }).get();
}
}
std::mutex mutex;
std::condition_variable condition;
std::queue<std::future<response::Value>> payloads;
std::queue<response::AwaitableValue> payloads;
std::optional<service::SubscriptionKey> key;
bool registered = false;
};
@ -136,9 +135,11 @@ NAN_METHOD(discardQuery)
class RegisteredSubscription : public AsyncProgressQueueWorker<std::string>
{
public:
explicit RegisteredSubscription(std::int32_t queryId, std::string&& operationName, const std::string& variables, std::unique_ptr<Callback>&& next, std::unique_ptr<Callback>&& complete)
explicit RegisteredSubscription(std::int32_t queryId, std::string&& operationName,
const std::string& variables, std::unique_ptr<Callback>&& next,
std::unique_ptr<Callback>&& complete)
: AsyncProgressQueueWorker(complete.release(), "graphql:subscription")
, _next{ std::move(next) }
, _next { std::move(next) }
{
try
{
@ -152,7 +153,8 @@ public:
}
auto& ast = itrQuery->second;
auto parsedVariables = (variables.empty() ? response::Value(response::Type::Map) : response::parseJSON(variables));
auto parsedVariables = (variables.empty() ? response::Value(response::Type::Map)
: response::parseJSON(variables));
if (parsedVariables.type() != response::Type::Map)
{
@ -161,37 +163,38 @@ public:
std::unique_lock<std::mutex> lock(_payloadQueue->mutex);
if (serviceSingleton->findOperationDefinition(ast, operationName).first == service::strSubscription)
if (serviceSingleton->findOperationDefinition(ast, operationName).first
== service::strSubscription)
{
_payloadQueue->registered = true;
_payloadQueue->key = std::make_optional(serviceSingleton->subscribe(std::launch::deferred, service::SubscriptionParams{
nullptr,
peg::ast{ ast },
std::move(operationName),
std::move(parsedVariables)
}, [spQueue = _payloadQueue](std::future<response::Value> payload) noexcept -> void
{
std::unique_lock<std::mutex> lock(spQueue->mutex);
_payloadQueue->key = std::make_optional(
serviceSingleton
->subscribe(
{ [spQueue = _payloadQueue](response::Value payload) noexcept -> void {
std::unique_lock<std::mutex> lock(spQueue->mutex);
if (!spQueue->registered)
{
return;
}
if (!spQueue->registered)
{
return;
}
spQueue->payloads.push(std::move(payload));
std::promise<response::Value> promise;
lock.unlock();
spQueue->condition.notify_one();
}).get());
promise.set_value(std::move(payload));
spQueue->payloads.push(promise.get_future());
lock.unlock();
spQueue->condition.notify_one();
},
peg::ast { ast },
std::move(operationName),
std::move(parsedVariables) })
.get());
}
else
{
_payloadQueue->payloads.push(serviceSingleton->resolve(
std::launch::deferred,
nullptr,
ast,
operationName,
std::move(parsedVariables)));
_payloadQueue->payloads.push(
serviceSingleton->resolve({ ast, operationName, std::move(parsedVariables) }));
lock.unlock();
_payloadQueue->condition.notify_one();
@ -230,10 +233,8 @@ private:
{
std::unique_lock<std::mutex> lock(spQueue->mutex);
spQueue->condition.wait(lock, [spQueue]() noexcept -> bool
{
return !spQueue->registered
|| !spQueue->payloads.empty();
spQueue->condition.wait(lock, [spQueue]() noexcept -> bool {
return !spQueue->registered || !spQueue->payloads.empty();
});
auto payloads = std::move(spQueue->payloads);
@ -245,7 +246,7 @@ private:
while (!payloads.empty())
{
response::Value document{ response::Type::Map };
response::Value document { response::Type::Map };
auto payload = std::move(payloads.front());
payloads.pop();
@ -257,8 +258,8 @@ private:
catch (service::schema_exception& scx)
{
document.reserve(2);
document.emplace_back(std::string{ service::strData }, {});
document.emplace_back(std::string{ service::strErrors }, scx.getErrors());
document.emplace_back(std::string { service::strData }, {});
document.emplace_back(std::string { service::strErrors }, scx.getErrors());
}
catch (const std::exception& ex)
{
@ -266,8 +267,9 @@ private:
oss << "Caught exception delivering subscription payload: " << ex.what();
document.reserve(2);
document.emplace_back(std::string{ service::strData }, {});
document.emplace_back(std::string{ service::strErrors }, response::Value{ oss.str() });
document.emplace_back(std::string { service::strData }, {});
document.emplace_back(std::string { service::strErrors },
response::Value { oss.str() });
}
json.push_back(response::toJSON(std::move(document)));
@ -314,7 +316,11 @@ NAN_METHOD(fetchQuery)
std::string variables(*Nan::Utf8String(To<String>(info[2]).ToLocalChecked()));
auto next = std::make_unique<Callback>(To<Function>(info[3]).ToLocalChecked());
auto complete = std::make_unique<Callback>(To<Function>(info[4]).ToLocalChecked());
auto subscription = std::make_unique<RegisteredSubscription>(queryId, std::move(operationName), variables, std::move(next), std::move(complete));
auto subscription = std::make_unique<RegisteredSubscription>(queryId,
std::move(operationName),
variables,
std::move(next),
std::move(complete));
subscriptionMap[queryId] = subscription->GetPayloadQueue();
AsyncQueueWorker(subscription.release());