import logging


def write_bigquery_to_file(bigquery_filepath, query_string):
    """Writes BigQuery query string to a file.

    Args:
      bigquery_filepath: (str) Output file path.
      query_string: (str) BigQuery query string to write to file.

    Returns:
      (bool) True if query was written to file successfully, False otherwise.
    """
    logger = logging.getLogger('telescope')
    try:
        with open(bigquery_filepath, 'w') as bigquery_file_raw:
            bigquery_file_raw.write(query_string)
        return True
    except Exception as caught_error:
        logger.error('When writing bigquery, caught %s.', caught_error)

    return False