Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to convert Apollo Schema Check JSON responses to markdown for github comments.
#!/usr/bin/env sh
set -euo pipefail
# 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)CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success')
if [ $CHECK_SUCCESS = "true" ]; then
echo "### Status: :white_check_mark:"
echo ""
fi
if [ $CHECK_SUCCESS = "false" ]; then
echo "### Status: :x:"
echo ""
echo $CHECK_OUTPUT | jq -r '.error.message' | tr -d '"'
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
done
fi
CHANGES=$(echo "${CHECK_OUTPUT}" | jq '.data.changes')
if [ "$CHANGES" != "null" ]; then
echo "<details>"
echo "<summary>Change Details</summary>"
echo ""
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 "</details>"
echo ""
fi
CHECK_URL=$(echo $CHECK_OUTPUT | jq '.data.target_url')
if [ $CHECK_URL != null ]; then
echo ""
echo "See more details in [Apollo Studio]($CHECK_URL)" | tr -d '"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment