Skip to content

Commit bf1221c

Browse files
committed
Fixed the rest of the tests
1 parent 3dd30f0 commit bf1221c

File tree

10 files changed

+43
-35
lines changed

10 files changed

+43
-35
lines changed

include/Validation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ using ValidateFieldArguments = std::map<std::string_view, ValidateArgumentValueP
122122

123123
struct ValidateField
124124
{
125-
ValidateField(std::string_view returnType, std::optional<std::string_view> objectType,
125+
ValidateField(std::string&& returnType, std::optional<std::string_view> objectType,
126126
std::string_view fieldName, ValidateFieldArguments&& arguments);
127127

128128
bool operator==(const ValidateField& other) const;
129129

130-
std::string_view returnType;
130+
std::string returnType;
131131
std::optional<std::string_view> objectType;
132132
std::string_view fieldName;
133133
ValidateFieldArguments arguments;
@@ -140,7 +140,7 @@ using ValidateTypeKinds = std::map<std::string_view, introspection::TypeKind>;
140140
class ValidateVariableTypeVisitor
141141
{
142142
public:
143-
ValidateVariableTypeVisitor(const schema::Schema& schema, const ValidateTypeKinds& typeKinds);
143+
ValidateVariableTypeVisitor(const std::shared_ptr<schema::Schema>& schema, const ValidateTypeKinds& typeKinds);
144144

145145
void visit(const peg::ast_node& typeName);
146146

@@ -152,7 +152,7 @@ class ValidateVariableTypeVisitor
152152
void visitListType(const peg::ast_node& listType);
153153
void visitNonNullType(const peg::ast_node& nonNullType);
154154

155-
const schema::Schema& _schema;
155+
const std::shared_ptr<schema::Schema>& _schema;
156156
const ValidateTypeKinds& _typeKinds;
157157

158158
bool _isInputType = false;

include/graphqlservice/GraphQLSchema.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EnumValue;
3535
class Schema : public std::enable_shared_from_this<Schema>
3636
{
3737
public:
38-
GRAPHQLSERVICE_EXPORT explicit Schema();
38+
GRAPHQLSERVICE_EXPORT explicit Schema(bool noIntrospection = false);
3939

4040
GRAPHQLSERVICE_EXPORT void AddQueryType(std::shared_ptr<ObjectType> query);
4141
GRAPHQLSERVICE_EXPORT void AddMutationType(std::shared_ptr<ObjectType> mutation);
@@ -47,6 +47,7 @@ class Schema : public std::enable_shared_from_this<Schema>
4747
GRAPHQLSERVICE_EXPORT void AddDirective(std::shared_ptr<Directive> directive);
4848

4949
// Accessors
50+
bool supportsIntrospection() const noexcept;
5051
const std::vector<std::pair<std::string_view, std::shared_ptr<BaseType>>>& types()
5152
const noexcept;
5253
const std::shared_ptr<ObjectType>& queryType() const noexcept;
@@ -55,6 +56,8 @@ class Schema : public std::enable_shared_from_this<Schema>
5556
const std::vector<std::shared_ptr<Directive>>& directives() const noexcept;
5657

5758
private:
59+
const bool _noIntrospection = false;
60+
5861
std::shared_ptr<ObjectType> _query;
5962
std::shared_ptr<ObjectType> _mutation;
6063
std::shared_ptr<ObjectType> _subscription;

samples/separate/TodaySchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ std::shared_ptr<schema::Schema> GetSchema()
233233

234234
if (!schema)
235235
{
236-
schema = std::make_shared<schema::Schema>();
236+
schema = std::make_shared<schema::Schema>(false);
237237
introspection::AddTypesToSchema(schema);
238238
AddTypesToSchema(schema);
239239
s_wpSchema = schema;

samples/separate_nointrospection/TodaySchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ std::shared_ptr<schema::Schema> GetSchema()
233233

234234
if (!schema)
235235
{
236-
schema = std::make_shared<schema::Schema>();
236+
schema = std::make_shared<schema::Schema>(true);
237237
introspection::AddTypesToSchema(schema);
238238
AddTypesToSchema(schema);
239239
s_wpSchema = schema;

samples/unified/TodaySchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ std::shared_ptr<schema::Schema> GetSchema()
12661266

12671267
if (!schema)
12681268
{
1269-
schema = std::make_shared<schema::Schema>();
1269+
schema = std::make_shared<schema::Schema>(false);
12701270
introspection::AddTypesToSchema(schema);
12711271
AddTypesToSchema(schema);
12721272
s_wpSchema = schema;

samples/unified_nointrospection/TodaySchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ std::shared_ptr<schema::Schema> GetSchema()
12491249

12501250
if (!schema)
12511251
{
1252-
schema = std::make_shared<schema::Schema>();
1252+
schema = std::make_shared<schema::Schema>(true);
12531253
introspection::AddTypesToSchema(schema);
12541254
AddTypesToSchema(schema);
12551255
s_wpSchema = schema;

samples/validation/ValidationSchema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ std::shared_ptr<schema::Schema> GetSchema()
10241024

10251025
if (!schema)
10261026
{
1027-
schema = std::make_shared<schema::Schema>();
1027+
schema = std::make_shared<schema::Schema>(false);
10281028
introspection::AddTypesToSchema(schema);
10291029
AddTypesToSchema(schema);
10301030
s_wpSchema = schema;

src/GraphQLSchema.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ using namespace std::literals;
88

99
namespace graphql::schema {
1010

11-
Schema::Schema()
11+
Schema::Schema(bool noIntrospection)
12+
: _noIntrospection(noIntrospection)
1213
{
1314
}
1415

@@ -33,6 +34,11 @@ void Schema::AddType(std::string_view name, std::shared_ptr<BaseType> type)
3334
_types.push_back({ name, std::move(type) });
3435
}
3536

37+
bool Schema::supportsIntrospection() const noexcept
38+
{
39+
return !_noIntrospection;
40+
}
41+
3642
const std::shared_ptr<BaseType>& Schema::LookupType(std::string_view name) const
3743
{
3844
auto itr = _typeMap.find(name);

src/SchemaGenerator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,8 @@ Operations::Operations()cpp";
25162516
{
25172517
bool firstValue = true;
25182518

2519-
sourceFile << R"cpp( type)cpp" << unionType.cppType << R"cpp(->AddPossibleTypes({
2519+
sourceFile << R"cpp( type)cpp" << unionType.cppType
2520+
<< R"cpp(->AddPossibleTypes({
25202521
)cpp";
25212522

25222523
for (const auto& unionOption : unionType.options)
@@ -2737,7 +2738,8 @@ Operations::Operations()cpp";
27372738
27382739
if (!schema)
27392740
{
2740-
schema = std::make_shared<schema::Schema>();
2741+
schema = std::make_shared<schema::Schema>()cpp"
2742+
<< (_options.noIntrospection ? "true" : "false") << R"cpp();
27412743
)cpp" << s_introspectionNamespace
27422744
<< R"cpp(::AddTypesToSchema(schema);
27432745
AddTypesToSchema(schema);

src/Validation.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ void ValidateArgumentValueVisitor::visitObjectValue(const peg::ast_node& objectV
243243
_argumentValue.position = { position.line, position.column };
244244
}
245245

246-
ValidateField::ValidateField(std::string_view returnType,
247-
std::optional<std::string_view> objectType, std::string_view fieldName,
248-
ValidateFieldArguments&& arguments)
249-
: returnType(returnType)
246+
ValidateField::ValidateField(std::string&& returnType, std::optional<std::string_view> objectType,
247+
std::string_view fieldName, ValidateFieldArguments&& arguments)
248+
: returnType(std::move(returnType))
250249
, objectType(objectType)
251250
, fieldName(fieldName)
252251
, arguments(std::move(arguments))
@@ -261,7 +260,7 @@ bool ValidateField::operator==(const ValidateField& other) const
261260
}
262261

263262
ValidateVariableTypeVisitor::ValidateVariableTypeVisitor(
264-
const schema::Schema& schema, const ValidateTypeKinds& typeKinds)
263+
const std::shared_ptr<schema::Schema>& schema, const ValidateTypeKinds& typeKinds)
265264
: _schema(schema)
266265
, _typeKinds(typeKinds)
267266
{
@@ -299,7 +298,7 @@ void ValidateVariableTypeVisitor::visitNamedType(const peg::ast_node& namedType)
299298
case introspection::TypeKind::ENUM:
300299
case introspection::TypeKind::INPUT_OBJECT:
301300
_isInputType = true;
302-
_variableType = _schema.LookupType(name);
301+
_variableType = _schema->LookupType(name);
303302
break;
304303

305304
default:
@@ -313,8 +312,7 @@ void ValidateVariableTypeVisitor::visitListType(const peg::ast_node& listType)
313312

314313
visitor.visit(*listType.children.front());
315314
_isInputType = visitor.isInputType();
316-
_variableType =
317-
std::make_shared<schema::WrapperType>(introspection::TypeKind::LIST, visitor.getType());
315+
_variableType = _schema->WrapType(introspection::TypeKind::LIST, visitor.getType());
318316
}
319317

320318
void ValidateVariableTypeVisitor::visitNonNullType(const peg::ast_node& nonNullType)
@@ -323,8 +321,7 @@ void ValidateVariableTypeVisitor::visitNonNullType(const peg::ast_node& nonNullT
323321

324322
visitor.visit(*nonNullType.children.front());
325323
_isInputType = visitor.isInputType();
326-
_variableType =
327-
std::make_shared<schema::WrapperType>(introspection::TypeKind::NON_NULL, visitor.getType());
324+
_variableType = _schema->WrapType(introspection::TypeKind::NON_NULL, visitor.getType());
328325
}
329326

330327
bool ValidateVariableTypeVisitor::isInputType() const
@@ -653,7 +650,7 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op
653650
else if (child->is_type<peg::named_type>() || child->is_type<peg::list_type>()
654651
|| child->is_type<peg::nonnull_type>())
655652
{
656-
ValidateVariableTypeVisitor visitor(*_schema, _typeKinds);
653+
ValidateVariableTypeVisitor visitor(_schema, _typeKinds);
657654

658655
visitor.visit(*child);
659656

@@ -1410,33 +1407,30 @@ ValidateExecutableVisitor::TypeFields::const_iterator ValidateExecutableVisitor:
14101407
validateFields[fieldName] = std::move(subField);
14111408
}
14121409

1413-
if (_scopedType == _operationTypes[strQuery])
1410+
if (_schema->supportsIntrospection() && _scopedType == _operationTypes[strQuery])
14141411
{
14151412
ValidateTypeField schemaField;
14161413

1417-
schemaField.returnType =
1418-
std::make_shared<schema::WrapperType>(introspection::TypeKind::NON_NULL,
1419-
_schema->LookupType(R"gql(__Schema)gql"sv));
1414+
schemaField.returnType = _schema->WrapType(introspection::TypeKind::NON_NULL,
1415+
_schema->LookupType(R"gql(__Schema)gql"sv));
14201416
validateFields[R"gql(__schema)gql"sv] = std::move(schemaField);
14211417

14221418
ValidateTypeField typeField;
14231419
ValidateArgument nameArgument;
14241420

14251421
typeField.returnType = _schema->LookupType(R"gql(__Type)gql"sv);
14261422

1427-
nameArgument.type =
1428-
std::make_shared<schema::WrapperType>(introspection::TypeKind::NON_NULL,
1429-
_schema->LookupType(R"gql(String)gql"sv));
1423+
nameArgument.type = _schema->WrapType(introspection::TypeKind::NON_NULL,
1424+
_schema->LookupType(R"gql(String)gql"sv));
14301425
typeField.arguments[R"gql(name)gql"sv] = std::move(nameArgument);
14311426

14321427
validateFields[R"gql(__type)gql"sv] = std::move(typeField);
14331428
}
14341429

14351430
ValidateTypeField typenameField;
14361431

1437-
typenameField.returnType =
1438-
std::make_shared<schema::WrapperType>(introspection::TypeKind::NON_NULL,
1439-
_schema->LookupType(R"gql(String)gql"sv));
1432+
typenameField.returnType = _schema->WrapType(introspection::TypeKind::NON_NULL,
1433+
_schema->LookupType(R"gql(String)gql"sv));
14401434
validateFields[R"gql(__typename)gql"sv] = std::move(typenameField);
14411435

14421436
itrType = _typeFields.insert({ _scopedType, std::move(validateFields) }).first;
@@ -1701,7 +1695,10 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field)
17011695

17021696
std::optional<std::string_view> objectType =
17031697
(*kind == introspection::TypeKind::OBJECT ? std::make_optional(_scopedType) : std::nullopt);
1704-
ValidateField validateField(wrappedType, objectType, name, std::move(validateArguments));
1698+
ValidateField validateField(std::move(wrappedType),
1699+
objectType,
1700+
name,
1701+
std::move(validateArguments));
17051702
auto itrValidateField = _selectionFields.find(alias);
17061703

17071704
if (itrValidateField != _selectionFields.end())

0 commit comments

Comments
 (0)