Skip to content

Commit 0e5ded2

Browse files
committed
fix: #321
1 parent 4d54be8 commit 0e5ded2

31 files changed

+1623
-1159
lines changed

cmake/cppgraphqlgen-update-schema-files.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ foreach(OLD_FILE ${OLD_FILES})
5252
file(REMOVE "${SCHEMA_SOURCE_DIR}/${OLD_FILE}")
5353
elseif(NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.h" AND
5454
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.ixx" AND
55-
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp")
55+
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp" AND
56+
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.h" AND
57+
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.ixx")
5658
message(WARNING "Unexpected file in ${SCHEMA_TARGET} GraphQL schema sources: ${OLD_FILE}")
5759
endif()
5860
endif()

include/SchemaGenerator.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ class [[nodiscard("unnecessary construction")]] Generator
3838
private:
3939
[[nodiscard("unnecessary memory copy")]] std::string getHeaderDir() const noexcept;
4040
[[nodiscard("unnecessary memory copy")]] std::string getSourceDir() const noexcept;
41-
[[nodiscard("unnecessary memory copy")]] std::string getHeaderPath() const noexcept;
42-
[[nodiscard("unnecessary memory copy")]] std::string getModulePath() const noexcept;
41+
[[nodiscard("unnecessary memory copy")]] std::string getSchemaHeaderPath() const noexcept;
42+
[[nodiscard("unnecessary memory copy")]] std::string getSchemaModulePath() const noexcept;
43+
[[nodiscard("unnecessary memory copy")]] std::string getSharedTypesHeaderPath() const noexcept;
44+
[[nodiscard("unnecessary memory copy")]] std::string getSharedTypesModulePath() const noexcept;
4345
[[nodiscard("unnecessary memory copy")]] std::string getSourcePath() const noexcept;
4446

45-
[[nodiscard("unnecessary call")]] bool outputHeader() const noexcept;
46-
[[nodiscard("unnecessary call")]] bool outputModule() const noexcept;
47+
[[nodiscard("unnecessary call")]] bool outputSchemaHeader() const noexcept;
48+
[[nodiscard("unnecessary call")]] bool outputSchemaModule() const noexcept;
49+
[[nodiscard("unnecessary call")]] bool outputSharedTypesHeader() const noexcept;
50+
[[nodiscard("unnecessary call")]] bool outputSharedTypesModule() const noexcept;
4751
void outputInterfaceDeclaration(std::ostream& headerFile, std::string_view cppType) const;
4852
void outputObjectModule(
4953
std::ostream& moduleFile, std::string_view objectNamespace, std::string_view cppType) const;
@@ -94,8 +98,10 @@ class [[nodiscard("unnecessary construction")]] Generator
9498
const std::string _headerDir;
9599
const std::string _moduleDir;
96100
const std::string _sourceDir;
97-
const std::string _headerPath;
98-
const std::string _modulePath;
101+
const std::string _schemaHeaderPath;
102+
const std::string _schemaModulePath;
103+
const std::string _sharedTypesHeaderPath;
104+
const std::string _sharedTypesModulePath;
99105
const std::string _sourcePath;
100106
};
101107

include/graphqlservice/introspection/IntrospectionSchema.h

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "graphqlservice/internal/Version.h"
1515
#include "graphqlservice/internal/Schema.h"
1616

