Skip to content

Commit c7dbfc6

Browse files
committed
Add a ""_graphql string literal UDL
1 parent 97ba63e commit c7dbfc6

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

GraphQLTree.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,5 +569,11 @@ std::unique_ptr<ast_node> parseFile(file_input<>&& in)
569569
}
570570

571571
} /* namespace peg */
572+
573+
std::unique_ptr<peg::ast_node> operator "" _graphql(const char* text, size_t size)
574+
{
575+
return tao::graphqlpeg::parse_tree::parse<peg::document, peg::ast_node, peg::ast_selector>(tao::graphqlpeg::memory_input<>(text, size, "GraphQL"));
576+
}
577+
572578
} /* namespace graphql */
573579
} /* namespace facebook */

GraphQLTree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ std::unique_ptr<ast_node> parseString(const char* text);
2727
std::unique_ptr<ast_node> parseFile(file_input<>&& in);
2828

2929
} /* namespace peg */
30+
31+
std::unique_ptr<peg::ast_node> operator "" _graphql(const char* text, size_t size);
32+
3033
} /* namespace graphql */
3134
} /* namespace facebook */

SchemaGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Generator::Generator()
4444
, _schemaNamespace(s_introspectionNamespace)
4545
{
4646
// Introspection Schema: https://facebook.github.io/graphql/June2018/#sec-Schema-Introspection
47-
auto ast = peg::parseString(R"gql(
47+
auto ast = R"(
4848
type __Schema {
4949
types: [__Type!]!
5050
queryType: __Type!
@@ -137,7 +137,7 @@ Generator::Generator()
137137
ENUM_VALUE
138138
INPUT_OBJECT
139139
INPUT_FIELD_DEFINITION
140-
})gql");
140+
})"_graphql;
141141

