-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from wravery/schema-stitch
fix: #323
- Loading branch information
Showing
16 changed files
with
909 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
cmake_minimum_required(VERSION 3.28) | ||
|
||
add_library(stitchedschema STATIC | ||
StitchedSchema.cpp) | ||
target_link_libraries(stitchedschema PUBLIC star_wars todaygraphql) | ||
target_include_directories(stitchedschema INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
add_executable(stitched sample.cpp) | ||
target_link_libraries(stitched PRIVATE | ||
stitchedschema | ||
graphqljson) | ||
|
||
if(WIN32 AND BUILD_SHARED_LIBS) | ||
add_custom_command(OUTPUT copied_sample_dlls | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
$<TARGET_FILE:graphqlservice> | ||
$<TARGET_FILE:graphqljson> | ||
$<TARGET_FILE:graphqlpeg> | ||
$<TARGET_FILE:graphqlresponse> | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
COMMAND ${CMAKE_COMMAND} -E touch copied_sample_dlls | ||
DEPENDS | ||
graphqlservice | ||
graphqljson | ||
graphqlpeg | ||
graphqlresponse) | ||
|
||
add_custom_target(copy_stitched_sample_dlls DEPENDS copied_sample_dlls) | ||
|
||
add_dependencies(stitched copy_stitched_sample_dlls) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "StitchedSchema.h" | ||
|
||
#include "StarWarsData.h" | ||
#include "StarWarsSchema.h" | ||
|
||
import GraphQL.Today.Mock; | ||
|
||
namespace graphql::stitched { | ||
|
||
std::shared_ptr<const service::Request> GetService() | ||
{ | ||
return star_wars::GetService()->stitch(today::mock_service()->service); | ||
} | ||
|
||
} // namespace graphql::stitched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#ifndef STITCHEDSCHEMA_H | ||
#define STITCHEDSCHEMA_H | ||
|
||
#include "graphqlservice/GraphQLService.h" | ||
|
||
#include "StarWarsSharedTypes.h" | ||
#include "TodaySharedTypes.h" | ||
|
||
namespace graphql::stitched { | ||
|
||
std::shared_ptr<const service::Request> GetService(); | ||
|
||
} // namespace graphql::stitched | ||
|
||
#endif // STITCHEDSCHEMA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "StitchedSchema.h" | ||
|
||
#include "graphqlservice/JSONResponse.h" | ||
|
||
#include <cstdio> | ||
#include <iostream> | ||
#include <iterator> | ||
#include <stdexcept> | ||
|
||
using namespace graphql; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
auto service = stitched::GetService(); | ||
|
||
std::cout << "Created the service..." << std::endl; | ||
|
||
try | ||
{ | ||
peg::ast query; | ||
|
||
if (argc > 1) | ||
{ | ||
query = peg::parseFile(argv[1]); | ||
} | ||
else | ||
{ | ||
std::istream_iterator<char> start { std::cin >> std::noskipws }, end {}; | ||
std::string input { start, end }; | ||
|
||
query = peg::parseString(std::move(input)); | ||
} | ||
|
||
if (!query.root) | ||
{ | ||
std::cerr << "Unknown error!" << std::endl; | ||
std::cerr << std::endl; | ||
return 1; | ||
} | ||
|
||
std::cout << "Executing query..." << std::endl; | ||
|
||
std::cout << response::toJSON( | ||
service->resolve({ query, ((argc > 2) ? argv[2] : "") }).get()) | ||
<< std::endl; | ||
} | ||
catch (const std::runtime_error& ex) | ||
{ | ||
std::cerr << ex.what() << std::endl; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.