Skip to content

Commit 73f7d98

Browse files
committed
Start narrowing down the DLL exports on Windows
1 parent 8f3e6a2 commit 73f7d98

File tree

11 files changed

+223
-78
lines changed

11 files changed

+223
-78
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33

44
cmake_minimum_required(VERSION 3.8.2)
5-
project(cppgraphqlgen VERSION 3.0.0)
5+
project(cppgraphqlgen VERSION 3.2.0)
66

77
set(CMAKE_CXX_STANDARD 17)
88

@@ -12,11 +12,6 @@ set(GRAPHQL_INSTALL_CMAKE_DIR lib/cmake CACHE PATH "CMake config files install d
1212

1313
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
1414

15-
if(WIN32 AND BUILD_SHARED_LIBS)
16-
# Let CMake figure out the exports for the SHARED library (DLL) on Windows.
17-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
18-
endif()
19-
2015
function(add_bigobj_flag target)
2116
if(MSVC)
2217
# MSVC requires the /bigobj flag if the number of sections gets too big.

include/graphqlservice/GraphQLParse.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#ifndef GRAPHQLPARSE_H
77
#define GRAPHQLPARSE_H
88

9+
#ifdef GRAPHQL_DLLEXPORTS
10+
#ifdef IMPL_GRAPHQLPEG_DLL
11+
#define GRAPHQLPEG_EXPORT __declspec(dllexport)
12+
#else // !IMPL_GRAPHQLPEG_DLL
13+
#define GRAPHQLPEG_EXPORT __declspec(dllimport)
14+
#endif // !IMPL_GRAPHQLPEG_DLL
15+
#else // !GRAPHQL_DLLEXPORTS
16+
#define GRAPHQLPEG_EXPORT
17+
#endif // !GRAPHQL_DLLEXPORTS
18+
919
#include <memory>
1020
#include <string_view>
1121

@@ -22,12 +32,12 @@ struct ast
2232
bool validated = false;
2333
};
2434

25-
ast parseString(std::string_view input);
26-
ast parseFile(std::string_view filename);
35+
GRAPHQLPEG_EXPORT ast parseString(std::string_view input);
36+
GRAPHQLPEG_EXPORT ast parseFile(std::string_view filename);
2737

2838
} /* namespace peg */
2939

30-
peg::ast operator "" _graphql(const char* text, size_t size);
40+
GRAPHQLPEG_EXPORT peg::ast operator "" _graphql(const char* text, size_t size);
3141

3242
} /* namespace graphql */
3343

include/graphqlservice/GraphQLResponse.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#ifndef GRAPHQLRESPONSE_H
77
#define GRAPHQLRESPONSE_H
88

9+
#ifdef GRAPHQL_DLLEXPORTS
10+
#ifdef IMPL_GRAPHQLRESPONSE_LIB
11+
#define GRAPHQLRESPONSE_EXPORT __declspec(dllexport)
12+
#else // !IMPL_GRAPHQLRESPONSE_LIB
13+
#define GRAPHQLRESPONSE_EXPORT __declspec(dllimport)
14+
#endif // !IMPL_GRAPHQLRESPONSE_LIB
15+
#else // !GRAPHQL_DLLEXPORTS
16+
#define GRAPHQLRESPONSE_EXPORT
17+
#endif // !GRAPHQL_DLLEXPORTS
18+
919
#include <memory>
1020
#include <string>
1121
#include <vector>
@@ -100,7 +110,7 @@ struct ValueTypeTraits<IdType>
100110
struct TypedData;
101111

102112
// Represent a discriminated union of GraphQL response value types.
103-
struct Value
113+
struct GRAPHQLRESPONSE_EXPORT Value
104114
{
105115
Value(Type type = Type::Null);
106116
~Value();
@@ -178,6 +188,26 @@ struct Value
178188
std::unique_ptr<TypedData> _data;
179189
};
180190

