Skip to content

Commit

Permalink
update schema to represent correct structure in preparation of transi…
Browse files Browse the repository at this point in the history
…tion to kadindexer.io/graphql (#2783)
  • Loading branch information
alber70g authored Jan 21, 2025
1 parent c298573 commit 35cad4d
Show file tree
Hide file tree
Showing 59 changed files with 666 additions and 294 deletions.
145 changes: 145 additions & 0 deletions .changeset/green-scissors-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
'@kadena/graph': minor
---

We're introduced a number of **deprecations** to prepare to transition to
kadindexer.io/graphql

Changes and their resolution

## Changes without Alternative

```log
✖ Field Block.target changed type from Decimal! to String!
✖ Field Block.weight changed type from Decimal! to String!
```

These changes shouldn't impact anyone too much, as they're mostly internal

## Changes with a Resolution

```log
✖ Field incrementedId was removed from object type Event
```

We've removed this field, `Event.orderIndex` can be used to order events

## Other modifications

```log
✖ Type MinerKey was removed
```

We've simplified the schema by using `FungibleAccount` instead of `MinerKey`.

### Guards

We've removed the `Guard` type and replaced it with `IGuard` to allow for more
flexibility in the future. We also added `KeysetGuard` to represent the old
`Guard` type.

The `IGuard` type is a union of all the different types of guards that can be
used in a Pact.

Currently implemented guards are `KeysetGuard` and `UserGuard`.

The `IGuard` has a field `raw` which can be used to retrieve any guard as a raw
JSON object.

They can be queried as such:

```graphql
guard {
raw
__typename
... on KeysetGuard {
keys
predicate
}
... on UserGuard {
fun
args
}
}
```

```log
✖ Field FungibleChainAccount.guard changed type from Guard! to IGuard!
✖ Type Guard was removed
✖ Field NonFungibleTokenBalance.guard changed type from Guard! to IGuard!
✔ Description A guard. Has values `keys`, `predicate` to provide backwards
compatibility for `KeysetGuard`. on type IGuard has changed to A guard. This
is a union of all the different types of guards that can be used in a pact.
✔ Deprecation reason on field IGuard.keys has changed from Use
`... on KeysetGuard { keys predicate }` instead when working with Keysets to
deprecated, use KeysetGuard.keys
✔ Directive deprecated was added to field IGuard.keys
✔ Deprecation reason on field IGuard.predicate has changed from Use
`... on KeysetGuard { keys predicate }` instead when working with Keysets to
deprecated, use KeysetGuard.predicate
✔ Directive deprecated was added to field IGuard.predicate
✔ Type RawGuard was added
✔ Type KeysetGuard was added
✔ Type UserGuard was added
```

### Default values

We've added default values for arguments to a number of fields to make it easier
to query the graph.

```log
⚠ 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
⚠ 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
```

### Query.fungibleChainAccounts

We've introduced a new field `Query.fungibleChainAccounts(chainIds: [String])`
to allow for querying multiple fungible chain accounts across chains.

```
✔ Field fungibleChainAccounts was added to object type Query
✔ Type for argument chainIds on field Subscription.newBlocksFromDepth changed
from [String!]! to [String!]
```

### Deprecations and removals

Various types had `height` and `chainId` which should've been retrieved from
`Block`. We're planning to remove these fields and added deprecations.

```log
✖ Type PositiveFloat was removed
✔ Field TransactionResult.height is deprecated
✔ Field TransactionResult.height has deprecation reason Use `block.height`
instead.
✔ Directive deprecated was added to field TransactionResult.height
✔ Field TransactionResult.metadata is deprecated
✔ Field TransactionResult.metadata has deprecation reason Not used.
✔ Field TransactionResult.metadata changed type from String to String!
✔ Directive deprecated was added to field TransactionResult.metadata
✔ Field Transfer.blockHash is deprecated
✔ Field Transfer.blockHash has deprecation reason Use `block.hash` field
instead.
✔ Field Transfer.chainId is deprecated
✔ Field Transfer.chainId has deprecation reason Use `block.chainId` field
instead.
✔ Field Transfer.height is deprecated
✔ Field Transfer.height has deprecation reason Use `block.height` field
instead.
```
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'],
},
},
};
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"*.json": "jsonc"
},
"eslint.workingDirectories": [{ "pattern": "./packages/*/*" }]
}
1 change: 1 addition & 0 deletions packages/apps/explorer/apollo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
service: {
name: 'graph',
localSchemaFile: __dirname + '/../graph/generated-schema.graphql',
// url: 'https://www.kadindexer.io/graphql',
},
includes: ['src/**/*.ts', 'src/**/*.tsx'],
excludes: ['**/node_modules/**/*', 'src/__generated__/**/*'],
Expand Down
5 changes: 3 additions & 2 deletions packages/apps/explorer/codegen-sdk.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
overwrite: true
# schema: ./node_modules/@kadena/graph/generated-schema.graphql
schema: https://graph.kadena.network/graphql
schema: ./node_modules/@kadena/graph/generated-schema.graphql
# schema: https://graph.kadena.network/graphql
# schema: https://www.kadindexer.io/graphql
generates:
./src/__generated__/sdk.ts:
documents: 'src/**/*.graph.(ts|tsx)'
Expand Down
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 @@ -76,7 +76,7 @@ export const CompactTransactionsTable = (
</Cell>
<Cell>
{edge.node.result.__typename === 'TransactionResult' ? (
edge.node.result.height
edge.node.result.block.height
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
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 @@ -206,7 +206,7 @@ export const ExtendedTransactionsTable = (
</Cell>
<Cell>
{edge.node.result.__typename === 'TransactionResult' ? (
edge.node.result.height
edge.node.result.block.height
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
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 @@ -21,7 +21,9 @@ export const CORE_TRANSACTION_FIELDS: DocumentNode = gql`
}
result {
... on TransactionResult {
height
block {
height
}
}
}
}
Expand Down Expand Up @@ -75,7 +77,6 @@ export const ALL_TRANSACTION_FIELDS: DocumentNode = gql`
gas
goodResult
logs
metadata
eventCount
transactionId
}
Expand Down
Loading

0 comments on commit 35cad4d

Please sign in to comment.