Skip to content

Remove the schemagen --merge-files option and make everything use separate files #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions cmake/cppgraphqlgen-functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ function(add_graphql_schema_target SCHEMA_TARGET)
add_custom_target(${SCHEMA_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)

file(STRINGS ${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
endif()
endfunction()

function(add_graphql_schema_no_introspection_target SCHEMA_NO_INTROSPECTION_TARGET)
add_custom_target(${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)

file(STRINGS ${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
endif()
endfunction()

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

file(STRINGS ${CLIENT_TARGET}_client_files CLIENT_FILES)
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files CLIENT_FILES)
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
endif()
endfunction()
2 changes: 1 addition & 1 deletion include/ClientGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct GeneratorPaths

struct GeneratorOptions
{
const std::optional<GeneratorPaths> paths;
const GeneratorPaths paths;
const bool verbose = false;
};

Expand Down
7 changes: 2 additions & 5 deletions include/SchemaGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ struct GeneratorPaths

struct GeneratorOptions
{
const std::optional<GeneratorPaths> paths;
const GeneratorPaths paths;
const bool verbose = false;
const bool stubs = false;
const bool mergeFiles = false;
const bool noIntrospection = false;
};

class Generator
{
public:
// Initialize the generator with the introspection schema or a custom GraphQL schema.
explicit Generator(std::optional<SchemaOptions>&& customSchema, GeneratorOptions&& options);
explicit Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options);

// Run the generator and return a list of filenames that were output.
std::vector<std::string> Build() const noexcept;
Expand All @@ -38,7 +37,6 @@ class Generator
std::string getHeaderDir() const noexcept;
std::string getSourceDir() const noexcept;
std::string getHeaderPath() const noexcept;
std::string getObjectHeaderPath() const noexcept;
std::string getSourcePath() const noexcept;

bool outputHeader() const noexcept;
Expand Down Expand Up @@ -80,7 +78,6 @@ class Generator
const std::string _headerDir;
const std::string _sourceDir;
const std::string _headerPath;
const std::string _objectHeaderPath;
const std::string _sourcePath;
};

Expand Down
5 changes: 3 additions & 2 deletions include/SchemaLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ struct SchemaOptions
const std::string schemaFilename;
const std::string filenamePrefix;
const std::string schemaNamespace;
const bool isIntrospection = false;
};

class SchemaLoader
{
public:
// Initialize the loader with the introspection schema or a custom GraphQL schema.
explicit SchemaLoader(std::optional<SchemaOptions>&& customSchema);
explicit SchemaLoader(SchemaOptions&& schemaOptions);

bool isIntrospection() const noexcept;
std::string_view getFilenamePrefix() const noexcept;
Expand Down Expand Up @@ -291,7 +292,7 @@ class SchemaLoader
static const CppTypeMap s_builtinCppTypes;
static const std::string_view s_scalarCppType;

const std::optional<SchemaOptions> _customSchema;
const SchemaOptions _schemaOptions;
const bool _isIntrospection;
std::string_view _schemaNamespace;
peg::ast _ast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#ifndef INTROSPECTION_H
#define INTROSPECTION_H

#include "graphqlservice/internal/Schema.h"

#include "graphqlservice/introspection/IntrospectionSchema.h"

#include "graphqlservice/internal/Schema.h"

namespace graphql::introspection {

class Schema;
Expand Down
81 changes: 81 additions & 0 deletions include/graphqlservice/introspection/DirectiveObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// WARNING! Do not edit this file manually, your changes will be overwritten.

#pragma once

#ifndef DIRECTIVEOBJECT_H
#define DIRECTIVEOBJECT_H

#include "IntrospectionSchema.h"

namespace graphql::introspection::object {

class Directive
: public service::Object
{
private:
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
service::AwaitableResolver resolveLocations(service::ResolverParams&& params) const;
service::AwaitableResolver resolveArgs(service::ResolverParams&& params) const;

service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;

struct Concept
{
virtual ~Concept() = default;

virtual service::FieldResult<std::string> getName() const = 0;
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
virtual service::FieldResult<std::vector<DirectiveLocation>> getLocations() const = 0;
virtual service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const = 0;
};

template <class T>
struct Model
: Concept
{
Model(std::shared_ptr<T>&& pimpl) noexcept
: _pimpl { std::move(pimpl) }
{
}

service::FieldResult<std::string> getName() const final
{
return { _pimpl->getName() };
}

service::FieldResult<std::optional<std::string>> getDescription() const final
{
return { _pimpl->getDescription() };
}

service::FieldResult<std::vector<DirectiveLocation>> getLocations() const final
{
return { _pimpl->getLocations() };
}

service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const final
{
return { _pimpl->getArgs() };
}

private:
const std::shared_ptr<T> _pimpl;
};

const std::unique_ptr<Concept> _pimpl;

service::TypeNames getTypeNames() const noexcept;
service::ResolverMap getResolvers() const noexcept;

public:
GRAPHQLINTROSPECTION_EXPORT Directive(std::shared_ptr<introspection::Directive> pimpl) noexcept;
GRAPHQLINTROSPECTION_EXPORT ~Directive();
};

} // namespace graphql::introspection::object

#endif // DIRECTIVEOBJECT_H
81 changes: 81 additions & 0 deletions include/graphqlservice/introspection/EnumValueObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// WARNING! Do not edit this file manually, your changes will be overwritten.

#pragma once

#ifndef ENUMVALUEOBJECT_H
#define ENUMVALUEOBJECT_H

#include "IntrospectionSchema.h"

namespace graphql::introspection::object {

class EnumValue
: public service::Object
{
private:
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
service::AwaitableResolver resolveIsDeprecated(service::ResolverParams&& params) const;
service::AwaitableResolver resolveDeprecationReason(service::ResolverParams&& params) const;

service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;

struct Concept
{
virtual ~Concept() = default;

virtual service::FieldResult<std::string> getName() const = 0;
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
virtual service::FieldResult<bool> getIsDeprecated() const = 0;
virtual service::FieldResult<std::optional<std::string>> getDeprecationReason() const = 0;
};

template <class T>
struct Model
: Concept
{
Model(std::shared_ptr<T>&& pimpl) noexcept
: _pimpl { std::move(pimpl) }
{
}

service::FieldResult<std::string> getName() const final
{
return { _pimpl->getName() };
}

service::FieldResult<std::optional<std::string>> getDescription() const final
{
return { _pimpl->getDescription() };
}

service::FieldResult<bool> getIsDeprecated() const final
{
return { _pimpl->getIsDeprecated() };
}

service::FieldResult<std::optional<std::string>> getDeprecationReason() const final
{
return { _pimpl->getDeprecationReason() };
}

private:
const std::shared_ptr<T> _pimpl;
};

const std::unique_ptr<Concept> _pimpl;

service::TypeNames getTypeNames() const noexcept;
service::ResolverMap getResolvers() const noexcept;

public:
GRAPHQLINTROSPECTION_EXPORT EnumValue(std::shared_ptr<introspection::EnumValue> pimpl) noexcept;
GRAPHQLINTROSPECTION_EXPORT ~EnumValue();
};

} // namespace graphql::introspection::object

#endif // ENUMVALUEOBJECT_H
95 changes: 95 additions & 0 deletions include/graphqlservice/introspection/FieldObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// WARNING! Do not edit this file manually, your changes will be overwritten.

#pragma once

#ifndef FIELDOBJECT_H
#define FIELDOBJECT_H

#include "IntrospectionSchema.h"

namespace graphql::introspection::object {

class Field
: public service::Object
{
private:
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
service::AwaitableResolver resolveArgs(service::ResolverParams&& params) const;
service::AwaitableResolver resolveType(service::ResolverParams&& params) const;
service::AwaitableResolver resolveIsDeprecated(service::ResolverParams&& params) const;
service::AwaitableResolver resolveDeprecationReason(service::ResolverParams&& params) const;

service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;

struct Concept
{
virtual ~Concept() = default;

virtual service::FieldResult<std::string> getName() const = 0;
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
virtual service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const = 0;
virtual service::FieldResult<std::shared_ptr<Type>> getType() const = 0;
virtual service::FieldResult<bool> getIsDeprecated() const = 0;
virtual service::FieldResult<std::optional<std::string>> getDeprecationReason() const = 0;
};

template <class T>
struct Model
: Concept
{
Model(std::shared_ptr<T>&& pimpl) noexcept
: _pimpl { std::move(pimpl) }
{
}

service::FieldResult<std::string> getName() const final
{
return { _pimpl->getName() };
}

service::FieldResult<std::optional<std::string>> getDescription() const final
{
return { _pimpl->getDescription() };
}

service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const final
{
return { _pimpl->getArgs() };
}

service::FieldResult<std::shared_ptr<Type>> getType() const final
{
return { _pimpl->getType() };
}

service::FieldResult<bool> getIsDeprecated() const final
{
return { _pimpl->getIsDeprecated() };
}

service::FieldResult<std::optional<std::string>> getDeprecationReason() const final
{
return { _pimpl->getDeprecationReason() };
}

private:
const std::shared_ptr<T> _pimpl;
};

const std::unique_ptr<Concept> _pimpl;

service::TypeNames getTypeNames() const noexcept;
service::ResolverMap getResolvers() const noexcept;

public:
GRAPHQLINTROSPECTION_EXPORT Field(std::shared_ptr<introspection::Field> pimpl) noexcept;
GRAPHQLINTROSPECTION_EXPORT ~Field();
};

} // namespace graphql::introspection::object

#endif // FIELDOBJECT_H
Loading