191+
#ifdef GRAPHQL_DLLEXPORTS
192+
// Export all of the specialized template methods
193+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<StringType>(StringType&& value);
194+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<BooleanType>(BooleanType value);
195+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<IntType>(IntType value);
196+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<FloatType>(FloatType value);
197+
template <> GRAPHQLRESPONSE_EXPORT void Value::set<ScalarType>(ScalarType&& value);
198+
template <> GRAPHQLRESPONSE_EXPORT const MapType& Value::get<MapType>() const;
199+
template <> GRAPHQLRESPONSE_EXPORT const ListType& Value::get<ListType>() const;
200+
template <> GRAPHQLRESPONSE_EXPORT const StringType& Value::get<StringType>() const;
201+
template <> GRAPHQLRESPONSE_EXPORT BooleanType Value::get<BooleanType>() const;
202+
template <> GRAPHQLRESPONSE_EXPORT IntType Value::get<IntType>() const;
203+
template <> GRAPHQLRESPONSE_EXPORT FloatType Value::get<FloatType>() const;
204+
template <> GRAPHQLRESPONSE_EXPORT const ScalarType& Value::get<ScalarType>() const;
205+
template <> GRAPHQLRESPONSE_EXPORT MapType Value::release<MapType>();
206+
template <> GRAPHQLRESPONSE_EXPORT ListType Value::release<ListType>();
207+
template <> GRAPHQLRESPONSE_EXPORT StringType Value::release<StringType>();
208+
template <> GRAPHQLRESPONSE_EXPORT ScalarType Value::release<ScalarType>();
209+
#endif // GRAPHQL_DLLEXPORTS
210+
181211
} /* namespace graphql::response */
182212

183213
#endif // GRAPHQLRESPONSE_H

include/graphqlservice/GraphQLService.h

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#ifndef GRAPHQLSERVICE_H
77
#define GRAPHQLSERVICE_H
88

9+
#ifdef GRAPHQL_DLLEXPORTS
10+
#ifdef IMPL_GRAPHQLSERVICE_DLL
11+
#define GRAPHQLSERVICE_EXPORT __declspec(dllexport)
12+
#else // !IMPL_GRAPHQLSERVICE_DLL
13+
#define GRAPHQLSERVICE_EXPORT __declspec(dllimport)
14+
#endif // !IMPL_GRAPHQLSERVICE_DLL
15+
#else // !GRAPHQL_DLLEXPORTS
16+
#define GRAPHQLSERVICE_EXPORT
17+
#endif // !GRAPHQL_DLLEXPORTS
18+
919
#include "graphqlservice/GraphQLParse.h"
1020
#include "graphqlservice/GraphQLResponse.h"
1121

