TraxBroadcast Attribute

The [TraxBroadcast] attribute opts a train into real-time GraphQL subscription events. Only trains decorated with this attribute will have their lifecycle transitions (onTrainStarted, onTrainCompleted, onTrainFailed, onTrainCancelled) published to WebSocket subscribers.

Trains without this attribute run normally but are silently skipped by both the local GraphQLSubscriptionHook and the remote GraphQLTrainEventHandler (used with UseBroadcaster()).

Definition

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class TraxBroadcastAttribute : Attribute { }

A simple marker attribute with no properties — just opt-in/opt-out.

Example

[TraxQuery(Description = "Looks up a player profile")]
[TraxBroadcast]
public class LookupPlayerTrain : ServiceTrain<LookupPlayerInput, LookupPlayerOutput>, ILookupPlayerTrain
{
    protected override async Task<Either<Exception, LookupPlayerOutput>> RunInternal(LookupPlayerInput input) =>
        Activate(input).Chain<FetchPlayerJunction>().Resolve();
}

When LookupPlayerTrain completes, subscribers to onTrainCompleted will receive a TrainLifecycleEvent with the train name, state, and timestamp.

Combined with TraxQuery / TraxMutation

[TraxBroadcast] and [TraxQuery]/[TraxMutation] are independent. You can use any combination:

AttributesGraphQL fields generated?Subscription events?
NeitherNoNo
[TraxQuery] or [TraxMutation] onlyYesNo
[TraxBroadcast] onlyNoYes
[TraxMutation] + [TraxBroadcast]YesYes

Discovery

The [TraxBroadcast] metadata is available through ITrainDiscoveryService. Each TrainRegistration includes IsBroadcastEnabled. The trains GraphQL query also exposes this field.

Package

dotnet add package Trax.Effect

The attribute is defined in Trax.Effect so train classes can use it without depending on Trax.Api.GraphQL.