Skip to content
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

Introduce graphql schema command #2575

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Introduce graphql schema command
  • Loading branch information
moreal committed Sep 10, 2024
commit f116d0dc4c6235881d2a12711b65e33a4ea933a1
81 changes: 81 additions & 0 deletions NineChronicles.Headless.Executable/Commands/GraphQLCommand.cs
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());
}
}
1 change: 1 addition & 0 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace NineChronicles.Headless.Executable
[HasSubCommands(typeof(MarketCommand), "market")]
[HasSubCommands(typeof(GenesisCommand), "genesis")]
[HasSubCommands(typeof(ReplayCommand), "replay")]
[HasSubCommands(typeof(GraphQLCommand), "graphql")]
public class Program : CoconaLiteConsoleAppBase
{
static async Task Main(string[] args)
Expand Down
Loading