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

remove AllEvent from gql eventbus + limit to 1 event max #2327

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 30 additions & 29 deletions gateway/graphql/modelext.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,15 @@ func busEventFromProto(events ...*types.BusEvent) []*BusEvent {
// in the future though
continue
}
et, err := eventTypeFromProto(e.Type)
if err != nil {
// @TODO for now just skip unmapped event types, probably better to handle some kind of error
// in the future though
continue
}
be := BusEvent{
EventID: e.ID,
Type: eventTypeFromProto(e.Type),
Type: et,
Event: evt,
}
r = append(r, &be)
Expand Down Expand Up @@ -1387,8 +1393,6 @@ func eventTypeToProto(btypes ...BusEventType) []types.BusEventType {
r := make([]types.BusEventType, 0, len(btypes))
for _, t := range btypes {
switch t {
case BusEventTypeAll:
r = append(r, types.BusEventType_BUS_EVENT_TYPE_ALL)
case BusEventTypeTimeUpdate:
r = append(r, types.BusEventType_BUS_EVENT_TYPE_TIME_UPDATE)
case BusEventTypeTransferResponses:
Expand Down Expand Up @@ -1436,53 +1440,50 @@ func eventTypeToProto(btypes ...BusEventType) []types.BusEventType {
return r
}

func eventTypeFromProto(t types.BusEventType) BusEventType {
func eventTypeFromProto(t types.BusEventType) (BusEventType, error) {
switch t {
case types.BusEventType_BUS_EVENT_TYPE_ALL:
edd marked this conversation as resolved.
Show resolved Hide resolved
return BusEventTypeAll
case types.BusEventType_BUS_EVENT_TYPE_TIME_UPDATE:
return BusEventTypeTimeUpdate
return BusEventTypeTimeUpdate, nil
case types.BusEventType_BUS_EVENT_TYPE_TRANSFER_RESPONSES:
return BusEventTypeTransferResponses
return BusEventTypeTransferResponses, nil
case types.BusEventType_BUS_EVENT_TYPE_POSITION_RESOLUTION:
return BusEventTypePositionResolution
return BusEventTypePositionResolution, nil
case types.BusEventType_BUS_EVENT_TYPE_ORDER:
return BusEventTypeOrder
return BusEventTypeOrder, nil
case types.BusEventType_BUS_EVENT_TYPE_ACCOUNT:
return BusEventTypeAccount
return BusEventTypeAccount, nil
case types.BusEventType_BUS_EVENT_TYPE_PARTY:
return BusEventTypeParty
return BusEventTypeParty, nil
case types.BusEventType_BUS_EVENT_TYPE_TRADE:
return BusEventTypeTrade
return BusEventTypeTrade, nil
case types.BusEventType_BUS_EVENT_TYPE_MARGIN_LEVELS:
return BusEventTypeMarginLevels
return BusEventTypeMarginLevels, nil
case types.BusEventType_BUS_EVENT_TYPE_PROPOSAL:
return BusEventTypeProposal
return BusEventTypeProposal, nil
case types.BusEventType_BUS_EVENT_TYPE_VOTE:
return BusEventTypeVote
return BusEventTypeVote, nil
case types.BusEventType_BUS_EVENT_TYPE_MARKET_DATA:
return BusEventTypeMarketData
return BusEventTypeMarketData, nil
case types.BusEventType_BUS_EVENT_TYPE_NODE_SIGNATURE:
return BusEventTypeNodeSignature
return BusEventTypeNodeSignature, nil
case types.BusEventType_BUS_EVENT_TYPE_LOSS_SOCIALIZATION:
return BusEventTypeLossSocialization
return BusEventTypeLossSocialization, nil
case types.BusEventType_BUS_EVENT_TYPE_SETTLE_POSITION:
return BusEventTypeSettlePosition
return BusEventTypeSettlePosition, nil
case types.BusEventType_BUS_EVENT_TYPE_SETTLE_DISTRESSED:
return BusEventTypeSettleDistressed
return BusEventTypeSettleDistressed, nil
case types.BusEventType_BUS_EVENT_TYPE_MARKET_CREATED:
return BusEventTypeMarketCreated
return BusEventTypeMarketCreated, nil
case types.BusEventType_BUS_EVENT_TYPE_ASSET:
return BusEventTypeAsset
return BusEventTypeAsset, nil
case types.BusEventType_BUS_EVENT_TYPE_MARKET_TICK:
return BusEventTypeMarketTick
return BusEventTypeMarketTick, nil
case types.BusEventType_BUS_EVENT_TYPE_MARKET:
return BusEventTypeMarket
return BusEventTypeMarket, nil
case types.BusEventType_BUS_EVENT_TYPE_AUCTION:
return BusEventTypeAuction
return BusEventTypeAuction, nil
case types.BusEventType_BUS_EVENT_TYPE_RISK_FACTOR:
return BusEventTypeRiskFactor
return BusEventTypeRiskFactor, nil
}
// @TODO this should be an error, but no event should ever be returned with this value anyway
return BusEventTypeAll
return "", errors.New("unsupported proto event type")
}
5 changes: 1 addition & 4 deletions gateway/graphql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,12 @@ func (r *mySubscriptionResolver) Votes(ctx context.Context, proposalID *string,
}

func (r *mySubscriptionResolver) BusEvents(ctx context.Context, types []BusEventType, marketID, partyID *string) (<-chan []*BusEvent, error) {
if len(types) > 1 {
return nil, errors.New("busEvents subscription support streaming 1 event at a time for now")
}
if len(types) <= 0 {
return nil, errors.New("busEvents subscription requires 1 event type")
}
t := eventTypeToProto(types...)
req := protoapi.ObserveEventsRequest{
Type: t,
Expand Down
2 changes: 0 additions & 2 deletions gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2044,8 +2044,6 @@ type AuctionEvent {
}

enum BusEventType {
"all events"
All
"event type indicating TimeUpdate"
TimeUpdate
"transfer response event"
Expand Down