Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A shell script to parse the JSON output of `rover subgraph check` or `rover graph check`
#!/usr/bin/env sh
set -euo pipefail
# This script performs a subgraph check and generates a markdown file from Rover's JSON output
# Change the following line to refer to your graph ref, schema, and subgraph name
CHECK_OUTPUT=$(rover subgraph check my-graph --schema ./products.graphql --name products --output json) || true
CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success')
if [ $CHECK_SUCCESS = "true" ]; then
echo "### $ENVIRONMENT Check Success"
echo ""
echo "#### Change Details"
echo ""
fi
CHANGES=$(echo "${CHECK_OUTPUT}" | jq '.data.changes')
if [ "$CHANGES" != "null" ]; then
CHANGE_SIZE=$(echo "${CHECK_OUTPUT}" | jq -r '.data.changes | length')
if [ "$CHANGE_SIZE" = "0" ]; then
echo "No changes"
fi
if [ "$CHANGE_SIZE" != "0" ]; then
echo "| Severity | Code | Description |"
echo "| -------- | ---- | ----------- |"
for CHANGE in $(echo "${CHECK_OUTPUT}" | jq -r '.data.changes[] | @base64'); do
_jq() {
echo ${CHANGE} | base64 -d | jq -r ${1}
}
CHANGE_SEVERITY=$(_jq '.severity')
CHANGE_CODE=$(_jq '.code')
CHANGE_DESCRIPTION=$(_jq '.description')
echo "| $CHANGE_SEVERITY | $CHANGE_CODE | $CHANGE_DESCRIPTION |"
done
fi
echo ""
fi
if [ $CHECK_SUCCESS = "false" ]; then
echo "### $ENVIRONMENT Check Failure"
echo ""
echo $CHECK_OUTPUT | jq -r '.error.message'
echo ""
echo "#### Error Details"
echo ""
for BUILD_ERROR in $(echo "${CHECK_OUTPUT}" | jq -r '.error.details.build_errors[] | @base64'); do
_jq() {
echo ${BUILD_ERROR} | base64 -d | jq -r ${1}
}
BUILD_ERROR_CODE=$(_jq '.code')
if [ $BUILD_ERROR_CODE != "null" ]; then
echo "$BUILD_ERROR_CODE: $(_jq '.message')"
else
echo "UNKNOWN: $(_jq '.message')"
fi
exit 1
done
fi
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment