Skip to content

Commit

Permalink
Separate GraphQL type and record
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed Aug 13, 2024
1 parent 120c990 commit 18372e5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion NineChronicles.Headless/BlockChainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public BlockChainContext(StandaloneContext standaloneContext)
_standaloneContext = standaloneContext;
}

public bool Preloaded => _standaloneContext.NodeStatus.PreloadEnded;
public bool Preloaded => _standaloneContext.PreloadEnded;
public BlockChain BlockChain => _standaloneContext.BlockChain;
public IStore Store => _standaloneContext.Store;
public Swarm Swarm => _standaloneContext.Swarm;
Expand Down
12 changes: 5 additions & 7 deletions NineChronicles.Headless/GraphTypes/NodeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@

namespace NineChronicles.Headless.GraphTypes
{
public class NodeStatusType : ObjectGraphType<NodeStatusType>
public class NodeStatusType : ObjectGraphType<NodeStatusType.NodeStatus>
{
#pragma warning disable SA1313
public record NodeStatus(bool BootstrapEnded, bool PreloadEnded, bool IsMining);
#pragma warning restore SA1313

private static readonly string _productVersion =
Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";

private static readonly string _informationalVersion =
Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? "Unknown";

public bool BootstrapEnded { get; set; }

public bool PreloadEnded { get; set; }

public bool IsMining { get; set; }

public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChainRepository)
{
Field<NonNullGraphType<BooleanGraphType>>(
Expand Down
4 changes: 2 additions & 2 deletions NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public StandaloneSubscription(StandaloneContext standaloneContext, IConfiguratio
{
Name = "nodeStatus",
Type = typeof(NodeStatusType),
Resolver = new FuncFieldResolver<NodeStatusType>(context => (context.Source as NodeStatusType)!),
Subscriber = new EventStreamResolver<NodeStatusType>(context => StandaloneContext.NodeStatusSubject.AsObservable()),
Resolver = new FuncFieldResolver<NodeStatusType.NodeStatus>(context => (context.Source as NodeStatusType.NodeStatus)!),
Subscriber = new EventStreamResolver<NodeStatusType.NodeStatus>(context => StandaloneContext.NodeStatusSubject.AsObservable()),
});
AddField(new EventStreamFieldType
{
Expand Down
10 changes: 3 additions & 7 deletions NineChronicles.Headless/StandaloneContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IKeyStore KeyStore
public bool BootstrapEnded { get; set; }
public bool PreloadEnded { get; set; }
public bool IsMining { get; set; }
public ReplaySubject<NodeStatusType> NodeStatusSubject { get; } = new(1);
public ReplaySubject<NodeStatusType.NodeStatus> NodeStatusSubject { get; } = new(1);
public ReplaySubject<BlockSyncState> PreloadStateSubject { get; } = new(5);

public Subject<DifferentAppProtocolVersionEncounter> DifferentAppProtocolVersionEncounterSubject { get; } =
Expand All @@ -51,12 +51,8 @@ public IKeyStore KeyStore
AgentAddresses
{ get; } = new ConcurrentDictionary<Address, ReplaySubject<string>>();

public NodeStatusType NodeStatus => new(this)
{
BootstrapEnded = BootstrapEnded,
PreloadEnded = PreloadEnded,
IsMining = IsMining,
};
public NodeStatusType.NodeStatus NodeStatus => new(
BootstrapEnded: BootstrapEnded, PreloadEnded: PreloadEnded, IsMining: IsMining);

public IStore Store
{
Expand Down

0 comments on commit 18372e5

Please sign in to comment.