Skip to content

Commit a503ed2

Browse files
committed
Website/GraphQL: escape query in bash script
1 parent 006a1c1 commit a503ed2

19 files changed

+80
-38
lines changed

website/docs/developers/scripts/graphql-api/mutations/curl/send-payment.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
# WARNING: This mutation modifies the blockchain state
99
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/send-payment.graphql" | sed 's/ */ /g')
10+
# Read the query and create JSON payload using jq for proper escaping
11+
QUERY=$(< "$SCRIPT_DIR/../query/send-payment.graphql")
1112

1213
# Example variables - replace with actual values
1314
VARIABLES='{
@@ -24,6 +25,7 @@ VARIABLES='{
2425
}
2526
}'
2627

28+
JSON_PAYLOAD=$(echo '{}' | jq --arg query "$QUERY" --argjson variables "$VARIABLES" '.query = $query | .variables = $variables')
2729
curl -X POST "$GRAPHQL_ENDPOINT" \
2830
-H "Content-Type: application/json" \
29-
-d "{\"query\": \"$QUERY\", \"variables\": $VARIABLES}"
31+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/account-balance.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/account-balance.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/account-balance.graphql")
11+
VARIABLES='{ "publicKey": "B62qp3B9VW1ir5qL1MWRwr6ecjC2NZbGr8vysGeme9vXGcFXTMNXb2t" }'
12+
JSON_PAYLOAD=$(echo '{}' | jq --arg query "$QUERY" --argjson variables "$VARIABLES" '.query = $query | .variables = $variables')
1013
curl -X POST "$GRAPHQL_ENDPOINT" \
1114
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\", \"variables\": { \"publicKey\": \"B62qp3B9VW1ir5qL1MWRwr6ecjC2NZbGr8vysGeme9vXGcFXTMNXb2t\" }}"
15+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/account.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/account.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/account.graphql")
11+
VARIABLES='{"publicKey": "B62qp3B9VW1ir5qL1MWRwr6ecjC2NZbGr8vysGeme9vXGcFXTMNXb2t"}'
12+
JSON_PAYLOAD=$(echo '{}' | jq --arg query "$QUERY" --argjson variables "$VARIABLES" '.query = $query | .variables = $variables')
1013
curl -X POST "$GRAPHQL_ENDPOINT" \
1114
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\", \"variables\": {\"publicKey\": \"B62qp3B9VW1ir5qL1MWRwr6ecjC2NZbGr8vysGeme9vXGcFXTMNXb2t\"}}"
15+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/basic-connectivity.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/basic-connectivity.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/basic-connectivity.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/best-chain.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/best-chain.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/block.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/block.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/block.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/current-snark-worker.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/current-snark-worker.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/current-snark-worker.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/daemon-status.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/daemon-status.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/daemon-status.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/genesis-block.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/genesis-block.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/genesis-block.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

website/docs/developers/scripts/graphql-api/queries/curl/genesis-constants.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ GRAPHQL_ENDPOINT="${1:-http://mina-rust-plain-1.gcp.o1test.net/graphql}"
66

77
# Replace with your own node endpoint: http://localhost:3000/graphql
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9-
QUERY=$(tr '\n' ' ' < "$SCRIPT_DIR/../query/genesis-constants.graphql" | sed 's/ */ /g')
9+
# Read the query and create JSON payload using jq for proper escaping
10+
QUERY=$(< "$SCRIPT_DIR/../query/genesis-constants.graphql")
11+
JSON_PAYLOAD=$(echo "{}" | jq --arg query "$QUERY" '.query = $query')
1012
curl -X POST "$GRAPHQL_ENDPOINT" \
1113
-H "Content-Type: application/json" \
12-
-d "{\"query\": \"$QUERY\"}"
14+
-d "$JSON_PAYLOAD"

0 commit comments

Comments
 (0)