Skip to content

Instantly share code, notes, and snippets.

@EverlastingBugstopper
Last active August 24, 2022 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a to your computer and use it in GitHub Desktop.
Save EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a to your computer and use it in GitHub Desktop.
A bash script to parse the JSON output of `rover subgraph check` or `rover graph check`
#! /bin/bash
# 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)
CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success')
if [ $CHECK_SUCCESS = "true" ]; then
echo "### 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 "### 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 -n "$BUILD_ERROR_CODE: "
else
echo -n "UNKNOWN: "
fi
echo $(_jq '.message')
done
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)"
fi
echo ""
@adiii717
Copy link

come up with this
https://gist.github.com/adiii717/a5428c0f91cb56521d7d5f2f834c7309

### | Severity | Code | Description |
| -------- | ---- | ----------- |
| FAIL | TYPE_REMOVED | type `demo`: removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
### Check Failure
This operation check has encountered 4 schema changes that would break operations from existing client traffic.

### Status: ❌
StatusCode: E030
Error Message: This operation check has encountered 4 schema changes that would break operations from existing client traffic.

See more details in [Apollo Studio]

and I was on gitlab so this work for me

  - export RESULT=$(curl -s https://gist.githubusercontent.com/adiii717/a5428c0f91cb56521d7d5f2f834c7309/raw/77ab4077617f252ba1a675e77fb67cd284655d93/rover_check_markdown.sh | bash -s -- "rover subgraph check demo@develop -s demo.gql --name demo --output json")
  - echo "${RESULT}" > result.md && export MD_RESULT=$(awk 'ORS="\n\n"' result.md)
  - curl --request POST --header "Content-Type:multipart/form-data" --header "PRIVATE-TOKEN:${GITLAB_TOKEN}" "https://gitlab.com/api/v4/projects/${CI_MERGE_REQUEST_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/notes?body"  -d  "body=$MD_RESULT"
  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment