Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add command for starting graphql with subscriptions * Connect to Dockerfile * Add sample script to subscribe to local query-node * Use yarn instead of npm * Rename docker container name to api * Refer query-node as api * Update graphql api commands * Spin new query-node for subscriptions * Set image name as query-node * Reorder command when starting processor
- Loading branch information
1 parent
923441e
commit 4c87c65
Showing
5 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
#!/bin/sh | ||
|
||
__usage=" | ||
Usage: ./scripts/query-node.sh <first> <second> | ||
Usage: ./scripts/api.sh <first> <second> | ||
Options for <first>: | ||
local Query data on local chain | ||
mlocal Query local chain running on mac | ||
dev Query data on battery-station (dev chain) | ||
stop Stop the already running query-node | ||
stop Stop the already running api | ||
Options for <second>: | ||
start Build & start query-node | ||
start Build & start api | ||
" | ||
|
||
if [ "$1" = "stop" ]; then | ||
echo "Stopping query-node..." | ||
docker stop zeitgeist-query-node | ||
echo "Stopping api..." | ||
docker stop api | ||
exit | ||
elif [ "$2" = "start" ]; then | ||
echo "Building query-node..." | ||
echo "Building api..." | ||
docker build . --target query-node -t query-node | ||
echo "Starting query-node..." | ||
echo "Starting api..." | ||
else | ||
echo "$__usage" | ||
exit | ||
fi | ||
|
||
if [ "$1" = "local" ]; then | ||
docker run -d --network=host --rm -e NODE_ENV=local --env-file=.env.local --name=zeitgeist-query-node query-node | ||
docker run -d --network=host --rm -e NODE_ENV=local --env-file=.env.local --name=api query-node | ||
elif [ "$1" = "mlocal" ]; then | ||
docker run -d -p 4350:4350 --rm -e NODE_ENV=mlocal --env-file=.env.mlocal --name=zeitgeist-query-node query-node | ||
docker run -d -p 4350:4350 --rm -e NODE_ENV=mlocal --env-file=.env.mlocal --name=api query-node | ||
elif [ "$1" = "dev" ]; then | ||
docker run -d -p 4350:4350 --rm -e NODE_ENV=dev --env-file=.env.dev --name=zeitgeist-query-node query-node | ||
docker run -d -p 4350:4350 --rm -e NODE_ENV=dev --env-file=.env.dev --name=api query-node | ||
elif [ "$1" = "d" ] || [ "$1" = "t1" ] || [ "$1" = "t2" ] || [ "$1" = "m1" ] || [ "$1" = "m2" ]; then | ||
docker run -d --network=host --rm -e NODE_ENV=$1 --env-file=.env.$1 --name=zeitgeist-query-node query-node | ||
docker run -d --network=host --rm -e NODE_ENV=$1 --env-file=.env.$1 --name=api query-node | ||
docker run -d --network=host --rm -e GQL_PORT=4000 -e NODE_ENV=$1 --env-file=.env.$1 --name=sub-api query-node | ||
else | ||
echo "$__usage" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const WebSocket = require('ws'); | ||
const { createClient } = require('graphql-ws'); | ||
|
||
const port = process.env.GQL_PORT || 4350 | ||
const host = process.env.GQL_HOST || 'localhost' | ||
const proto = process.env.GQL_PROTO || 'ws' | ||
|
||
|
||
const client = createClient({ | ||
webSocketImpl: WebSocket, | ||
url: `${proto}://${host}:${port}/graphql`, | ||
}); | ||
|
||
client.subscribe( | ||
{ | ||
query: ` | ||
subscription { | ||
historicalAccountBalances(limit: 5, orderBy: id_DESC) { | ||
accountId | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
next: (data) => { | ||
console.log(`New transfers: ${JSON.stringify(data)}`); | ||
}, | ||
error: (error) => { | ||
console.error('error', error); | ||
}, | ||
complete: () => { | ||
console.log('done!'); | ||
}, | ||
} | ||
); |