Last active
January 9, 2023 16:00
-
-
Save franciscoafonsoo/0231da8363af91e319513c557a7b7cc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install the dependencies: | |
# | |
# brew install pipx | |
# pipx install graphql-schema-diff | |
# | |
# Example usage: | |
# λ › ./schemacheck.sh src/schema/schema.graphqls | |
# 🎉 Both schemas are equal! | |
# | |
# λ › ./schemacheck.sh src/schema/schema.graphqls origin/improve_error_handling | |
# ❌ `TimeInput.value` type changed from `NonNegativeInt!` to `NonNegativeFloat!` | |
# ❌ `Time.value` type changed from `NonNegativeInt!` to `NonNegativeFloat!` | |
# ❌ `ChargeInput.value` type changed from `Float!` to `NonNegativeFloat!` | |
# Check if schemadiff is installed | |
if ! command -v schemadiff > /dev/null; then | |
echo "Error: schemadiff is not installed. Please install it using 'pipx install graphql-schema-diff'" | |
exit 1 | |
fi | |
# path to the graphqls file is mandatory | |
if [ -z "$1" ]; then | |
# $1 is not set or is empty | |
echo "Error: Missing file path argument." | |
echo "Usage: schemacheck.sh [<schema.graphqls filename>] [<git commit hash>]" | |
exit 1 | |
fi | |
# Set the commit hash to HEAD if not specified | |
commit_hash=${2:-master} | |
# Create a temporary file | |
temp_file=$(mktemp) | |
# Retrieve the contents of the file from the commit and redirect the output to the temporary file | |
git show $commit_hash:$1 > $temp_file | |
# Pass the name of the temporary file as an argument to schemadiff | |
schemadiff -o $temp_file -n $1 | |
# remove the temp file | |
rm $temp_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment