Skip to content

Commit

Permalink
Return only offer ids for trades
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-wasp committed Jun 4, 2019
1 parent d46ae58 commit 424f557
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/model/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Trade implements ITrade {
this.baseAccount = data.baseAccount;
this.baseAmount = data.baseAmount;
this.baseAsset = data.baseAsset;
this.counterOffer = data.baseOffer;
this.counterOffer = data.counterOffer;
this.counterAccount = data.counterAccount;
this.counterAsset = data.counterAsset;
this.baseIsSeller = data.baseIsSeller;
Expand Down
21 changes: 2 additions & 19 deletions src/schema/resolvers/trades.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import { getRepository } from "typeorm";
import { IHorizonTradeData } from "../../datasource/types";
import { IApolloContext } from "../../graphql_server";
import { Trade } from "../../model";
import { TradeFactory } from "../../model/factories";
import { Offer } from "../../orm/entities";
import { createBatchResolver, idOnlyRequested, makeConnection } from "./util";
import { makeConnection } from "./util";

import * as resolvers from "./shared";

const offerResolver = createBatchResolver<any, Offer[]>(async (source: any, args: any, context: any, info: any) => {
const ids: string[] = source.map((s: any) => s[info.fieldName]);

if (idOnlyRequested(info)) {
return ids.map(id => (id ? { id } : null));
}

const offers = await getRepository(Offer).findByIds(ids);

return ids.map(id => offers.find(o => o.id === id) || null);
});

export default {
Trade: {
baseAsset: resolvers.asset,
counterAsset: resolvers.asset,
baseAccount: resolvers.account,
counterAccount: resolvers.account,
offer: offerResolver,
baseOffer: offerResolver,
counterOffer: offerResolver
counterAccount: resolvers.account
},
Query: {
trades: async (root: any, args: any, ctx: IApolloContext, info: any) => {
Expand Down
6 changes: 3 additions & 3 deletions src/schema/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export const typeDefs = gql`
"When the ledger with this trade was closed"
ledgerCloseTime: DateTime!
"The sell offer"
offer: Offer
baseOffer: Offer
offer: OfferID
baseOffer: OfferID
"Base party of this trade"
baseAccount: Account
"Amount of \`baseAsset\` that was moved from \`baseAccount\` to \`counterAccount\`"
baseAmount: Float!
baseAsset: Asset!
counterOffer: Offer
counterOffer: OfferID
"Counter party of this trade"
counterAccount: Account
"Amount of \`counterAsset\` that was moved from \`counterAccount\` to \`baseAccount\`"
Expand Down

0 comments on commit 424f557

Please sign in to comment.