142142
if (!ast)
143143
{
@@ -1627,7 +1627,7 @@ template <>
16271627
if (firstField)
16281628
{
16291629
firstField = false;
1630-
sourceFile << R"cpp( static const auto defaultValue = []() -> rapidjson::Document
1630+
sourceFile << R"cpp( const auto defaultValue = []()
16311631
{
16321632
rapidjson::Document values(rapidjson::Type::kObjectType);
16331633
auto& allocator = values.GetAllocator();
@@ -1858,7 +1858,7 @@ rapidjson::Document )cpp" << objectType.type
18581858
if (firstArgument)
18591859
{
18601860
firstArgument = false;
1861-
sourceFile << R"cpp( static const auto defaultArguments = []() -> rapidjson::Document
1861+
sourceFile << R"cpp( const auto defaultArguments = []()
18621862
{
18631863
rapidjson::Document values(rapidjson::Type::kObjectType);
18641864
auto& allocator = values.GetAllocator();

samples/IntrospectionSchema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ rapidjson::Document __Type::resolveDescription(service::ResolverParams&& params)
228228

229229
rapidjson::Document __Type::resolveFields(service::ResolverParams&& params)
230230
{
231-
static const auto defaultArguments = []() -> rapidjson::Document
231+
const auto defaultArguments = []()
232232
{
233233
rapidjson::Document values(rapidjson::Type::kObjectType);
234234
auto& allocator = values.GetAllocator();
@@ -267,7 +267,7 @@ rapidjson::Document __Type::resolvePossibleTypes(service::ResolverParams&& param
267267

268268
rapidjson::Document __Type::resolveEnumValues(service::ResolverParams&& params)
269269
{
270-
static const auto defaultArguments = []() -> rapidjson::Document
270+
const auto defaultArguments = []()
271271
{
272272
rapidjson::Document values(rapidjson::Type::kObjectType);
273273
auto& allocator = values.GetAllocator();

samples/TodaySchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ rapidjson::Document service::ModifiedResult<today::TaskState>::convert(today::Ta
5454
template <>
5555
today::CompleteTaskInput ModifiedArgument<today::CompleteTaskInput>::convert(const rapidjson::Value& value)
5656
{
57-
static const auto defaultValue = []() -> rapidjson::Document
57+
const auto defaultValue = []()
5858
{
5959
rapidjson::Document values(rapidjson::Type::kObjectType);
6060
auto& allocator = values.GetAllocator();

tests.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ size_t TodayServiceCase::_getUnreadCountsCount = 0;
9191

9292
TEST_F(TodayServiceCase, QueryEverything)
9393
{
94-
auto ast = peg::parseString(R"gql(
94+
auto ast = R"(
9595
query Everything {
9696
appointments {
9797
edges {
@@ -121,7 +121,7 @@ TEST_F(TodayServiceCase, QueryEverything)
121121
}
122122
}
123123
}
124-
})gql");
124+
})"_graphql;
125125
const rapidjson::Document variables(rapidjson::Type::kObjectType);
126126
const auto result = _service->resolve(*ast, "Everything", variables.GetObject());
127127
EXPECT_EQ(size_t(1), _getAppointmentsCount) << "today service lazy loads the appointments and caches the result";
@@ -184,7 +184,7 @@ TEST_F(TodayServiceCase, QueryEverything)
184184

185185
TEST_F(TodayServiceCase, QueryAppointments)
186186
{
187-
auto ast = peg::parseString(R"gql({
187+
auto ast = R"({
188188
appointments {
189189
edges {
190190
node {
@@ -195,7 +195,7 @@ TEST_F(TodayServiceCase, QueryAppointments)
195195
}
196196
}
197197
}
198-
})gql");
198+
})"_graphql;
199199
const rapidjson::Document variables(rapidjson::Type::kObjectType);
200200
const auto result = _service->resolve(*ast, "", variables.GetObject());
201201
EXPECT_EQ(size_t(1), _getAppointmentsCount) << "today service lazy loads the appointments and caches the result";
@@ -240,7 +240,7 @@ TEST_F(TodayServiceCase, QueryAppointments)
240240

241241
TEST_F(TodayServiceCase, QueryTasks)
242242
{
243-
auto ast = peg::parseString(R"gql({
243+
auto ast = R"gql({
244244
tasks {
245245
edges {
246246
node {
@@ -250,7 +250,7 @@ TEST_F(TodayServiceCase, QueryTasks)
250250
}
251251
}
252252
}
253-
})gql");
253+
})gql"_graphql;
254254
const rapidjson::Document variables(rapidjson::Type::kObjectType);
255255
const auto result = _service->resolve(*ast, "", variables.GetObject());
256256
EXPECT_GE(size_t(1), _getAppointmentsCount) << "today service lazy loads the appointments and caches the result";
@@ -294,7 +294,7 @@ TEST_F(TodayServiceCase, QueryTasks)
294294

295295
TEST_F(TodayServiceCase, QueryUnreadCounts)
296296
{
297-
auto ast = peg::parseString(R"gql({
297+
auto ast = R"({
298298
unreadCounts {
299299
edges {
300300
node {
@@ -304,7 +304,7 @@ TEST_F(TodayServiceCase, QueryUnreadCounts)
304304
}
305305
}
306306
}
307-
})gql");
307+
})"_graphql;
308308
const rapidjson::Document variables(rapidjson::Type::kObjectType);
309309
const auto result = _service->resolve(*ast, "", variables.GetObject());
310310
EXPECT_GE(size_t(1), _getAppointmentsCount) << "today service lazy loads the appointments and caches the result";
@@ -348,7 +348,7 @@ TEST_F(TodayServiceCase, QueryUnreadCounts)
348348

349349
TEST_F(TodayServiceCase, MutateCompleteTask)
350350
{
351-
auto ast = peg::parseString(R"gql(mutation {
351+
auto ast = R"(mutation {
352352
completedTask: completeTask(input: {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) {
353353
completedTask: task {
354354
completedTaskId: id
@@ -357,7 +357,7 @@ TEST_F(TodayServiceCase, MutateCompleteTask)
357357
}
358358
clientMutationId
359359
}
360-
})gql");
360+
})"_graphql;
361361
const rapidjson::Document variables(rapidjson::Type::kObjectType);
362362
const auto result = _service->resolve(*ast, "", variables.GetObject());
363363

@@ -401,7 +401,7 @@ TEST_F(TodayServiceCase, MutateCompleteTask)
401401

402402
TEST_F(TodayServiceCase, Introspection)
403403
{
404-
auto ast = peg::parseString(R"gql({
404+
auto ast = R"({
405405
__schema {
406406
types {
407407
kind
@@ -432,7 +432,7 @@ TEST_F(TodayServiceCase, Introspection)
432432
name
433433
}
434434
}
435-
})gql");
435+
})"_graphql;
436436
const rapidjson::Document variables(rapidjson::Type::kObjectType);
437437
const auto result = _service->resolve(*ast, "", variables.GetObject());
438438

0 commit comments

Comments
 (0)