check_graphql_api_consistency.sh 908 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. set -e
  3. TMP_FILE_BEFORE='./tmp/serialized-graphql-api.ts.before'
  4. TMP_FILE_AFTER='./tmp/serialized-graphql-api.ts.after'
  5. # Delete files on exit
  6. trap 'rm -f $TMP_FILE_BEFORE $TMP_FILE_AFTER' EXIT
  7. function serialize_graphql_api() {
  8. TARGET_FILE=$1
  9. INTROSPECTION_FILE='app/graphql/graphql_introspection.json'
  10. TYPES_FILE='./app/frontend/shared/graphql/types.ts'
  11. API_FILES=$(find ./app/frontend -path '*/graphql/*' -name '*.api.ts')
  12. cat $INTROSPECTION_FILE $TYPES_FILE $API_FILES > $TARGET_FILE
  13. }
  14. echo "Checking if auto-generated GraphQL API is up-to-date…"
  15. serialize_graphql_api $TMP_FILE_BEFORE
  16. pnpm generate-graphql-api
  17. serialize_graphql_api $TMP_FILE_AFTER
  18. if ! cmp $TMP_FILE_BEFORE $TMP_FILE_AFTER
  19. then
  20. diff $TMP_FILE_BEFORE $TMP_FILE_AFTER
  21. echo "Use the command 'pnpm run generate-graphql-api' to re-generate the API files."
  22. exit 1
  23. else
  24. echo "API files are up-to-date."
  25. fi