<commit_before>from .endpoint import Endpoint, api
from .exceptions import GraphQLError
import logging
import json

logger = logging.getLogger('tableau.endpoint.metadata')


class Metadata(Endpoint):
    @property
    def baseurl(self):
        return "{0}/api/exp/metadata/graphql".format(self.parent_srv._server_address)

    @api("3.2")
    def query(self, query, abort_on_error=False):
        logger.info('Querying Metadata API')
        url = self.baseurl

        try:
            graphql_query = json.dumps({'query': query})
        except Exception:
            # Place holder for now
            raise Exception('Must provide a string')

        # Setting content type because post_reuqest defaults to text/xml
        server_response = self.post_request(url, graphql_query, content_type='text/json')
        breakpoint()
        results = server_response.json()

        if abort_on_error and results.get('errors', None):
            raise GraphQLError(results['errors'])

        return results<commit_msg>last one<commit_after>from .endpoint import Endpoint, api
from .exceptions import GraphQLError
import logging
import json

logger = logging.getLogger('tableau.endpoint.metadata')


class Metadata(Endpoint):
    @property
    def baseurl(self):
        return "{0}/api/exp/metadata/graphql".format(self.parent_srv._server_address)

    @api("3.2")
    def query(self, query, abort_on_error=False):
        logger.info('Querying Metadata API')
        url = self.baseurl

        try:
            graphql_query = json.dumps({'query': query})
        except Exception:
            # Place holder for now
            raise Exception('Must provide a string')

        # Setting content type because post_reuqest defaults to text/xml
        server_response = self.post_request(url, graphql_query, content_type='text/json')
        results = server_response.json()

        if abort_on_error and results.get('errors', None):
            raise GraphQLError(results['errors'])

        return results
{'fraction_non_alphanumeric': 0.09850746268656717, 'fraction_numerical': 0.0029850746268656717, 'mean_word_length': 2.950884086444008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4936749', 'n_tokens_mistral': 569, 'n_tokens_neox': 552, 'n_words': 141}