Skip to content

Commit

Permalink
Merge branch 'development' into improve/state-query-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae authored Feb 26, 2021
2 parents 190777b + c374c8a commit 2a2b39f
Show file tree
Hide file tree
Showing 38 changed files with 1,016 additions and 131 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/deploy_gh_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy gh pages
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
submodules: recursive
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm install -g @2fd/graphdoc
- name: Build
run: graphdoc -s schema.graphql -o doc
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc
3 changes: 3 additions & 0 deletions NineChronicles.Headless.Tests/GraphQLTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GraphQL;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless.Tests
{
Expand All @@ -23,6 +24,8 @@ public static Task<ExecutionResult> ExecuteQueryAsync<TObjectGraphType>(
services.AddSingleton(standaloneContext);
}

services.AddLibplanetExplorer<NCAction>();

var serviceProvider = services.BuildServiceProvider();
return ExecuteQueryAsync<TObjectGraphType>(
serviceProvider,
Expand Down
2 changes: 2 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Microsoft.Extensions.DependencyInjection;
using Nekoyume.Model.State;
using Nekoyume.TableData;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless.Tests.GraphTypes
{
Expand Down Expand Up @@ -96,6 +97,7 @@ public GraphQLTestBase(ITestOutputHelper output)
services.AddSingleton(StandaloneContextFx);
services.AddSingleton<IConfiguration>(configuration);
services.AddGraphTypes();
services.AddLibplanetExplorer<NCAction>();
services.AddSingleton<StateQuery>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
Schema = new StandaloneSchema(serviceProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public async Task GetTx()
timestamp
updatedAddresses
actions {{
plainValue
inspection
}}
}}
}}";
Expand Down Expand Up @@ -576,7 +576,7 @@ public async Task GetTx()
var plainValue = tx["actions"]
.As<List<object>>()
.First()
.As<Dictionary<string, object>>()["plainValue"];
.As<Dictionary<string, object>>()["inspection"];
Assert.Equal(transaction.Actions.First().PlainValue.Inspection, plainValue);
}

Expand Down
23 changes: 23 additions & 0 deletions NineChronicles.Headless/BlockChainContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Libplanet.Action;
using Libplanet.Blockchain;
using Libplanet.Explorer.Interfaces;
using Libplanet.Store;
using Nekoyume.Action;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless
{
public class BlockChainContext : IBlockChainContext<NCAction>
{
private readonly StandaloneContext _standaloneContext;

public BlockChainContext(StandaloneContext standaloneContext)
{
_standaloneContext = standaloneContext;
}

public bool Preloaded => _standaloneContext.NodeStatus.PreloadEnded;
public BlockChain<PolymorphicAction<ActionBase>> BlockChain => _standaloneContext.BlockChain;
public IStore Store => _standaloneContext.Store;
}
}
16 changes: 16 additions & 0 deletions NineChronicles.Headless/GraphQLBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using GraphQL.Server;
using Libplanet.Action;

namespace NineChronicles.Headless
{
public static class GraphQLBuilderExtensions
{
public static IGraphQLBuilder AddLibplanetExplorer<T>(this IGraphQLBuilder builder)
where T : IAction, new()
{
builder.Services.AddLibplanetExplorer<T>();

return builder;
}
}
}
9 changes: 6 additions & 3 deletions NineChronicles.Headless/GraphQLService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using GraphQL.Server;
using Microsoft.AspNetCore.Builder;
Expand All @@ -9,6 +10,7 @@
using NineChronicles.Headless.Middleware;
using NineChronicles.Headless.Properties;
using Serilog;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless
{
Expand Down Expand Up @@ -91,15 +93,16 @@ public void ConfigureServices(IServiceCollection services)
options.EnableMetrics = true;
options.UnhandledExceptionDelegate = context =>
{
Log.Error(
context.Exception,
context.ErrorMessage);
Console.Error.WriteLine(context.Exception.ToString());
Console.Error.WriteLine(context.ErrorMessage);
};
})
.AddSystemTextJson()
.AddWebSockets()
.AddDataLoader()
.AddGraphTypes(typeof(StandaloneSchema))
.AddLibplanetExplorer<NCAction>()
.AddUserContextBuilder<UserContextBuilder>()
.AddGraphQLAuthorization(
options => options.AddPolicy(
LocalPolicyKey,
Expand Down
37 changes: 37 additions & 0 deletions NineChronicles.Headless/GraphQLServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
using System.Linq;
using System.Reflection;
using GraphQL.Types;
using Libplanet.Action;
using Libplanet.Explorer.GraphTypes;
using Libplanet.Explorer.Interfaces;
using Libplanet.Explorer.Queries;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless
{
Expand All @@ -24,5 +29,37 @@ public static IServiceCollection AddGraphTypes(this IServiceCollection services)

return services;
}

public static IServiceCollection AddLibplanetScalarTypes(this IServiceCollection services)
{
services.TryAddSingleton<AddressType>();
services.TryAddSingleton<ByteStringType>();

return services;
}

public static IServiceCollection AddBlockChainContext(this IServiceCollection services)
{
services.TryAddSingleton<IBlockChainContext<NCAction>, BlockChainContext>();

return services;
}

public static IServiceCollection AddLibplanetExplorer<T>(this IServiceCollection services)
where T : IAction, new()
{
services.AddLibplanetScalarTypes();
services.AddBlockChainContext();

services.TryAddSingleton<ActionType<T>>();
services.TryAddSingleton<BlockType<T>>();
services.TryAddSingleton<TransactionType<T>>();
services.TryAddSingleton<NodeStateType<T>>();
services.TryAddSingleton<BlockQuery<T>>();
services.TryAddSingleton<TransactionQuery<T>>();
services.TryAddSingleton<Query<T>>();

return services;
}
}
}
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/ActionMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Serilog;
using System;
using System.Collections.Generic;
using Libplanet.Explorer.GraphTypes;
using Libplanet.Tx;
using NineChroniclesActionType = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

Expand Down
17 changes: 0 additions & 17 deletions NineChronicles.Headless/GraphTypes/ActionType.cs

This file was deleted.

56 changes: 0 additions & 56 deletions NineChronicles.Headless/GraphTypes/AddressType.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Bencodex;
using Libplanet.Net;
using GraphQL.Types;
using Libplanet.Explorer.GraphTypes;

namespace NineChronicles.Headless.GraphTypes
{
Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/BlockHeaderType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Libplanet;
using Libplanet.Action;
using Libplanet.Blocks;
using Libplanet.Explorer.GraphTypes;

namespace NineChronicles.Headless.GraphTypes
{
Expand Down
53 changes: 0 additions & 53 deletions NineChronicles.Headless/GraphTypes/ByteStringType.cs

This file was deleted.

1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/KeyStoreMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GraphQL.Types;
using Libplanet;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;
using Libplanet.KeyStore;

namespace NineChronicles.Headless.GraphTypes
Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/KeyStoreType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GraphQL.Types;
using Libplanet;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;
using Libplanet.KeyStore;
using Org.BouncyCastle.Security;

Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/NodeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Libplanet.Action;
using Libplanet.Blockchain;
using Libplanet.Blocks;
using Libplanet.Explorer.GraphTypes;
using Libplanet.Store;
using Libplanet.Tx;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;
Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/PrivateKeyType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GraphQL.Types;
using Libplanet;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;

namespace NineChronicles.Headless.GraphTypes
{
Expand Down
Loading

0 comments on commit 2a2b39f

Please sign in to comment.