@@ -34,133 +34,17 @@ const CppTypeMap SchemaLoader::s_builtinCppTypes = {
3434
3535const std::string_view SchemaLoader::s_scalarCppType = R"cpp( response::Value)cpp" sv;
3636
37- SchemaLoader::SchemaLoader (std::optional< SchemaOptions> && customSchema )
38- : _customSchema (std::move(customSchema ))
39- , _isIntrospection(!_customSchema || _customSchema-> isIntrospection)
40- , _schemaNamespace(_customSchema ? _customSchema-> schemaNamespace : s_introspectionNamespace )
37+ SchemaLoader::SchemaLoader (SchemaOptions&& schemaOptions )
38+ : _schemaOptions (std::move(schemaOptions ))
39+ , _isIntrospection(_schemaOptions. isIntrospection)
40+ , _schemaNamespace(_schemaOptions. schemaNamespace)
4141{
42- if (!_customSchema)
43- {
44- // Introspection Schema:
45- // http://spec.graphql.org/June2018/#sec-Schema-Introspection
46- _ast = peg::parseSchemaString (R"gql(
47- type __Schema {
48- types: [__Type!]!
49- queryType: __Type!
50- mutationType: __Type
51- subscriptionType: __Type
52- directives: [__Directive!]!
53- }
54-
55- type __Type {
56- kind: __TypeKind!
57- name: String
58- description: String
59-
60- # OBJECT and INTERFACE only
61- fields(includeDeprecated: Boolean = false): [__Field!]
62-
63- # OBJECT only
64- interfaces: [__Type!]
65-
66- # INTERFACE and UNION only
67- possibleTypes: [__Type!]
68-
69- # ENUM only
70- enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
71-
72- # INPUT_OBJECT only
73- inputFields: [__InputValue!]
74-
75- # NON_NULL and LIST only
76- ofType: __Type
77- }
78-
79- type __Field {
80- name: String!
81- description: String
82- args: [__InputValue!]!
83- type: __Type!
84- isDeprecated: Boolean!
85- deprecationReason: String
86- }
87-
88- type __InputValue {
89- name: String!
90- description: String
91- type: __Type!
92- defaultValue: String
93- }
94-
95- type __EnumValue {
96- name: String!
97- description: String
98- isDeprecated: Boolean!
99- deprecationReason: String
100- }
101-
102- enum __TypeKind {
103- SCALAR
104- OBJECT
105- INTERFACE
106- UNION
107- ENUM
108- INPUT_OBJECT
109- LIST
110- NON_NULL
111- }
112-
113- type __Directive {
114- name: String!
115- description: String
116- locations: [__DirectiveLocation!]!
117- args: [__InputValue!]!
118- }
119-
120- enum __DirectiveLocation {
121- QUERY
122- MUTATION
123- SUBSCRIPTION
124- FIELD
125- FRAGMENT_DEFINITION
126- FRAGMENT_SPREAD
127- INLINE_FRAGMENT
128- SCHEMA
129- SCALAR
130- OBJECT
131- FIELD_DEFINITION
132- ARGUMENT_DEFINITION
133- INTERFACE
134- UNION
135- ENUM
136- ENUM_VALUE
137- INPUT_OBJECT
138- INPUT_FIELD_DEFINITION
139- }
140-
141- # These directives are always defined and should be included in the Introspection schema.
142- directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
143- directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
144- directive @deprecated(
145- reason: String = "No longer supported"
146- ) on FIELD_DEFINITION | ENUM_VALUE
147- )gql" sv);
42+ _ast = peg::parseSchemaFile (_schemaOptions.schemaFilename );
14843
149- if (!_ast.root )
150- {
151- throw std::logic_error (" Unable to parse the introspection schema, but there was no "
152- " error message from the parser!" );
153- }
154- }
155- else
44+ if (!_ast.root )
15645 {
157- _ast = peg::parseSchemaFile (_customSchema->schemaFilename );
158-
159- if (!_ast.root )
160- {
161- throw std::logic_error (" Unable to parse the service schema, but there was no error "
162- " message from the parser!" );
163- }
46+ throw std::logic_error (" Unable to parse the service schema, but there was no error "
47+ " message from the parser!" );
16448 }
16549
16650 for (const auto & child : _ast.root ->children )
@@ -1215,7 +1099,7 @@ bool SchemaLoader::isIntrospection() const noexcept
12151099
12161100std::string_view SchemaLoader::getFilenamePrefix () const noexcept
12171101{
1218- return _customSchema ? _customSchema-> filenamePrefix : " Introspection " sv ;
1102+ return _schemaOptions. filenamePrefix ;
12191103}
12201104
12211105std::string_view SchemaLoader::getSchemaNamespace () const noexcept
0 commit comments