Skip to content

Commit

Permalink
feat(graph): update schema to represent correct structure in preparat…
Browse files Browse the repository at this point in the history
…ion of transition to kadindexer.io/graphql
  • Loading branch information
alber70g committed Jan 10, 2025
1 parent 5517c5d commit 1afb5ba
Show file tree
Hide file tree
Showing 45 changed files with 285 additions and 201 deletions.
74 changes: 74 additions & 0 deletions .changeset/green-scissors-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
'@kadena/graph': major
---

BREAKING CHANGES: we've introduced a number of breaking changes to prepare to
transition to kadindexer.io/graphql

Changes and their resolution

## Breaking Changes

### Without alternative

- ✖ Field `Block.target` changed type from `Decimal!` to `String!`
- ✖ Field `Block.weight` changed type from `Decimal!` to `String!`
- ✖ Field `incrementedId` was removed from object type `Event`
- ✖ Field `parameterText` was removed from object type `Event`
- ✖ Type `MinerKey` was removed
- ✖ Type `PositiveFloat` was removed
- ✖ Field `metadata` was removed from object type `TransactionResult`

### With Alternatives

- ✖ Field `Query.fungibleChainAccount` changed type from `FungibleChainAccount`
to [FungibleChainAccount!]
- ✖ Argument `chainId`: String! was removed from field
`Query.fungibleChainAccount`
- `chainId` was replaced by `chainIds: [String!]` with a default value
- ✖ Field `blockHash` was removed from object type `Transfer`
- can be retrieved via `block.hash`
- ✖ Field `chainId` was removed from object type `Transfer`
- can be retrieved via `block.chainId`
- ✖ Field `height` was removed from object type `Transfer`
- can be retrieved via `block.height`

## Improvements

These shouldn't affect how it's being used. We changed the value for

- `chainIds` to include all chains as the default value,
- `fungibleName` to include `coin` as the default value

and represented as such by GraphQL instead of a optional argument with a hidden
default value.

- ⚠ Default value
`[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]` was
added to argument `chainIds` on field `Query.blocksFromDepth`
- ⚠ Default value
`[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]` was
added to argument `chainIds` on field `Query.blocksFromHeight`
- ⚠ Default value
`[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]` was
added to argument `chainIds` on field `Query.completedBlockHeights`
- ⚠ Default value `coin` was added to argument fungibleName on field
`Query.fungibleAccount`
- ⚠ Argument `chainIds: [String!]!` (with default value) added to field
`Query.fungibleChainAccount`
- ⚠ Default value `coin` was added to argument fungibleName on field
`Query.fungibleChainAccount`
- ⚠ Default value
`[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]` was
added to argument `chainIds` on field `Subscription.newBlocks`
- ⚠ Default value
`[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]` was
added to argument `chainIds` on field `Subscription.newBlocksFromDepth`

## Other Changes

