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
3040namespace 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
3545struct 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
4353using path_segment = std::variant<std::string, size_t >;
4454using 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{
6070public:
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{
169179public:
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&&)>;
212222using 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{
217227public:
218228 // Map a single Base64-encoded character to its 6-bit integer value.
@@ -402,6 +412,16 @@ using BooleanArgument = ModifiedArgument<response::BooleanType>;
402412using IdArgument = ModifiedArgument<response::IdType>;
403413using 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.
407427using 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{
415435public:
416436 explicit Object (TypeNames&& typeNames, ResolverMap&& resolvers);
@@ -747,12 +767,23 @@ using IdResult = ModifiedResult<response::IdType>;
747767using ScalarResult = ModifiedResult<response::Value>;
748768using 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+
750781using 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{
812843protected:
813844 explicit Request (TypeMap&& operationTypes);
0 commit comments