@@ -30,32 +40,32 @@
3040
namespace graphql::service {
3141

3242
// Errors should have a message string, and optional locations and a path.
33-
void addErrorMessage(std::string&& message, response::Value& error);
43+
GRAPHQLSERVICE_EXPORT void addErrorMessage(std::string&& message, response::Value& error);
3444

3545
struct schema_location
3646
{
3747
size_t line = 0;
3848
size_t byte_in_line = 0;
3949
};
4050

41-
void addErrorLocation(const schema_location& location, response::Value& error);
51+
GRAPHQLSERVICE_EXPORT void addErrorLocation(const schema_location& location, response::Value& error);
4252

4353
using path_segment = std::variant<std::string, size_t>;
4454
using field_path = std::queue<path_segment>;
4555

46-
void addErrorPath(field_path&& path, response::Value& error);
56+
GRAPHQLSERVICE_EXPORT void addErrorPath(field_path&& path, response::Value& error);
4757

48-
struct schema_error
58+
struct GRAPHQLSERVICE_EXPORT schema_error
4959
{
5060
std::string message;
5161
schema_location location;
5262
field_path path;
5363
};
5464

55-
response::Value buildErrorValues(const std::vector<schema_error>& structuredErrors);
65+
GRAPHQLSERVICE_EXPORT response::Value buildErrorValues(const std::vector<schema_error>& structuredErrors);
5666

5767
// This exception bubbles up 1 or more error messages to the JSON results.
58-
class schema_exception : public std::exception
68+
class GRAPHQLSERVICE_EXPORT schema_exception : public std::exception
5969
{
6070
public:
6171
explicit schema_exception(std::vector<schema_error>&& structuredErrors);
@@ -82,7 +92,7 @@ class schema_exception : public std::exception
8292
// per-request state that you want to maintain throughout the request (e.g. optimizing or batching
8393
// backend requests), you can inherit from RequestState and pass it to Request::resolve to correlate the
8494
// asynchronous/recursive callbacks and accumulate state in it.
85-
struct RequestState : std::enable_shared_from_this<RequestState>
95+
struct GRAPHQLSERVICE_EXPORT RequestState : std::enable_shared_from_this<RequestState>
8696
{
8797
};
8898

@@ -104,7 +114,7 @@ constexpr std::string_view strSubscription { "subscription"sv };
104114
}
105115

106116
// Pass a common bundle of parameters to all of the generated Object::getField accessors in a SelectionSet
107-
struct SelectionSetParams
117+
struct GRAPHQLSERVICE_EXPORT SelectionSetParams
108118
{
109119
// The lifetime of each of these borrowed references is guaranteed until the future returned
110120
// by the accessor is resolved or destroyed. They are owned by the OperationData shared pointer.
@@ -126,7 +136,7 @@ struct SelectionSetParams
126136
};
127137

128138
// Pass a common bundle of parameters to all of the generated Object::getField accessors.
129-
struct FieldParams : SelectionSetParams
139+
struct GRAPHQLSERVICE_EXPORT FieldParams : SelectionSetParams
130140
{
131141
explicit FieldParams(const SelectionSetParams& selectionSetParams, response::Value&& directives);
132142

@@ -164,7 +174,7 @@ class FieldResult
164174
// Fragments are referenced by name and have a single type condition (except for inline
165175
// fragments, where the type condition is common but optional). They contain a set of fields
166176
// (with optional aliases and sub-selections) and potentially references to other fragments.
167-
class Fragment
177+
class GRAPHQLSERVICE_EXPORT Fragment
168178
{
169179
public:
170180
explicit Fragment(const peg::ast_node& fragmentDefinition, const response::Value& variables);
@@ -187,7 +197,7 @@ using FragmentMap = std::unordered_map<std::string, Fragment>;
187197
// Resolver functors take a set of arguments encoded as members on a JSON object
188198
// with an optional selection set for complex types and return a JSON value for
189199
// a single field.
190-
struct ResolverParams : SelectionSetParams
200+
struct GRAPHQLSERVICE_EXPORT ResolverParams : SelectionSetParams
191201
{
192202
explicit ResolverParams(const SelectionSetParams& selectionSetParams, const peg::ast_node& field,
193203
std::string&& fieldName, response::Value&& arguments, response::Value&& fieldDirectives,
@@ -212,7 +222,7 @@ using Resolver = std::function<std::future<response::Value>(ResolverParams&&)>;
212222
using ResolverMap = std::unordered_map<std::string, Resolver>;
213223

214224
// Binary data and opaque strings like IDs are encoded in Base64.
215-
class Base64
225+
class GRAPHQLSERVICE_EXPORT Base64
216226
{
217227
public:
218228
// Map a single Base64-encoded character to its 6-bit integer value.
@@ -402,6 +412,16 @@ using BooleanArgument = ModifiedArgument<response::BooleanType>;
402412
using IdArgument = ModifiedArgument<response::IdType>;
403413
using ScalarArgument = ModifiedArgument<response::Value>;
404414

415+
#ifdef GRAPHQL_DLLEXPORTS
416+
// Export all of the built-in converters
417+
template <> GRAPHQLSERVICE_EXPORT response::IntType ModifiedArgument<response::IntType>::convert(const response::Value& value);
418+
template <> GRAPHQLSERVICE_EXPORT response::FloatType ModifiedArgument<response::FloatType>::convert(const response::Value& value);
419+
template <> GRAPHQLSERVICE_EXPORT response::StringType ModifiedArgument<response::StringType>::convert(const response::Value& value);
420+
template <> GRAPHQLSERVICE_EXPORT response::BooleanType ModifiedArgument<response::BooleanType>::convert(const response::Value& value);
421+
template <> GRAPHQLSERVICE_EXPORT response::IdType ModifiedArgument<response::IdType>::convert(const response::Value& value);
422+
template <> GRAPHQLSERVICE_EXPORT response::Value ModifiedArgument<response::Value>::convert(const response::Value& value);
423+
#endif // GRAPHQL_DLLEXPORTS
424+
405425
// Each type should handle fragments with type conditions matching its own
406426
// name and any inheritted interfaces.
407427
using TypeNames = std::unordered_set<std::string>;
@@ -410,7 +430,7 @@ using TypeNames = std::unordered_set<std::string>;
410430
// and @skip directives, and calls through to the resolver functor for each selected field with
411431
// its arguments. This may be a recursive process for fields which return another complex type,
412432
// in which case it requires its own selection set.
413-
class Object : public std::enable_shared_from_this<Object>
433+
class GRAPHQLSERVICE_EXPORT Object : public std::enable_shared_from_this<Object>
414434
{
415435
public:
416436
explicit Object(TypeNames&& typeNames, ResolverMap&& resolvers);
@@ -747,12 +767,23 @@ using IdResult = ModifiedResult<response::IdType>;
747767
using ScalarResult = ModifiedResult<response::Value>;
748768
using ObjectResult = ModifiedResult<Object>;
749769

770+
#ifdef GRAPHQL_DLLEXPORTS
771+
// Export all of the built-in converters
772+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::IntType>::convert(FieldResult<response::IntType>&& result, ResolverParams&& params);
773+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::FloatType>::convert(FieldResult<response::FloatType>&& result, ResolverParams&& params);
774+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::StringType>::convert(FieldResult<response::StringType>&& result, ResolverParams&& params);
775+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::BooleanType>::convert(FieldResult<response::BooleanType>&& result, ResolverParams&& params);
776+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::IdType>::convert(FieldResult<response::IdType>&& result, ResolverParams&& params);
777+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<response::Value>::convert(FieldResult<response::Value>&& result, ResolverParams&& params);
778+
template <> GRAPHQLSERVICE_EXPORT std::future<response::Value> ModifiedResult<Object>::convert(FieldResult<std::shared_ptr<Object>>&& result, ResolverParams&& params);
779+
#endif // GRAPHQL_DLLEXPORTS
780+
750781
using TypeMap = std::unordered_map<std::string, std::shared_ptr<Object>>;
751782

752783
// You can still sub-class RequestState and use that in the state parameter to Request::subscribe
753784
// to add your own state to the service callbacks that you receive while executing the subscription
754785
// query.
755-
struct SubscriptionParams
786+
struct GRAPHQLSERVICE_EXPORT SubscriptionParams
756787
{
757788
std::shared_ptr<RequestState> state;
758789
peg::ast query;
@@ -807,7 +838,7 @@ struct SubscriptionData : std::enable_shared_from_this<SubscriptionData>
807838
// Request scans the fragment definitions and finds the right operation definition to interpret
808839
// depending on the operation name (which might be empty for a single-operation document). It
809840
// also needs the values of the request variables.
810-
class Request : public std::enable_shared_from_this<Request>
841+
class GRAPHQLSERVICE_EXPORT Request : public std::enable_shared_from_this<Request>
811842
{
812843
protected:
813844
explicit Request(TypeMap&& operationTypes);

0 commit comments

Comments
 (0)