Skip to content

Commit

Permalink
Merge pull request #176 from input-output-hk/feat/graphql-int64-support
Browse files Browse the repository at this point in the history
feat: graphql int64 support
  • Loading branch information
rhyslbw authored Feb 9, 2022
2 parents 7a59de5 + de488b1 commit cc15f0c
Show file tree
Hide file tree
Showing 17 changed files with 3,443 additions and 3,082 deletions.
8 changes: 1 addition & 7 deletions packages/cardano-graphql/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,4 @@ config:
strictScalars: true
scalars:
DateTime: string
# It actually seems to be serialized to number in response json
# Suggested solution:
# Fork (and possibly open a PR) this dependency:
# https://github.com/prisma-labs/graphql-request/blob/master/src/index.ts#L440
# Add an option to provide a custom JSON serializer,
# Where we would parse it into bigint, or likely into 'number | bigint'
Int64: bigint
Int64: number | bigint
26 changes: 14 additions & 12 deletions packages/cardano-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@
"test:debug": "DEBUG=true yarn test"
},
"devDependencies": {
"@graphql-codegen/cli": "^2.2.1",
"@graphql-codegen/typescript": "^2.2.4",
"@graphql-codegen/typescript-graphql-request": "^4.1.6",
"@graphql-codegen/typescript-operations": "^2.1.8",
"@graphql-tools/utils": "^8.4.0",
"@graphql-codegen/cli": "~2.5.0",
"@graphql-codegen/typescript": "~2.4.3",
"@graphql-codegen/typescript-graphql-request": "~4.3.4",
"@graphql-codegen/typescript-operations": "~2.2.4",
"@graphql-tools/utils": "~8.6.1",
"npm-run-all": "^4.1.5",
"shx": "^0.3.3"
},
"dependencies": {
"@cardano-graphql/client-ts": "^5.1.0-beta.1",
"@cardano-ogmios/client": "4.1.0",
"@cardano-sdk/core": " 0.2.0",
"@cardano-graphql/client-ts": "~6.1.0",
"@cardano-ogmios/client": "~5.1.0",
"@cardano-sdk/core": "0.2.0",
"class-validator": "^0.13.1",
"graphql": "^15.6.1",
"graphql-request": "^3.5.0",
"reflect-metadata": "^0.1.13",
"type-graphql": "^1.1.1"
"graphql": "~15.6.1",
"graphql-request": "npm:graphql-request-configurable-serializer@4.0.0",
"graphql-tag": "2.12.5",
"json-bigint": "~1.0.0",
"reflect-metadata": "~0.1.13",
"type-graphql": "~1.1.1"
},
"files": [
"dist/*",
Expand Down
7 changes: 4 additions & 3 deletions packages/cardano-graphql/src/Schema/types/Ada.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Block } from './Block';
import { Cardano } from '@cardano-sdk/core';
import { Field, Int, ObjectType } from 'type-graphql';
import { Int64 } from './util';

@ObjectType()
export class CoinSupply {
@Field(() => String)
@Field(() => Int64)
circulating: Cardano.Lovelace;
@Field(() => String)
@Field(() => Int64)
max: Cardano.Lovelace;
@Field(() => String)
@Field(() => Int64)
total: Cardano.Lovelace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const toCoreStakePool = (responseStakePool: GraphqlStakePool): Cardano.StakePool
...poolParameters,
epochRewards: stakePool.epochRewards.map(
({ epochNo, totalRewards, memberROI, operatorFees, epochLength, activeStake }) => ({
activeStake,
activeStake: BigInt(activeStake),
epoch: epochNo,
epochLength,
memberROI,
operatorFees,
totalRewards
operatorFees: BigInt(operatorFees),
totalRewards: BigInt(totalRewards)
})
),
hexId: Cardano.PoolIdHex(stakePool.hexId),
Expand Down
4 changes: 2 additions & 2 deletions packages/cardano-graphql/src/WalletProvider/networkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const networkInfoProvider =
total: BigInt(supply.total)
},
stake: {
active: activeStake,
live: totalLiveStake
active: BigInt(activeStake),
live: BigInt(totalLiveStake)
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ const outputsToCore = (outputs: GraphqlTransaction['outputs']) =>
datum: datumHash ? Cardano.Hash32ByteBase16(datumHash) : undefined,
value: {
assets: new Map(assets?.map(({ asset, quantity }) => [Cardano.AssetId(asset.assetId), BigInt(quantity)])),
coins: coin
coins: BigInt(coin)
}
})
);

const withdrawalsToCore = (withdrawals: GraphqlTransaction['withdrawals']) =>
withdrawals?.map(
(withdrawal): Cardano.Withdrawal => ({
quantity: withdrawal.quantity,
quantity: BigInt(withdrawal.quantity),
stakeAddress: Cardano.RewardAccount(withdrawal.rewardAccount.address)
})
);
Expand Down Expand Up @@ -147,7 +147,7 @@ const certificatesToCore = (certificates: GraphQlCertificates) =>
return {
__typename: Cardano.CertificateType.MIR,
pot: cert.pot as Cardano.MirCertificate['pot'],
quantity: cert.quantity,
quantity: BigInt(cert.quantity),
rewardAccount: Cardano.RewardAccount(cert.rewardAccount.address)
};
case 'PoolRegistrationCertificate': {
Expand Down Expand Up @@ -212,7 +212,7 @@ export const graphqlTransactionsToCore = (
body: {
certificates,
collaterals: tx.collateral ? inputsToCore(tx.collateral, txId) : undefined,
fee: tx.fee,
fee: BigInt(tx.fee),
inputs: inputsToCore(tx.inputs, txId),
mint: mintToCore(tx.mint),
outputs: outputsToCore(tx.outputs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const rewardsHistoryProvider =
const rawRewards = queryRewardAccount?.filter(util.isNotNil) || [];
const rewardsByEpoch = groupBy(
rawRewards.flatMap(({ rewards }): EpochRewards[] =>
rewards.map(({ epochNo, quantity }) => ({ epoch: epochNo, rewards: quantity }))
rewards.map(({ epochNo, quantity }) => ({ epoch: epochNo, rewards: BigInt(quantity) }))
),
({ epoch }) => epoch
);
Expand Down
12 changes: 12 additions & 0 deletions packages/cardano-graphql/src/createSDK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GraphQLClient } from 'graphql-request';
import { RequestInit } from 'graphql-request/dist/types.dom';
import { getSdk } from './sdk';
import { jsonSerializer } from './util';

export const createSDK = (url: string, options?: Omit<RequestInit, 'jsonSerializer'>) => {
const client = new GraphQLClient(url, {
...options,
jsonSerializer
});
return getSdk(client);
};
2 changes: 2 additions & 0 deletions packages/cardano-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { WalletProvider, StakePoolSearchProvider } from '@cardano-sdk/core';
export * from './StakePoolSearchProvider';
export * from './WalletProvider';
export * from './createSDK';
// Do not export this. Using core types elsewhere in the sdk.
// export * as Schema from './Schema';
Loading

0 comments on commit cc15f0c

Please sign in to comment.