Skip to content

Commit d22231d

Browse files
committed
Switch IntrospectionSchema to separate files
1 parent 218e7d9 commit d22231d

File tree

94 files changed

+3612
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3612
-1405
lines changed

cmake/cppgraphqlgen-functions.cmake

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ function(add_graphql_schema_target SCHEMA_TARGET)
4242
add_custom_target(${SCHEMA_TARGET}_update_schema ALL
4343
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
4444

45-
file(STRINGS ${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
46-
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
47-
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
48-
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
49-
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
45+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
46+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
47+
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
48+
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
49+
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
50+
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
51+
endif()
5052
endfunction()
5153

5254
function(add_graphql_schema_no_introspection_target SCHEMA_NO_INTROSPECTION_TARGET)
5355
add_custom_target(${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema ALL
5456
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
5557

56-
file(STRINGS ${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
57-
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
58-
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
59-
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
60-
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
58+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
59+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
60+
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
61+
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
62+
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
63+
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
64+
endif()
6165
endfunction()
6266

6367
function(update_graphql_client_files CLIENT_TARGET SCHEMA_GRAPHQL REQUEST_GRAPHQL CLIENT_PREFIX CLIENT_NAMESPACE)
@@ -93,9 +97,11 @@ function(add_graphql_client_target CLIENT_TARGET)
9397
add_custom_target(${CLIENT_TARGET}_update_client ALL
9498
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
9599

96-
file(STRINGS ${CLIENT_TARGET}_client_files CLIENT_FILES)
97-
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
98-
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
99-
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
100-
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
100+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
101+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files CLIENT_FILES)
102+
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
103+
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
104+
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
105+
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
106+
endif()
101107
endfunction()

include/SchemaLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct SchemaOptions
209209
const std::string schemaFilename;
210210
const std::string filenamePrefix;
211211
const std::string schemaNamespace;
212+
const bool isIntrospection = false;
212213
};
213214

214215
class SchemaLoader

include/graphqlservice/introspection/Introspection.h renamed to include/graphqlservice/internal/Introspection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#ifndef INTROSPECTION_H
77
#define INTROSPECTION_H
88

9-
#include "graphqlservice/internal/Schema.h"
10-
119
#include "graphqlservice/introspection/IntrospectionSchema.h"
1210

11+
#include "graphqlservice/internal/Schema.h"
12+
1313
namespace graphql::introspection {
1414

1515
class Schema;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 DIRECTIVEOBJECT_H
9+
#define DIRECTIVEOBJECT_H
10+
11+
#include "IntrospectionSchema.h"
12+
13+
namespace graphql::introspection::object {
14+
namespace methods::DirectiveHas {
15+
16+
template <class TImpl>
17+
concept getNameWithParams = requires (TImpl impl, service::FieldParams params)
18+
{
19+
{ service::FieldResult<std::string> { impl.getName(std::move(params)) } };
20+
};
21+
22+
template <class TImpl>
23+
concept getName = requires (TImpl impl)
24+
{
25+
{ service::FieldResult<std::string> { impl.getName() } };
26+
};
27+
28+
template <class TImpl>
29+
concept getDescriptionWithParams = requires (TImpl impl, service::FieldParams params)
30+
{
31+
{ service::FieldResult<std::optional<std::string>> { impl.getDescription(std::move(params)) } };
32+
};
33+
34+
template <class TImpl>
35+
concept getDescription = requires (TImpl impl)
36+
{
37+
{ service::FieldResult<std::optional<std::string>> { impl.getDescription() } };
38+
};
39+
40+
template <class TImpl>
41+
concept getLocationsWithParams = requires (TImpl impl, service::FieldParams params)
42+
{
43+
{ service::FieldResult<std::vector<DirectiveLocation>> { impl.getLocations(std::move(params)) } };
44+
};
45+
46+
template <class TImpl>
47+
concept getLocations = requires (TImpl impl)
48+
{
49+
{ service::FieldResult<std::vector<DirectiveLocation>> { impl.getLocations() } };
50+
};
51+
52+
template <class TImpl>
53+
concept getArgsWithParams = requires (TImpl impl, service::FieldParams params)
54+
{
55+
{ service::FieldResult<std::vector<std::shared_ptr<InputValue>>> { impl.getArgs(std::move(params)) } };
56+
};
57+
58+
template <class TImpl>
59+
concept getArgs = requires (TImpl impl)
60+
{
61+
{ service::FieldResult<std::vector<std::shared_ptr<InputValue>>> { impl.getArgs() } };
62+
};
63+
64+
template <class TImpl>
65+
concept beginSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
66+
{
67+
{ impl.beginSelectionSet(params) };
68+
};
69+
70+
template <class TImpl>
71+
concept endSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
72+
{
73+
{ impl.endSelectionSet(params) };
74+
};
75+
76+
} // namespace methods::DirectiveHas
77+
78+
class Directive
79+
: public service::Object
80+
{
81+
private:
82+
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
83+
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
84+
service::AwaitableResolver resolveLocations(service::ResolverParams&& params) const;
85+
service::AwaitableResolver resolveArgs(service::ResolverParams&& params) const;
86+
87+
service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
88+
89+
struct Concept
90+
{
91+
virtual ~Concept() = default;
92+
93+
virtual service::FieldResult<std::string> getName(service::FieldParams&& params) const = 0;
94+
virtual service::FieldResult<std::optional<std::string>> getDescription(service::FieldParams&& params) const = 0;
95+
virtual service::FieldResult<std::vector<DirectiveLocation>> getLocations(service::FieldParams&& params) const = 0;
96+
virtual service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs(service::FieldParams&& params) const = 0;
97+
};
98+
99+
template <class T>
100+
struct Model
101+
: Concept
102+
{
103+
Model(std::shared_ptr<T>&& pimpl) noexcept
104+
: _pimpl { std::move(pimpl) }
105+
{
106+
}
107+
108+
service::FieldResult<std::string> getName(service::FieldParams&&) const final
109+
{
110+
return { _pimpl->getName() };
111+
}
112+
113+
service::FieldResult<std::optional<std::string>> getDescription(service::FieldParams&&) const final
114+
{
115+
return { _pimpl->getDescription() };
116+
}
117+
118+
service::FieldResult<std::vector<DirectiveLocation>> getLocations(service::FieldParams&&) const final
119+
{
120+
return { _pimpl->getLocations() };
121+
}
122+
123+
service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs(service::FieldParams&&) const final
124+
{
125+
return { _pimpl->getArgs() };
126+
}
127+
128+
private:
129+
const std::shared_ptr<T> _pimpl;
130+
};
131+
132+
const std::unique_ptr<Concept> _pimpl;
133+
134+
service::TypeNames getTypeNames() const noexcept;
135+
service::ResolverMap getResolvers() const noexcept;
136+
137+
public:
138+
GRAPHQLINTROSPECTION_EXPORT Directive(std::shared_ptr<introspection::Directive> pimpl) noexcept;
139+
GRAPHQLINTROSPECTION_EXPORT ~Directive();
140+
};
141+
142+
} // namespace graphql::introspection::object
143+
144+
#endif // DIRECTIVEOBJECT_H
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 ENUMVALUEOBJECT_H
9+
#define ENUMVALUEOBJECT_H
10+
11+
#include "IntrospectionSchema.h"
12+
13+
namespace graphql::introspection::object {
14+
namespace methods::EnumValueHas {
15+
16+
template <class TImpl>
17+
concept getNameWithParams = requires (TImpl impl, service::FieldParams params)
18+
{
19+
{ service::FieldResult<std::string> { impl.getName(std::move(params)) } };
20+
};
21+
22+
template <class TImpl>
23+
concept getName = requires (TImpl impl)
24+
{
25+
{ service::FieldResult<std::string> { impl.getName() } };
26+
};
27+
28+
template <class TImpl>
29+
concept getDescriptionWithParams = requires (TImpl impl, service::FieldParams params)
30+
{
31+
{ service::FieldResult<std::optional<std::string>> { impl.getDescription(std::move(params)) } };
32+
};
33+
34+
template <class TImpl>
35+
concept getDescription = requires (TImpl impl)
36+
{
37+
{ service::FieldResult<std::optional<std::string>> { impl.getDescription() } };
38+
};
39+
40+
template <class TImpl>
41+
concept getIsDeprecatedWithParams = requires (TImpl impl, service::FieldParams params)
42+
{
43+
{ service::FieldResult<bool> { impl.getIsDeprecated(std::move(params)) } };
44+
};
45+
46+
template <class TImpl>
47+
concept getIsDeprecated = requires (TImpl impl)
48+
{
49+
{ service::FieldResult<bool> { impl.getIsDeprecated() } };
50+
};
51+
52+
template <class TImpl>
53+
concept getDeprecationReasonWithParams = requires (TImpl impl, service::FieldParams params)
54+
{
55+
{ service::FieldResult<std::optional<std::string>> { impl.getDeprecationReason(std::move(params)) } };
56+
};
57+
58+
template <class TImpl>
59+
concept getDeprecationReason = requires (TImpl impl)
60+
{
61+
{ service::FieldResult<std::optional<std::string>> { impl.getDeprecationReason() } };
62+
};
63+
64+
template <class TImpl>
65+
concept beginSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
66+
{
67+
{ impl.beginSelectionSet(params) };
68+
};
69+
70+
template <class TImpl>
71+
concept endSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
72+
{
73+
{ impl.endSelectionSet(params) };
74+
};
75+
76+
} // namespace methods::EnumValueHas
77+
78+
class EnumValue
79+
: public service::Object
80+
{
81+
private:
82+
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
83+
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
84+
service::AwaitableResolver resolveIsDeprecated(service::ResolverParams&& params) const;
85+
service::AwaitableResolver resolveDeprecationReason(service::ResolverParams&& params) const;
86+
87+
service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
88+
89+
struct Concept
90+
{
91+
virtual ~Concept() = default;
92+
93+
virtual service::FieldResult<std::string> getName(service::FieldParams&& params) const = 0;
94+
virtual service::FieldResult<std::optional<std::string>> getDescription(service::FieldParams&& params) const = 0;
95+
virtual service::FieldResult<bool> getIsDeprecated(service::FieldParams&& params) const = 0;
96+
virtual service::FieldResult<std::optional<std::string>> getDeprecationReason(service::FieldParams&& params) const = 0;
97+
};
98+
99+
template <class T>
100+
struct Model
101+
: Concept
102+
{
103+
Model(std::shared_ptr<T>&& pimpl) noexcept
104+
: _pimpl { std::move(pimpl) }
105+
{
106+
}
107+
108+
service::FieldResult<std::string> getName(service::FieldParams&&) const final
109+
{
110+
return { _pimpl->getName() };
111+
}
112+
113+
service::FieldResult<std::optional<std::string>> getDescription(service::FieldParams&&) const final
114+
{
115+
return { _pimpl->getDescription() };
116+
}
117+
118+
service::FieldResult<bool> getIsDeprecated(service::FieldParams&&) const final
119+
{
120+
return { _pimpl->getIsDeprecated() };
121+
}
122+
123+
service::FieldResult<std::optional<std::string>> getDeprecationReason(service::FieldParams&&) const final
124+
{
125+
return { _pimpl->getDeprecationReason() };
126+
}
127+
128+
private:
129+
const std::shared_ptr<T> _pimpl;
130+
};
131+
132+
const std::unique_ptr<Concept> _pimpl;
133+
134+
service::TypeNames getTypeNames() const noexcept;
135+
service::ResolverMap getResolvers() const noexcept;
136+
137+
public:
138+
GRAPHQLINTROSPECTION_EXPORT EnumValue(std::shared_ptr<introspection::EnumValue> pimpl) noexcept;
139+
GRAPHQLINTROSPECTION_EXPORT ~EnumValue();
140+
};
141+
142+
} // namespace graphql::introspection::object
143+
144+
#endif // ENUMVALUEOBJECT_H

0 commit comments

Comments
 (0)