Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #304 #308

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/graphqlservice/internal/Grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct comment : seq<one<'#'>, until<eolf>>
};

// https://spec.graphql.org/October2021/#sec-Source-Text.Ignored-Tokens
struct ignored : sor<space, one<','>, comment>
struct ignored : sor<utf8::bom, space, one<','>, comment>
{
};

Expand Down Expand Up @@ -1177,7 +1177,7 @@ struct mixed_definition : sor<executable_definition, type_system_definition, typ
};

struct mixed_document_content
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
: seq<bof, star<ignored>, // leading whitespace/ignored
list<mixed_definition, star<ignored>>, // mixed definitions
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
{
Expand All @@ -1189,7 +1189,7 @@ struct mixed_document : must<mixed_document_content>
};

struct executable_document_content
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
: seq<bof, star<ignored>, // leading whitespace/ignored
list<executable_definition, star<ignored>>, // executable definitions
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
{
Expand All @@ -1206,7 +1206,7 @@ struct schema_type_definition : sor<type_system_definition, type_system_extensio
};

struct schema_document_content
: seq<bof, opt<utf8::bom>, star<ignored>, // leading whitespace/ignored
: seq<bof, star<ignored>, // leading whitespace/ignored
list<schema_type_definition, star<ignored>>, // schema type definitions
star<ignored>, tao::graphqlpeg::eof> // trailing whitespace/ignored
{
Expand Down
4 changes: 4 additions & 0 deletions samples/client/multiple/MultipleQueriesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ const peg::ast& GetRequestObject() noexcept
}

CompleteTaskInput::CompleteTaskInput() noexcept
: id {}
, testTaskState {}
, isComplete {}
, clientMutationId {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down
8 changes: 4 additions & 4 deletions samples/client/multiple/MultipleQueriesClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
CompleteTaskInput& operator=(const CompleteTaskInput& other);
CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept;

response::IdType id {};
std::optional<TaskState> testTaskState {};
std::optional<bool> isComplete {};
std::optional<std::string> clientMutationId {};
response::IdType id;
std::optional<TaskState> testTaskState;
std::optional<bool> isComplete;
std::optional<std::string> clientMutationId;
};

} // namespace multiple
Expand Down
4 changes: 4 additions & 0 deletions samples/client/mutate/MutateClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const peg::ast& GetRequestObject() noexcept
}

CompleteTaskInput::CompleteTaskInput() noexcept
: id {}
, testTaskState {}
, isComplete {}
, clientMutationId {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down
8 changes: 4 additions & 4 deletions samples/client/mutate/MutateClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
CompleteTaskInput& operator=(const CompleteTaskInput& other);
CompleteTaskInput& operator=(CompleteTaskInput&& other) noexcept;

response::IdType id {};
std::optional<TaskState> testTaskState {};
std::optional<bool> isComplete {};
std::optional<std::string> clientMutationId {};
response::IdType id;
std::optional<TaskState> testTaskState;
std::optional<bool> isComplete;
std::optional<std::string> clientMutationId;
};

} // namespace mutate
Expand Down
9 changes: 9 additions & 0 deletions samples/client/nestedinput/NestedInputClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const peg::ast& GetRequestObject() noexcept
}

InputA::InputA() noexcept
: a {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down Expand Up @@ -87,6 +88,7 @@ InputA& InputA::operator=(InputA&& other) noexcept
}

InputB::InputB() noexcept
: b {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down Expand Up @@ -125,6 +127,11 @@ InputB& InputB::operator=(InputB&& other) noexcept
}

InputABCD::InputABCD() noexcept
: d {}
, a {}
, b {}
, bc {}
, value {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down Expand Up @@ -183,6 +190,8 @@ InputABCD& InputABCD::operator=(InputABCD&& other) noexcept
}

InputBC::InputBC() noexcept
: c {}
, b {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand Down
18 changes: 9 additions & 9 deletions samples/client/nestedinput/NestedInputClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct [[nodiscard("unnecessary construction")]] InputA
InputA& operator=(const InputA& other);
InputA& operator=(InputA&& other) noexcept;

bool a {};
bool a;
};

struct [[nodiscard("unnecessary construction")]] InputB
Expand All @@ -71,7 +71,7 @@ struct [[nodiscard("unnecessary construction")]] InputB
InputB& operator=(const InputB& other);
InputB& operator=(InputB&& other) noexcept;

double b {};
double b;
};

struct InputBC;
Expand All @@ -92,11 +92,11 @@ struct [[nodiscard("unnecessary construction")]] InputABCD
InputABCD& operator=(const InputABCD& other);
InputABCD& operator=(InputABCD&& other) noexcept;

std::string d {};
InputA a {};
InputB b {};
std::vector<InputBC> bc {};
int value {};
std::string d;
InputA a;
InputB b;
std::vector<InputBC> bc;
int value;
};

struct [[nodiscard("unnecessary construction")]] InputBC
Expand All @@ -112,8 +112,8 @@ struct [[nodiscard("unnecessary construction")]] InputBC
InputBC& operator=(const InputBC& other);
InputBC& operator=(InputBC&& other) noexcept;

response::IdType c {};
InputB b {};
response::IdType c;
InputB b;
};

} // namespace nestedinput
Expand Down
22 changes: 17 additions & 5 deletions src/ClientGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
headerFile << R"cpp( )cpp"
<< _requestLoader.getInputCppType(inputField->type().lock())
<< R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name())
<< R"cpp( {};
<< R"cpp(;
)cpp";
}

Expand Down Expand Up @@ -648,15 +648,28 @@ using namespace std::literals;

pendingSeparator.reset();

sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept
sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp";

bool firstField = true;

for (const auto& inputField : inputType.type->inputFields())
{
sourceFile << R"cpp(
)cpp" << (firstField ? R"cpp(:)cpp" : R"cpp(,)cpp")
<< R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name())
<< R"cpp( {})cpp";
firstField = false;
}

sourceFile << R"cpp(
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}

)cpp" << cppType << R"cpp(::)cpp"
<< cppType << R"cpp(()cpp";

bool firstField = true;
firstField = true;

for (const auto& inputField : inputType.type->inputFields())
{
Expand Down Expand Up @@ -854,8 +867,7 @@ response::Value Variable<)cpp"

sourceFile << R"cpp(template <>
response::Value Variable<)cpp"
<< cppType << R"cpp(>::serialize()cpp" << cppType
<< R"cpp(&& inputValue)
<< cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& inputValue)
{
response::Value result { response::Type::Map };

Expand Down
17 changes: 16 additions & 1 deletion test/PegtlExecutableTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,25 @@ TEST(PegtlExecutableCase, ParserDepthLimitExceeded)

TEST(PegtlExecutableCase, ParseFloatWithFractionalAndExponentialParts)
{
memory_input<> input(R"gql({ field(value: 1.1e1) })gql",
memory_input<> input(R"gql(
query {
combinedField(value: 1.1e1)
onlyFractional(value: 1.1)
onlyExponent(value: 1e1)
})gql",
"ParseFloatWithFractionalAndExponentialParts");

const bool result = parse<executable_document>(input);

ASSERT_TRUE(result) << "we should be able to parse the doc";
}

TEST(PegtlExecutableCase, ParseIgnoreUnicodeBOM)
{
memory_input<> input("query { \xEF\xBB\xBF __typename }",
"ParseIgnoreUnicodeBOM");

const bool result = parse<executable_document>(input);

ASSERT_TRUE(result) << "we should be able to parse the doc";
}