The mighty Flywheel Trading app's GraphQL API service. Its primary purpose is to serve user data to the web service.
Launch the GraphQL API service (at localhost:4000 by default):
(To deploy the full stack application at once, please see https://github.com/chohanbin/flywheel-data-service)
Create .env.local file that specifies which MongoDB to target (Replace <CONNECTION_STRING> with the target DB URI, e.g. 'mongodb+srv://.../sample_analytics?...' or mongodb://localhost:27017)
- NOTE: This service is compatible only with a MongoDB database with Sample Analytics Dataset schema.
DB_CONN_STRING=<CONNECTION_STRING>From the repo root directory, invoke:
npm install # Only needs to be run once.
npm start # Run every time the service needs to start.Shut down the service with Ctrl + D.
If this is your first time running this service, run:
# If the output to this command returns nothing,
docker network ls | grep flywheel
# Then run
docker network create flywheelBuild the image with:
docker build -t flywheel-data-service .Run a container (Replace <CONNECTION_STRING> with the target DB URI):
docker run --name data-service \ # the name that this service will be known to other services on 'flywheel' network
--network flywheel \
-dp 127.0.0.1:4000:4000 \
-e DB_CONN_STRING='<CONNECTION_STRING>' \
flywheel-data-service// ^TODO: Add instruction on how to allow this docker service to connect to mongodb://localhost:27017
Shut down the service with:
docker ps | grep flywheel-data-serviceThen run (Explanation of docker rm -f):
docker rm -f <target docker container ID>This service exposes the content of a MongoDB database in Sample Analytics Dataset schema.
Currently, it supports fetching customers collection with customer query, and transactions collection with transactionBatch query, as shown below. For the official GraphQL schema, refer to src/schema.graphql
Visit http://localhost:4000 from your browser, to open up Apollo Sandbox from where you can submit these GraphQL queries against your local flywheel-data-service.
Operation (omit fields as desired):
query GetCustomer($email: String!) {
customer(email: $email) {
username
name
email
accounts
}
}Variables (replace appleseed with your target email):
{ "email": "johnny@appleseed.com" }Operation (omit fields as desired):
query GetTransactionBatch($accountId: Int!) {
transactionBatch(accountId: $accountId) {
account_id
transaction_count
bucket_start_date
bucket_end_date
transactions {
date
amount
transaction_code
symbol
price
total
}
}
}Variables (replace 123456 with your target accountId):
{ "accountId": 123456 }From the repo root directory, invoke:
npm testHanbin Cho