Skip to content

Commit

Permalink
fix: JSON resolver for transaction metadata
Browse files Browse the repository at this point in the history
The API type name will be changed to JSON at the next major version update.
Until then this ensures the non-object JSON values are accepted as valid.

Fixes #389

(cherry picked from commit ff36501)
  • Loading branch information
rhyslbw committed Dec 21, 2020
1 parent cbdb22a commit 9085036
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 55 deletions.
4 changes: 2 additions & 2 deletions packages/api-cardano-db-hasura/src/executableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GraphQLSchema } from 'graphql'
import {
IPv4Resolver,
IPv6Resolver,
JSONObjectResolver,
JSONResolver,
TimestampResolver,
URLResolver
} from 'graphql-scalars'
Expand All @@ -24,7 +24,7 @@ export const scalarResolvers = {
Hash32Hex: util.scalars.Hash32Hex,
IPv4: IPv4Resolver,
IPv6: IPv6Resolver,
JSONObject: JSONObjectResolver,
JSONObject: JSONResolver,
Percentage: util.scalars.Percentage,
StakeAddress: util.scalars.StakeAddress,
StakePoolID: util.scalars.StakePoolID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,54 +105,6 @@ Object {
}
`;

exports[`transactions Can return transaction metadata if present 1`] = `
Object {
"transactions": Array [
Object {
"metadata": Array [
Object {
"key": "0",
"value": Object {
"La_RepsistancE": "Was here",
},
},
Object {
"key": "1",
"value": Object {
"Choices": Array [
Object {
"CandidateId": "aaa9503a-6fc5-46ea-9aa0-b4c90f361a4c",
"VoteRank": 1,
"VoteWeight": 1,
},
Object {
"CandidateId": "8d649c12-936e-46be-b65a-c17f30f59574",
"VoteRank": 2,
"VoteWeight": 1,
},
Object {
"CandidateId": "81ce7f8e-94c3-4835-91fc-2146d51fa1fc",
"VoteRank": 0,
"VoteWeight": 0,
},
Object {
"CandidateId": "407540aa-58b5-40ca-b484-f40040eb2990",
"VoteRank": 3,
"VoteWeight": 1,
},
],
"NetworkId": "TheRealAdamDean",
"ObjectType": "VoteBallot",
"ProposalId": "80064c28-1b03-4f1c-abf0-ca8c5a98d5b9",
"VoterId": "d990a1e8-cb90-4f59-b5cf-a8b59c9ba8ae",
},
},
],
},
],
}
`;

exports[`transactions Returns transactions by hashes 1`] = `
Object {
"transactions": Array [
Expand Down Expand Up @@ -315,3 +267,94 @@ Object {
],
}
`;

exports[`transactions metadata JSON object 1`] = `
Object {
"transactions": Array [
Object {
"metadata": Array [
Object {
"key": "0",
"value": Object {
"La_RepsistancE": "Was here",
},
},
Object {
"key": "1",
"value": Object {
"Choices": Array [
Object {
"CandidateId": "aaa9503a-6fc5-46ea-9aa0-b4c90f361a4c",
"VoteRank": 1,
"VoteWeight": 1,
},
Object {
"CandidateId": "8d649c12-936e-46be-b65a-c17f30f59574",
"VoteRank": 2,
"VoteWeight": 1,
},
Object {
"CandidateId": "81ce7f8e-94c3-4835-91fc-2146d51fa1fc",
"VoteRank": 0,
"VoteWeight": 0,
},
Object {
"CandidateId": "407540aa-58b5-40ca-b484-f40040eb2990",
"VoteRank": 3,
"VoteWeight": 1,
},
],
"NetworkId": "TheRealAdamDean",
"ObjectType": "VoteBallot",
"ProposalId": "80064c28-1b03-4f1c-abf0-ca8c5a98d5b9",
"VoterId": "d990a1e8-cb90-4f59-b5cf-a8b59c9ba8ae",
},
},
],
},
],
}
`;

exports[`transactions metadata JSON string 1`] = `
Object {
"transactions": Array [
Object {
"metadata": Array [
Object {
"key": "0",
"value": "MelDemo1",
},
Object {
"key": "1",
"value": "454654654564564654",
},
Object {
"key": "2",
"value": "sha256",
},
Object {
"key": "3",
"value": "http://127.0.0.1/data.json",
},
Object {
"key": "4",
"value": "dsfgdfsgsdfgsdfgsdfgdsfdfgdsfgdfgdfsgsdef",
},
Object {
"key": "5",
"value": "http://127.0.0.1/client_publickey.txt",
},
Object {
"key": "6",
"value": "kjfsdhgdjiksfedhdgjksdhfgjksdfhgjklsdhf",
},
Object {
"key": "7",
"value": "http://scantrust/server_publickey.txt",
},
],
},
],
}
`;
21 changes: 16 additions & 5 deletions packages/api-cardano-db-hasura/test/transactions.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,22 @@ describe('transactions', () => {
})
expect(result.data).toMatchSnapshot()
})
it('Can return transaction metadata if present', async () => {
const result = await client.query({
query: await loadQueryNode('transactionByIdWithMetadataIfPresent'),
variables: { hash: 'f910021138e553c65b96cf3e4647927fcd9f634e06544251f83cffb1891876e8' }

describe('metadata', () => {
it('JSON object', async () => {
const result = await client.query({
query: await loadQueryNode('transactionByIdWithMetadataIfPresent'),
variables: { hash: 'f910021138e553c65b96cf3e4647927fcd9f634e06544251f83cffb1891876e8' }
})
expect(result.data).toMatchSnapshot()
})

it('JSON string', async () => {
const result = await client.query({
query: await loadQueryNode('transactionByIdWithMetadataIfPresent'),
variables: { hash: '204ca3088bbab666692f39dddb9b773e6fb20b0d0c3e464407985fa7863e5bac' }
})
expect(result.data).toMatchSnapshot()
})
expect(result.data).toMatchSnapshot()
})
})

0 comments on commit 9085036

Please sign in to comment.