(self, query, variables=None,  # noqa: C901
                 operation_name=None, extra_headers=None, timeout=None)
Calls the GraphQL endpoint.

        :param query: the GraphQL query or mutation to execute. Note
          that this is converted using ``bytes()``, thus one may pass
          an object implementing ``__bytes__()`` method to return the
          query, eventually in more compact form (no indentation, etc).
        :type query: :class:`str` or :class:`bytes`.

        :param variables: variables (dict) to use with
          ``query``. This is only useful if the query or
          mutation contains ``$variableName``.
          Must be a **plain JSON-serializeable object**
          (dict with string keys and values being one of dict, list, tuple,
          str, int, float, bool, None... -- :func:`json.dumps` is used)
          and the keys must **match exactly** the variable names (no name
          conversion is done, no dollar-sign prefix ``$`` should be used).
        :type variables: dict

        :param operation_name: if more than one operation is listed in
          ``query``, then it should specify the one to be executed.
        :type operation_name: str

        :param extra_headers: dict with extra HTTP headers to use.
        :type extra_headers: dict

        :param timeout: overrides the default timeout.
        :type timeout: float

        :return: dict with optional fields ``data`` containing the GraphQL
          returned data as nested dict and ``errors`` with an array of
          errors. Note that both ``data`` and ``errors`` may be returned!
        :rtype: dict
Calls the GraphQL endpoint.
Calls the GraphQL endpoint .
def __call__(self, query, variables=None,  # noqa: C901
                 operation_name=None, extra_headers=None, timeout=None):
        '''Calls the GraphQL endpoint.

        :param query: the GraphQL query or mutation to execute. Note
          that this is converted using ``bytes()``, thus one may pass
          an object implementing ``__bytes__()`` method to return the
          query, eventually in more compact form (no indentation, etc).
        :type query: :class:`str` or :class:`bytes`.

        :param variables: variables (dict) to use with
          ``query``. This is only useful if the query or
          mutation contains ``$variableName``.
          Must be a **plain JSON-serializeable object**
          (dict with string keys and values being one of dict, list, tuple,
          str, int, float, bool, None... -- :func:`json.dumps` is used)
          and the keys must **match exactly** the variable names (no name
          conversion is done, no dollar-sign prefix ``$`` should be used).
        :type variables: dict

        :param operation_name: if more than one operation is listed in
          ``query``, then it should specify the one to be executed.
        :type operation_name: str

        :param extra_headers: dict with extra HTTP headers to use.
        :type extra_headers: dict

        :param timeout: overrides the default timeout.
        :type timeout: float

        :return: dict with optional fields ``data`` containing the GraphQL
          returned data as nested dict and ``errors`` with an array of
          errors. Note that both ``data`` and ``errors`` may be returned!
        :rtype: dict
        '''
        if isinstance(query, bytes):
            query = query.decode('utf-8')
        elif not isinstance(query, str):
            # allows sgqlc.operation.Operation to be passed
            # and generate compact representation of the queries
            query = bytes(query).decode('utf-8')

        headers = self.base_headers.copy()
        if extra_headers:
            headers.update(extra_headers)

        if 'Accept' not in headers:
            headers['Accept'] = 'application/json; charset=utf-8'

        if self.method.upper() == 'POST':
            get_http_request = self.get_http_post_request
        else:
            get_http_request = self.get_http_get_request

        req = get_http_request(query, variables, operation_name, headers)

        self.logger.debug('Query:\n%s', query)

        try:
            with self.session if self.session is not None \
                    else requests.Session() as session:
                prepped = session.prepare_request(req)
                with session.send(prepped,
                                  timeout=timeout or self.timeout) as f:
                    try:
                        f.raise_for_status()
                        data = f.json()
                        if data and data.get('errors'):
                            return self._log_graphql_error(query, data)
                        return data
                    except json.JSONDecodeError as exc:
                        return self._log_json_error(f.text, exc)
        except requests.exceptions.HTTPError as exc:
            return self._log_http_error(query, req, exc)
def __call__ ( self , query , variables = None , # noqa: C901 operation_name = None , extra_headers = None , timeout = None ) : if isinstance ( query , bytes ) : query = query . decode ( 'utf-8' ) elif not isinstance ( query , str ) : # allows sgqlc.operation.Operation to be passed # and generate compact representation of the queries query = bytes ( query ) . decode ( 'utf-8' ) headers = self . base_headers . copy ( ) if extra_headers : headers . update ( extra_headers ) if 'Accept' not in headers : headers [ 'Accept' ] = 'application/json; charset=utf-8' if self . method . upper ( ) == 'POST' : get_http_request = self . get_http_post_request else : get_http_request = self . get_http_get_request req = get_http_request ( query , variables , operation_name , headers ) self . logger . debug ( 'Query:\n%s' , query ) try : with self . session if self . session is not None else requests . Session ( ) as session : prepped = session . prepare_request ( req ) with session . send ( prepped , timeout = timeout or self . timeout ) as f : try : f . raise_for_status ( ) data = f . json ( ) if data and data . get ( 'errors' ) : return self . _log_graphql_error ( query , data ) return data except json . JSONDecodeError as exc : return self . _log_json_error ( f . text , exc ) except requests . exceptions . HTTPError as exc : return self . _log_http_error ( query , req , exc )