Sanitize and represent a string argument in MATCH.

def _safe_match_string(value):
    """Sanitize and represent a string argument in MATCH."""
    if not isinstance(value, six.string_types):
        if isinstance(value, bytes):  # should only happen in py3
            value = value.decode('utf-8')
        else:
            raise GraphQLInvalidArgumentError(u'Attempting to convert a non-string into a string: '
                                              u'{}'.format(value))

    # Using JSON encoding means that all unicode literals and special chars
    # (e.g. newlines and backslashes) are replaced by appropriate escape sequences.
    # JSON has the same escaping rules as MATCH / SQL, so no further escaping is necessary.
    return json.dumps(value)