6
6
#ifndef GRAPHQLSERVICE_H
7
7
#define GRAPHQLSERVICE_H
8
8
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
+
9
19
#include " graphqlservice/GraphQLParse.h"
10
20
#include " graphqlservice/GraphQLResponse.h"
11
21
30
40
namespace graphql ::service {
31
41
32
42
// 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);
34
44
35
45
struct schema_location
36
46
{
37
47
size_t line = 0 ;
38
48
size_t byte_in_line = 0 ;
39
49
};
40
50
41
- void addErrorLocation (const schema_location& location, response::Value& error);
51
+ GRAPHQLSERVICE_EXPORT void addErrorLocation (const schema_location& location, response::Value& error);
42
52
43
53
using path_segment = std::variant<std::string, size_t >;
44
54
using field_path = std::queue<path_segment>;
45
55
46
- void addErrorPath (field_path&& path, response::Value& error);
56
+ GRAPHQLSERVICE_EXPORT void addErrorPath (field_path&& path, response::Value& error);
47
57
48
- struct schema_error
58
+ struct GRAPHQLSERVICE_EXPORT schema_error
49
59
{
50
60
std::string message;
51
61
schema_location location;
52
62
field_path path;
53
63
};
54
64
55
- response::Value buildErrorValues (const std::vector<schema_error>& structuredErrors);
65
+ GRAPHQLSERVICE_EXPORT response::Value buildErrorValues (const std::vector<schema_error>& structuredErrors);
56
66
57
67
// 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
59
69
{
60
70
public:
61
71
explicit schema_exception (std::vector<schema_error>&& structuredErrors);
@@ -82,7 +92,7 @@ class schema_exception : public std::exception
82
92
// per-request state that you want to maintain throughout the request (e.g. optimizing or batching
83
93
// backend requests), you can inherit from RequestState and pass it to Request::resolve to correlate the
84
94
// 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>
86
96
{
87
97
};
88
98
@@ -104,7 +114,7 @@ constexpr std::string_view strSubscription { "subscription"sv };
104
114
}
105
115
106
116
// 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
108
118
{
109
119
// The lifetime of each of these borrowed references is guaranteed until the future returned
110
120
// by the accessor is resolved or destroyed. They are owned by the OperationData shared pointer.
@@ -126,7 +136,7 @@ struct SelectionSetParams
126
136
};
127
137
128
138
// Pass a common bundle of parameters to all of the generated Object::getField accessors.
129
- struct FieldParams : SelectionSetParams
139
+ struct GRAPHQLSERVICE_EXPORT FieldParams : SelectionSetParams
130
140
{
131
141
explicit FieldParams (const SelectionSetParams& selectionSetParams, response::Value&& directives);
132
142
@@ -164,7 +174,7 @@ class FieldResult
164
174
// Fragments are referenced by name and have a single type condition (except for inline
165
175
// fragments, where the type condition is common but optional). They contain a set of fields
166
176
// (with optional aliases and sub-selections) and potentially references to other fragments.
167
- class Fragment
177
+ class GRAPHQLSERVICE_EXPORT Fragment
168
178
{
169
179
public:
170
180
explicit Fragment (const peg::ast_node& fragmentDefinition, const response::Value& variables);
@@ -187,7 +197,7 @@ using FragmentMap = std::unordered_map<std::string, Fragment>;
187
197
// Resolver functors take a set of arguments encoded as members on a JSON object
188
198
// with an optional selection set for complex types and return a JSON value for
189
199
// a single field.
190
- struct ResolverParams : SelectionSetParams
200
+ struct GRAPHQLSERVICE_EXPORT ResolverParams : SelectionSetParams
191
201
{
192
202
explicit ResolverParams (const SelectionSetParams& selectionSetParams, const peg::ast_node& field,
193
203
std::string&& fieldName, response::Value&& arguments, response::Value&& fieldDirectives,
@@ -212,7 +222,7 @@ using Resolver = std::function<std::future<response::Value>(ResolverParams&&)>;
212
222
using ResolverMap = std::unordered_map<std::string, Resolver>;
213
223
214
224
// Binary data and opaque strings like IDs are encoded in Base64.
215
- class Base64
225
+ class GRAPHQLSERVICE_EXPORT Base64
216
226
{
217
227
public:
218
228
// Map a single Base64-encoded character to its 6-bit integer value.
@@ -402,6 +412,16 @@ using BooleanArgument = ModifiedArgument<response::BooleanType>;
402
412
using IdArgument = ModifiedArgument<response::IdType>;
403
413
using ScalarArgument = ModifiedArgument<response::Value>;
404
414
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
+
405
425
// Each type should handle fragments with type conditions matching its own
406
426
// name and any inheritted interfaces.
407
427
using TypeNames = std::unordered_set<std::string>;
@@ -410,7 +430,7 @@ using TypeNames = std::unordered_set<std::string>;
410
430
// and @skip directives, and calls through to the resolver functor for each selected field with
411
431
// its arguments. This may be a recursive process for fields which return another complex type,
412
432
// 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>
414
434
{
415
435
public:
416
436
explicit Object (TypeNames&& typeNames, ResolverMap&& resolvers);
@@ -747,12 +767,23 @@ using IdResult = ModifiedResult<response::IdType>;
747
767
using ScalarResult = ModifiedResult<response::Value>;
748
768
using ObjectResult = ModifiedResult<Object>;
749
769
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
+
750
781
using TypeMap = std::unordered_map<std::string, std::shared_ptr<Object>>;
751
782
752
783
// You can still sub-class RequestState and use that in the state parameter to Request::subscribe
753
784
// to add your own state to the service callbacks that you receive while executing the subscription
754
785
// query.
755
- struct SubscriptionParams
786
+ struct GRAPHQLSERVICE_EXPORT SubscriptionParams
756
787
{
757
788
std::shared_ptr<RequestState> state;
758
789
peg::ast query;
@@ -807,7 +838,7 @@ struct SubscriptionData : std::enable_shared_from_this<SubscriptionData>
807
838
// Request scans the fragment definitions and finds the right operation definition to interpret
808
839
// depending on the operation name (which might be empty for a single-operation document). It
809
840
// 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>
811
842
{
812
843
protected:
813
844
explicit Request (TypeMap&& operationTypes);
0 commit comments