- ✔ Directive oneOf was added
- ✔ Directive deprecated was added to field IGuard.keys
- ✔ Directive deprecated was added to field IGuard.predicate
- ✔ Type for argument chainIds on field Subscription.newBlocksFromDepth changed
from [String!]! to [String!]
21 changes: 21 additions & 0 deletions .graphqlrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// .graphqlrc.ts or graphql.config.ts
export default {
projects: {
'graph-client': {
schema: ['./packages/apps/graph/generated-schema.graphql'],
documents: ['./packages/apps/graph-client/src/**/*.graph.ts'],
},
explorer: {
schema: ['./packages/apps/graph/generated-schema.graphql'],
documents: ['./packages/apps/explorer/src/**/*.graph.ts'],
},
'proof-of-us': {
schema: ['./packages/apps/graph/generated-schema.graphql'],
documents: ['./packages/apps/proof-of-us/src/**/*.graph.ts'],
},
'rwa-demo': {
schema: ['./packages/apps/graph/generated-schema.graphql'],
documents: ['./packages/apps/rwa-demo/src/**/*.graph.ts'],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ export const accountTransfers: DocumentNode = gql`
}
edges {
node {
requestKey
blockHash
transaction {
cmd {
meta {
chainId
}
}
hash
}
block {
hash
height
}
amount
chainId
receiverAccount
senderAccount
height
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const loadingData: BlockQuery = {
},
payloadHash: '',
powHash: '',
target: 0,
weight: 0,
target: '',
weight: '',
transactions: {
totalCount: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const loadingTransactionData: TransactionRequestKeyQuery = {
transactionId: 1,
logs: '1',
gas: 262,
metadata: null,
continuation: null,
__typename: 'TransactionResult',
events: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export const TransactionResultComponent: React.FC<{
},
{
key: 'Counterpart',
value: getCrosschainTransfer(transaction).requestKey,
link: `/transaction/${getCrosschainTransfer(transaction).requestKey}`,
value: getCrosschainTransfer(transaction).transaction?.hash || '',
link: `/transaction/${getCrosschainTransfer(transaction).transaction?.hash || ''}`,
},
]}
/>
Expand Down Expand Up @@ -124,7 +124,6 @@ export const TransactionResultComponent: React.FC<{
/>
),
},
{ key: 'Metadata', value: transaction.metadata },
]}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const transactionRequestKey: DocumentNode = gql`
hash
creationTime
}
metadata
continuation
events {
edges {
Expand All @@ -71,7 +70,9 @@ export const transactionRequestKey: DocumentNode = gql`
edges {
node {
crossChainTransfer {
requestKey
transaction {
hash
}
senderAccount
receiverAccount
}
Expand Down
11 changes: 10 additions & 1 deletion packages/apps/explorer/src/services/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ export function formatNumberWithUnit(number: number): string {
}

export function formatStatisticsData(
networkInfo: NetworkInfo | null | undefined,
networkInfo:
| Pick<
NetworkInfo,
| 'networkHashRate'
| 'totalDifficulty'
| 'transactionCount'
| 'coinsInCirculation'
>
| null
| undefined,
): { label: string; value: string }[] {
if (!networkInfo) {
return [
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph-client/apollo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
client: {
service: {
name: 'graph',
localSchemaFile: __dirname + '/../graph/generated-schema.graphql',
localSchemaFile: `${__dirname}/../graph/generated-schema.graphql`,
},
includes: ['src/**/*.ts', 'src/**/*.tsx'],
excludes: ['**/node_modulues/**/*', 'src/__generated__/**/*'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const EventsTable = (props: IEventsTableProps): JSX.Element => {
<Column>Values</Column>
</TableHeader>
<TableBody>
{JSON.parse(event.parameterText).map(
{JSON.parse(event.parameters || '""').map(
(parameter: any, index: number) => (
<Row key={`arguments-${index}`}>
<Cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { gql } from '@apollo/client';

export const CORE_EVENT_FIELDS: DocumentNode = gql`
fragment CoreEventFields on Event {
parameterText
parameters
qualifiedName
}
`;
Expand Down
20 changes: 0 additions & 20 deletions packages/apps/graph-client/src/graphql/fields/miner-key.graph.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const ALL_TRANSACTION_FIELDS: DocumentNode = gql`
gas
goodResult
logs
metadata
eventCount
transactionId
}
Expand Down
4 changes: 1 addition & 3 deletions packages/apps/graph-client/src/graphql/queries.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ALL_FUNGIBLE_CHAIN_ACCOUNT_FIELDS,
CORE_FUNGIBLE_CHAIN_ACCOUNT_FIELDS,
} from './fields/fungible-chain-account.graph';
import { CORE_MINER_KEY_FIELDS } from './fields/miner-key.graph';
import { ALL_NON_FUNGIBLE_ACCOUNT_FIELDS } from './fields/non-fungible-account.graph';
import { CORE_NON_FUNGIBLE_CHAIN_ACCOUNT_FIELDS } from './fields/non-fungible-chain-account.graph';
import { CORE_TRANSACTION_FIELDS } from './fields/transaction.graph';
Expand All @@ -17,7 +16,6 @@ import { gql } from '@apollo/client';
export const getBlockFromHash: DocumentNode = gql`
${ALL_BLOCK_FIELDS}
${CORE_TRANSACTION_FIELDS}
${CORE_MINER_KEY_FIELDS}
query getBlockFromHash(
$hash: String!
Expand Down Expand Up @@ -136,7 +134,7 @@ export const getFungibleChainAccount: DocumentNode = gql`
fungibleChainAccount(
fungibleName: $fungibleName
accountName: $accountName
chainId: $chainId
chainIds: [$chainId]
) {
...AllFungibleChainAccountFields
transactions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const ChainAccount: React.FC = () => {
</Cell>
<Cell>
{
fungibleChainAccountData.fungibleChainAccount
fungibleChainAccountData.fungibleChainAccount[0]
.fungibleName
}
</Cell>
Expand All @@ -209,7 +209,7 @@ const ChainAccount: React.FC = () => {
<strong>Balance</strong>
</Cell>
<Cell>
{fungibleChainAccountData.fungibleChainAccount.balance}
{fungibleChainAccountData.fungibleChainAccount[0].balance}
</Cell>
</Row>
<Row>
Expand All @@ -218,7 +218,7 @@ const ChainAccount: React.FC = () => {
</Cell>
<Cell>
{
fungibleChainAccountData.fungibleChainAccount.guard
fungibleChainAccountData.fungibleChainAccount[0].guard
.predicate
}
</Cell>
Expand All @@ -228,7 +228,10 @@ const ChainAccount: React.FC = () => {
<strong>Guard Keys</strong>
</Cell>
<Cell>
{fungibleChainAccountData.fungibleChainAccount.guard.keys}
{
fungibleChainAccountData.fungibleChainAccount[0].guard
.keys
}
</Cell>
</Row>
</TableBody>
Expand All @@ -244,7 +247,7 @@ const ChainAccount: React.FC = () => {
chainId={router.query.chain as string}
truncateColumns={true}
transfers={
fungibleChainAccountData.fungibleChainAccount
fungibleChainAccountData.fungibleChainAccount[0]
.transfers as FungibleChainAccountTransfersConnection
}
/>
Expand All @@ -258,7 +261,7 @@ const ChainAccount: React.FC = () => {
}`}
truncateColumns={true}
transactions={
fungibleChainAccountData.fungibleChainAccount
fungibleChainAccountData.fungibleChainAccount[0]
.transactions as FungibleChainAccountTransactionsConnection
}
/>
Expand Down
8 changes: 1 addition & 7 deletions packages/apps/graph-client/src/pages/transactions/[key].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ const RequestKey: React.FC = () => {
</Cell>
<Cell>{transaction.result.logs}</Cell>
</Row>
<Row>
<Cell>
<strong>Metadata</strong>
</Cell>
<Cell>{transaction.result.metadata}</Cell>
</Row>
<Row>
<Cell>
<strong>Continuation</strong>
Expand Down Expand Up @@ -282,7 +276,7 @@ const RequestKey: React.FC = () => {
<Cell>
<pre>
{event?.node ? (
formatCode(event.node.parameterText)
formatCode(event.node.parameters || '""')
) : (
<span style={{ color: 'lightgray' }}>
N/A
Expand Down
1 change: 0 additions & 1 deletion packages/apps/graph/.graphqlrc.yml

This file was deleted.

Loading

0 comments on commit 1afb5ba

Please sign in to comment.