check_graphql_api_consistency.sh 868 B

1234567891011121314151617181920212223242526272829
  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. yarn generate-graphql-api
  17. serialize_graphql_api $TMP_FILE_AFTER
  18. if ! cmp $TMP_FILE_BEFORE $TMP_FILE_AFTER
  19. then
  20. echo "Use the command 'yarn run generate-graphql-api' to re-generate the API files."
  21. exit 1
  22. else
  23. echo "API files are up-to-date."
  24. fi