17+
#include "IntrospectionSharedTypes.h"
18+
1719
#include <array>
1820
#include <memory>
1921
#include <string>
@@ -25,128 +27,6 @@ static_assert(graphql::internal::MinorVersion == 0, "regenerate with schemagen:
2527

2628
namespace graphql {
2729
namespace introspection {
28-
29-
enum class TypeKind
30-
{
31-
SCALAR,
32-
OBJECT,
33-
INTERFACE,
34-
UNION,
35-
ENUM,
36-
INPUT_OBJECT,
37-
LIST,
38-
NON_NULL
39-
};
40-
41-
[[nodiscard("unnecessary call")]] constexpr auto getTypeKindNames() noexcept
42-
{
43-
using namespace std::literals;
44-
45-
return std::array<std::string_view, 8> {
46-
R"gql(SCALAR)gql"sv,
47-
R"gql(OBJECT)gql"sv,
48-
R"gql(INTERFACE)gql"sv,
49-
R"gql(UNION)gql"sv,
50-
R"gql(ENUM)gql"sv,
51-
R"gql(INPUT_OBJECT)gql"sv,
52-
R"gql(LIST)gql"sv,
53-
R"gql(NON_NULL)gql"sv
54-
};
55-
}
56-
57-
[[nodiscard("unnecessary call")]] constexpr auto getTypeKindValues() noexcept
58-
{
59-
using namespace std::literals;
60-
61-
return std::array<std::pair<std::string_view, TypeKind>, 8> {
62-
std::make_pair(R"gql(ENUM)gql"sv, TypeKind::ENUM),
63-
std::make_pair(R"gql(LIST)gql"sv, TypeKind::LIST),
64-
std::make_pair(R"gql(UNION)gql"sv, TypeKind::UNION),
65-
std::make_pair(R"gql(OBJECT)gql"sv, TypeKind::OBJECT),
66-
std::make_pair(R"gql(SCALAR)gql"sv, TypeKind::SCALAR),
67-
std::make_pair(R"gql(NON_NULL)gql"sv, TypeKind::NON_NULL),
68-
std::make_pair(R"gql(INTERFACE)gql"sv, TypeKind::INTERFACE),
69-
std::make_pair(R"gql(INPUT_OBJECT)gql"sv, TypeKind::INPUT_OBJECT)
70-
};
71-
}
72-
73-
enum class DirectiveLocation
74-
{
75-
QUERY,
76-
MUTATION,
77-
SUBSCRIPTION,
78-
FIELD,
79-
FRAGMENT_DEFINITION,
80-
FRAGMENT_SPREAD,
81-
INLINE_FRAGMENT,
82-
VARIABLE_DEFINITION,
83-
SCHEMA,
84-
SCALAR,
85-
OBJECT,
86-
FIELD_DEFINITION,
87-
ARGUMENT_DEFINITION,
88-
INTERFACE,
89-
UNION,
90-
ENUM,
91-
ENUM_VALUE,
92-
INPUT_OBJECT,
93-
INPUT_FIELD_DEFINITION
94-
};
95-
96-
[[nodiscard("unnecessary call")]] constexpr auto getDirectiveLocationNames() noexcept
97-
{
98-
using namespace std::literals;
99-
100-
return std::array<std::string_view, 19> {
101-
R"gql(QUERY)gql"sv,
102-
R"gql(MUTATION)gql"sv,
103-
R"gql(SUBSCRIPTION)gql"sv,
104-
R"gql(FIELD)gql"sv,
105-
R"gql(FRAGMENT_DEFINITION)gql"sv,
106-
R"gql(FRAGMENT_SPREAD)gql"sv,
107-
R"gql(INLINE_FRAGMENT)gql"sv,
108-
R"gql(VARIABLE_DEFINITION)gql"sv,
109-
R"gql(SCHEMA)gql"sv,
110-
R"gql(SCALAR)gql"sv,
111-
R"gql(OBJECT)gql"sv,
112-
R"gql(FIELD_DEFINITION)gql"sv,
113-
R"gql(ARGUMENT_DEFINITION)gql"sv,
114-
R"gql(INTERFACE)gql"sv,
115-
R"gql(UNION)gql"sv,
116-
R"gql(ENUM)gql"sv,
117-
R"gql(ENUM_VALUE)gql"sv,
118-
R"gql(INPUT_OBJECT)gql"sv,
119-
R"gql(INPUT_FIELD_DEFINITION)gql"sv
120-
};
121-
}
122-
123-
[[nodiscard("unnecessary call")]] constexpr auto getDirectiveLocationValues() noexcept
124-
{
125-
using namespace std::literals;
126-
127-
return std::array<std::pair<std::string_view, DirectiveLocation>, 19> {
128-
std::make_pair(R"gql(ENUM)gql"sv, DirectiveLocation::ENUM),
129-
std::make_pair(R"gql(FIELD)gql"sv, DirectiveLocation::FIELD),
130-
std::make_pair(R"gql(QUERY)gql"sv, DirectiveLocation::QUERY),
131-
std::make_pair(R"gql(UNION)gql"sv, DirectiveLocation::UNION),
132-
std::make_pair(R"gql(OBJECT)gql"sv, DirectiveLocation::OBJECT),
133-
std::make_pair(R"gql(SCALAR)gql"sv, DirectiveLocation::SCALAR),
134-
std::make_pair(R"gql(SCHEMA)gql"sv, DirectiveLocation::SCHEMA),
135-
std::make_pair(R"gql(MUTATION)gql"sv, DirectiveLocation::MUTATION),
136-
std::make_pair(R"gql(INTERFACE)gql"sv, DirectiveLocation::INTERFACE),
137-
std::make_pair(R"gql(ENUM_VALUE)gql"sv, DirectiveLocation::ENUM_VALUE),
138-
std::make_pair(R"gql(INPUT_OBJECT)gql"sv, DirectiveLocation::INPUT_OBJECT),
139-
std::make_pair(R"gql(SUBSCRIPTION)gql"sv, DirectiveLocation::SUBSCRIPTION),
140-
std::make_pair(R"gql(FRAGMENT_SPREAD)gql"sv, DirectiveLocation::FRAGMENT_SPREAD),
141-
std::make_pair(R"gql(INLINE_FRAGMENT)gql"sv, DirectiveLocation::INLINE_FRAGMENT),
142-
std::make_pair(R"gql(FIELD_DEFINITION)gql"sv, DirectiveLocation::FIELD_DEFINITION),
143-
std::make_pair(R"gql(ARGUMENT_DEFINITION)gql"sv, DirectiveLocation::ARGUMENT_DEFINITION),
144-
std::make_pair(R"gql(FRAGMENT_DEFINITION)gql"sv, DirectiveLocation::FRAGMENT_DEFINITION),
145-
std::make_pair(R"gql(VARIABLE_DEFINITION)gql"sv, DirectiveLocation::VARIABLE_DEFINITION),
146-
std::make_pair(R"gql(INPUT_FIELD_DEFINITION)gql"sv, DirectiveLocation::INPUT_FIELD_DEFINITION)
147-
};
148-
}
149-
15030
class Schema;
15131
class Type;
15232
class Field;

include/graphqlservice/introspection/IntrospectionSchema.ixx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module;
99

1010
export module GraphQL.Introspection.IntrospectionSchema;
1111

12+
export import GraphQL.Introspection.IntrospectionSharedTypes;
13+
1214
export import GraphQL.Introspection.SchemaObject;
1315
export import GraphQL.Introspection.TypeObject;
1416
export import GraphQL.Introspection.FieldObject;
@@ -18,14 +20,6 @@ export import GraphQL.Introspection.DirectiveObject;
1820

1921
export namespace graphql::introspection {
2022

21-
using introspection::TypeKind;
22-
using introspection::getTypeKindNames;
23-
using introspection::getTypeKindValues;
24-
25-
using introspection::DirectiveLocation;
26-
using introspection::getDirectiveLocationNames;
27-
using introspection::getDirectiveLocationValues;
28-
2923
using introspection::AddSchemaDetails;
3024
using introspection::AddTypeDetails;
3125
using introspection::AddFieldDetails;
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#pragma once
7+
8+
#ifndef INTROSPECTIONSHAREDTYPES_H
9+
#define INTROSPECTIONSHAREDTYPES_H
10+
11+
#include "graphqlservice/GraphQLResponse.h"
12+
13+
#include "graphqlservice/internal/Version.h"
14+
15+
#include <array>
16+
#include <memory>
17+
#include <optional>
18+
#include <string>
19+
#include <string_view>
20+
#include <vector>
21+
22+
// Check if the library version is compatible with schemagen 5.0.0
23+
static_assert(graphql::internal::MajorVersion == 5, "regenerate with schemagen: major version mismatch");
24+
static_assert(graphql::internal::MinorVersion == 0, "regenerate with schemagen: minor version mismatch");
25+
26+
namespace graphql::introspection {
27+
28+
enum class TypeKind
29+
{
30+
SCALAR,
31+
OBJECT,
32+
INTERFACE,
33+
UNION,
34+
ENUM,
35+
INPUT_OBJECT,
36+
LIST,
37+
NON_NULL
38+
};
39+
40+
[[nodiscard("unnecessary call")]] constexpr auto getTypeKindNames() noexcept
41+
{
42+
using namespace std::literals;
43+
44+
return std::array<std::string_view, 8> {
45+
R"gql(SCALAR)gql"sv,
46+
R"gql(OBJECT)gql"sv,
47+
R"gql(INTERFACE)gql"sv,
48+
R"gql(UNION)gql"sv,
49+
R"gql(ENUM)gql"sv,
50+
R"gql(INPUT_OBJECT)gql"sv,
51+
R"gql(LIST)gql"sv,
52+
R"gql(NON_NULL)gql"sv
53+
};
54+
}
55+
56+
[[nodiscard("unnecessary call")]] constexpr auto getTypeKindValues() noexcept
57+
{
58+
using namespace std::literals;
59+
60+
return std::array<std::pair<std::string_view, TypeKind>, 8> {
61+
std::make_pair(R"gql(ENUM)gql"sv, TypeKind::ENUM),
62+
std::make_pair(R"gql(LIST)gql"sv, TypeKind::LIST),
63+
std::make_pair(R"gql(UNION)gql"sv, TypeKind::UNION),
64+
std::make_pair(R"gql(OBJECT)gql"sv, TypeKind::OBJECT),
65+
std::make_pair(R"gql(SCALAR)gql"sv, TypeKind::SCALAR),
66+
std::make_pair(R"gql(NON_NULL)gql"sv, TypeKind::NON_NULL),
67+
std::make_pair(R"gql(INTERFACE)gql"sv, TypeKind::INTERFACE),
68+
std::make_pair(R"gql(INPUT_OBJECT)gql"sv, TypeKind::INPUT_OBJECT)
69+
};
70+
}
71+
72+
enum class DirectiveLocation
73+
{
74+
QUERY,
75+
MUTATION,
76+
SUBSCRIPTION,
77+
FIELD,
78+
FRAGMENT_DEFINITION,
79+
FRAGMENT_SPREAD,
80+
INLINE_FRAGMENT,
81+
VARIABLE_DEFINITION,
82+
SCHEMA,
83+
SCALAR,
84+
OBJECT,
85+
FIELD_DEFINITION,
86+
ARGUMENT_DEFINITION,
87+
INTERFACE,
88+
UNION,
89+
ENUM,
90+
ENUM_VALUE,
91+
INPUT_OBJECT,
92+
INPUT_FIELD_DEFINITION
93+
};
94+
95+
[[nodiscard("unnecessary call")]] constexpr auto getDirectiveLocationNames() noexcept
96+
{
97+
using namespace std::literals;
98+
99+
return std::array<std::string_view, 19> {
100+
R"gql(QUERY)gql"sv,
101+
R"gql(MUTATION)gql"sv,
102+
R"gql(SUBSCRIPTION)gql"sv,
103+
R"gql(FIELD)gql"sv,
104+
R"gql(FRAGMENT_DEFINITION)gql"sv,
105+
R"gql(FRAGMENT_SPREAD)gql"sv,
106+
R"gql(INLINE_FRAGMENT)gql"sv,
107+
R"gql(VARIABLE_DEFINITION)gql"sv,
108+
R"gql(SCHEMA)gql"sv,
109+
R"gql(SCALAR)gql"sv,
110+
R"gql(OBJECT)gql"sv,
111+
R"gql(FIELD_DEFINITION)gql"sv,
112+
R"gql(ARGUMENT_DEFINITION)gql"sv,
113+
R"gql(INTERFACE)gql"sv,
114+
R"gql(UNION)gql"sv,
115+
R"gql(ENUM)gql"sv,
116+
R"gql(ENUM_VALUE)gql"sv,
117+
R"gql(INPUT_OBJECT)gql"sv,
118+
R"gql(INPUT_FIELD_DEFINITION)gql"sv
119+
};
120+
}
121+
122+
[[nodiscard("unnecessary call")]] constexpr auto getDirectiveLocationValues() noexcept
123+
{
124+
using namespace std::literals;
125+
126+
return std::array<std::pair<std::string_view, DirectiveLocation>, 19> {
127+
std::make_pair(R"gql(ENUM)gql"sv, DirectiveLocation::ENUM),
128+
std::make_pair(R"gql(FIELD)gql"sv, DirectiveLocation::FIELD),
129+
std::make_pair(R"gql(QUERY)gql"sv, DirectiveLocation::QUERY),
130+
std::make_pair(R"gql(UNION)gql"sv, DirectiveLocation::UNION),
131+
std::make_pair(R"gql(OBJECT)gql"sv, DirectiveLocation::OBJECT),
132+
std::make_pair(R"gql(SCALAR)gql"sv, DirectiveLocation::SCALAR),
133+
std::make_pair(R"gql(SCHEMA)gql"sv, DirectiveLocation::SCHEMA),
134+
std::make_pair(R"gql(MUTATION)gql"sv, DirectiveLocation::MUTATION),
135+
std::make_pair(R"gql(INTERFACE)gql"sv, DirectiveLocation::INTERFACE),
136+
std::make_pair(R"gql(ENUM_VALUE)gql"sv, DirectiveLocation::ENUM_VALUE),
137+
std::make_pair(R"gql(INPUT_OBJECT)gql"sv, DirectiveLocation::INPUT_OBJECT),
138+
std::make_pair(R"gql(SUBSCRIPTION)gql"sv, DirectiveLocation::SUBSCRIPTION),
139+
std::make_pair(R"gql(FRAGMENT_SPREAD)gql"sv, DirectiveLocation::FRAGMENT_SPREAD),
140+
std::make_pair(R"gql(INLINE_FRAGMENT)gql"sv, DirectiveLocation::INLINE_FRAGMENT),
141+
std::make_pair(R"gql(FIELD_DEFINITION)gql"sv, DirectiveLocation::FIELD_DEFINITION),
142+
std::make_pair(R"gql(ARGUMENT_DEFINITION)gql"sv, DirectiveLocation::ARGUMENT_DEFINITION),
143+
std::make_pair(R"gql(FRAGMENT_DEFINITION)gql"sv, DirectiveLocation::FRAGMENT_DEFINITION),
144+
std::make_pair(R"gql(VARIABLE_DEFINITION)gql"sv, DirectiveLocation::VARIABLE_DEFINITION),
145+
std::make_pair(R"gql(INPUT_FIELD_DEFINITION)gql"sv, DirectiveLocation::INPUT_FIELD_DEFINITION)
146+
};
147+
}
148+
149+
} // namespace graphql::introspection
150+
151+
#endif // INTROSPECTIONSHAREDTYPES_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
module;
7+
8+
#include "IntrospectionSharedTypes.h"
9+
10+
export module GraphQL.Introspection.IntrospectionSharedTypes;
11+
12+
export namespace graphql::introspection {
13+
14+
using introspection::TypeKind;
15+
using introspection::getTypeKindNames;
16+
using introspection::getTypeKindValues;
17+
18+
using introspection::DirectiveLocation;
19+
using introspection::getDirectiveLocationNames;
20+
using introspection::getDirectiveLocationValues;
21+
22+
} // namespace graphql::introspection

0 commit comments

Comments
 (0)