-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
NineChronicles.Headless.Executable/Commands/GraphQLCommand.cs
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,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using GraphQL.Server; | ||
using GraphQL.Utilities; | ||
using Lib9c.Renderers; | ||
using Libplanet.Action.State; | ||
using Libplanet.Blockchain; | ||
using Libplanet.Blockchain.Policies; | ||
using Libplanet.Crypto; | ||
using Libplanet.Headless.Hosting; | ||
using Libplanet.Net; | ||
using Libplanet.Store; | ||
using Libplanet.Store.Trie; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Nekoyume; | ||
using Nekoyume.Action.Loader; | ||
using NineChronicles.Headless.GraphTypes; | ||
|
||
namespace NineChronicles.Headless.Executable.Commands; | ||
|
||
public class GraphQLCommand | ||
{ | ||
[Cocona.Command] | ||
public void Schema() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
|
||
serviceCollection.AddSingleton<StateMemoryCache>(); | ||
serviceCollection.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()); | ||
serviceCollection.AddSingleton<BlockRenderer>(); | ||
serviceCollection.AddSingleton<ActionRenderer>(); | ||
serviceCollection.AddSingleton<ExceptionRenderer>(); | ||
serviceCollection.AddSingleton<NodeStatusRenderer>(); | ||
serviceCollection.AddSingleton<IBlockChainStates>( | ||
new BlockChainStates( | ||
new MemoryStore(), | ||
new TrieStateStore(new MemoryKeyValueStore()))); | ||
serviceCollection.AddSingleton<string>("STRING"); // Invalid usage but not care in this case. | ||
serviceCollection.AddSingleton<RpcContext>(); | ||
serviceCollection.AddSingleton<ActionEvaluationPublisher>(services => new ActionEvaluationPublisher( | ||
services.GetRequiredService<BlockRenderer>(), | ||
services.GetRequiredService<ActionRenderer>(), | ||
services.GetRequiredService<ExceptionRenderer>(), | ||
services.GetRequiredService<NodeStatusRenderer>(), | ||
services.GetRequiredService<IBlockChainStates>(), | ||
"host", | ||
0, | ||
services.GetRequiredService<RpcContext>(), | ||
services.GetRequiredService<StateMemoryCache>() | ||
)); | ||
serviceCollection.AddSingleton(new NineChroniclesNodeService( | ||
new PrivateKey(), | ||
new LibplanetNodeServiceProperties | ||
{ | ||
SwarmPrivateKey = new PrivateKey(), | ||
Host = "localhost", | ||
IceServers = Array.Empty<IceServer>(), | ||
StorePath = Path.GetRandomFileName(), | ||
GenesisBlock = BlockChain.ProposeGenesisBlock(), | ||
}, | ||
new BlockPolicy(), | ||
Planet.Heimdall, | ||
new NCActionLoader())); | ||
serviceCollection.AddSingleton<StandaloneContext>(services => new StandaloneContext | ||
{ | ||
NineChroniclesNodeService = services.GetRequiredService<NineChroniclesNodeService>(), | ||
}); | ||
|
||
serviceCollection.AddGraphQL() | ||
.AddLibplanetExplorer() | ||
.AddGraphTypes(typeof(StandaloneSchema)); | ||
|
||
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); | ||
var schema = new StandaloneSchema(serviceProvider); | ||
var printer = new SchemaPrinter(schema); | ||
|
||
Console.WriteLine(printer.Print()); | ||
} | ||
} |
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