Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
bigchaindb-graphql
Advanced tools
Readme
Example GraphQL API running on top of the BigchainDB JavaScript driver.
asset_id
asset_id
$ npm install bigchaindb-graphql
or
$ yarn add bigchaindb-graphql
(Optional) Prepopulate BigchainDB with the example transactions, see bigchaindb/graphql-bigchaindb:
$ python prepopulate.py
These are the transactions used in the examples below.
$ npm run test
The code does not talk to the backend database directly. It just retrieves whatever data it needs using the JavaScript driver and constructs the GraphQL objects from the returned JSON.
import { graphql } from 'graphql'
import {
BigchainDBGraphQLConnection,
BigchainDBGraphQLSchema
} from 'bigchaindb-graphql'
const BigchainDBSchema = new BigchainDBGraphQLSchema(
new BigchainDBGraphQLConnection("<connection details eg. 'http://localhost:9984/api/v1/', headers>")
).schema
const queryTransaction = `
{
transaction(id: "3b3fd7128580280052595b9bcda98895a851793cba77402ca4de0963be958c9e") {
id
operation
asset
metadata
}
}
`
graphql(BigchainDBSchema, queryTransaction).then(result => {
console.log(JSON.stringify(result, null, 2))
})
After prepopulating BigchainDB with the transactions provided you can run the following queries in the browser or Node.js.
query {
transaction(id:"3b3fd7128580280052595b9bcda98895a851793cba77402ca4de0963be958c9e") {
id
operation
asset
# we don't care about the inputs
# inputs
# from the outputs we don't care about the condition so we only want
# the amount and public keys
outputs {
amount
public_keys
}
# we don't care about the metadata
# metadata
}
}
asset_id
query {
transactions(asset_id:"3b3fd7128580280052595b9bcda98895a851793cba77402ca4de0963be958c9e") {
# For each transaction returned I only want the id, operation and
# public keys in the outputs
id
operation
outputs {
public_keys
}
}
}
asset_id
query {
transactions(asset_id:"3b3fd7128580280052595b9bcda98895a851793cba77402ca4de0963be958c9e", operation:"TRANSFER") {
# I only want the public keys and amounts of all the outputs that this
# transfer transaction fulfills
inputs {
fulfills {
output_index
# the `transaction_id` inside fulfills is resolved to the
# actual transaction so we can query fields on the transaction
# pointed to in this inputs, notice that this can go as deep as you like
transaction {
outputs {
amount
public_keys
}
}
}
}
}
}
query {
transaction(id:"3b3fd7128580280052595b9bcda98895a851793cba77402ca4de0963be958c9e") {
# I want to know the blocks, votes and respective timestamps of a transaction
asset
metadata
blocks {
block {
node_pubkey
timestamp
}
votes {
node_pubkey
vote {
timestamp
}
}
}
}
}
query {
outputs(publicKey:"FxEfUt9ArymGeCB99dZtfCUcsKwC29c8AHZ9EPnVWcyL") {
output_index
# once again the transaction_id is resolved to the actual transaction
transaction {
id
operation
asset
}
}
}
query {
outputs(publicKey:"FxEfUt9ArymGeCB99dZtfCUcsKwC29c8AHZ9EPnVWcyL") {
output_index
# once again the transaction_id is resolved to the actual transaction
transaction {
id
operation
asset
}
}
}
query {
block(id: "c44c06985175ee0cf210fff65c44e63aa06300999e5e7654e13678582522e8f0") {
id
block {
timestamp
transactions {
id
}
node_pubkey
voters
}
votes {
vote {
timestamp
}
}
signature
}
}
query {
votes(block_id: "c44c06985175ee0cf210fff65c44e63aa06300999e5e7654e13678582522e8f0") {
node_pubkey
signature
vote {
voting_for_block
previous_block
is_block_valid
invalid_reason
timestamp
}
}
}
query {
search(text: "b") {
id
asset
}
}
note: graphql doesn't support unstructured objects, hence the
asset
andmetadata
need to be serialized in an URI encoded string (e.g.encodeURIComponent(JSON.stringify({ metadata: 'metavalue' }))
)
mutation {
transaction(
publicKey: "4AzdUiGGjUNmSp75dNGe5Qw36czV8PdaLDkCY2bdZpcH",
privateKey: "57c3KBq7hiQ7JLHuVWzBGfwCKeLfm1oFbv9CgP2uxwhN",
asset: "{ assetdata: 'assetvalue' }",
metadata: "{ metadata: 'metavalue' }"
) {
id
operation
asset
metadata
inputs {
owners_before
fulfillment
fulfills {
output_index
transaction {
id
asset
metadata
inputs {
fulfills {
transaction {
id
}
}
}
}
}
}
outputs {
condition
public_keys
amount
}
blocks {
block {
node_pubkey
timestamp
}
votes {
node_pubkey
vote {
timestamp
}
}
}
}
}
note: graphql doesn't support unstructured objects, hence the
tx
andmetadata
need to be serialized in an URI encoded string (e.g.encodeURIComponent(JSON.stringify(tx))
)
mutation {
transfer(
tx: <transaction to transfer>,
fromPublicKey: "8bpyjMowghbfN8vMTAyueQVggjtR9geACU8JeXLQHawY",
fromPrivateKey: "DQGfjg1kseHZTedxsUjwTXukGZ8hPNjioJ7Btq9wyiTW",
toPublicKey: "GvjRh229J3GEgGnSjKzdv81eiEUtjyftBsJzU2Urmfud",
metadata: "{metadata: 'newmetavalue'}"
) {
id
operation
asset
metadata
inputs {
owners_before
fulfillment
fulfills {
output_index
transaction {
id
asset
metadata
inputs {
fulfills {
transaction {
id
}
}
}
}
}
}
outputs {
condition
public_keys
amount
}
blocks {
block {
node_pubkey
timestamp
}
votes {
node_pubkey
vote {
timestamp
}
}
}
}
}
For a new patch release, execute on the machine where you're logged into your npm account:
npm run release
Command is powered by release-it
package, defined in the package.json
.
That's what the command does without any user interaction:
package.json
If you want to create a minor or major release, use these commands:
npm run release-minor
npm run release-major
Copyright 2017 BigchainDB GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
FAQs
> Example GraphQL API running on top of the BigchainDB JavaScript driver.
We found that bigchaindb-graphql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).