# Path: commands/graphql.py
# def set_graphql_schema_on_view(view, req):
#     """If request was to a GraphQL endpoint, send introspection query on a separate
#     thread, parse response and set it on view.
#     """
#     if not req.skwargs.get('gql'):
#         return
# 
#     def _set(view, url):
#         """Ensure types and fields within types can be looked up quickly by name.
# 
#         `types` dict has the following format:
#             typeName -> typeDict
#         Within `typeDict`, `fields` dict has similar format:
#             fieldName -> fieldDict
#         """
#         kwargs = dict(req.kwargs)
#         kwargs.pop('params', None)
#         kwargs.pop('json', None)
#         kwargs['timeout'] = 3
# 
#         try:
#             response = requests.get(url, params={'query': introspection_query}, **kwargs)
#             schema = response.json()['data']['__schema']  # get root `Query` type
#             query_type = schema['queryType']['name']
#         except:
#             response = requests.post(url, json={'query': introspection_query}, **kwargs)
#             schema = response.json()['data']['__schema']  # get root `Query` type
#             query_type = schema['queryType']['name']
# 
#         types = {}
#         for t in schema['types']:
#             types[t['name']] = t
#             fields = {f['name']: f for f in (t['fields'] or [])}
#             t['fields'] = fields
# 
#         view.settings().set('requester.gql_schema', (query_type, types))
# 
#     thread = Thread(target=lambda: _set(view, req.url.split('?')[0]))
#     thread.start()


import sublime
import sublime_plugin
import os
import json
import time
from sys import maxsize
from urllib import parse
from collections import namedtuple
from ..deps.requests import options
from .graphql import set_graphql_schema_on_view
from ..core import RequestCommandMixin
from ..core.parsers import parse_requests
from ..core.responses import prepare_request
from ..core.helpers import clean_url, truncate
        if not len(views):  # if there are no matching response tabs, create a new one
            view = window.new_file()
            pinned = self.config.get('pin_tabs_by_default', False)
            if pinned:
                view.settings().set('requester.response_pinned', True)
        else:
            view = views[0]
        window.focus_sheet(requester_sheet)  # keep focus on requester view
        self.prepare_response_view(view, response)

    def prepare_response_view(self, view, response):
        """Insert response content into response view, and set settings on it.
        """
        req, res, err = response
        self._response_view = view  # cache this to change focus after all responses return
        view.set_scratch(True)

        # this setting allows keymap to target response views separately
        view.settings().set('requester.response_view', True)
        self.set_env_on_view(view)

        content, point = get_response_view_content(response)
        view.run_command('requester_replace_view_text', {'text': content, 'point': point})
        view.set_syntax_file('Packages/Requester/syntax/requester-response.sublime-syntax')
        set_request_on_view(view, response)

        # should response tabs be reordered after requests return?
        if self.config.get('reorder_tabs_after_requests', False):
            self.view.run_command('requester_reorder_response_tabs')
        set_response_view_name(view, response)

# Path: commands/graphql.py
# def set_graphql_schema_on_view(view, req):
#     """If request was to a GraphQL endpoint, send introspection query on a separate
#     thread, parse response and set it on view.
#     """
#     if not req.skwargs.get('gql'):
#         return
# 
#     def _set(view, url):
#         """Ensure types and fields within types can be looked up quickly by name.
# 
#         `types` dict has the following format:
#             typeName -> typeDict
#         Within `typeDict`, `fields` dict has similar format:
#             fieldName -> fieldDict
#         """
#         kwargs = dict(req.kwargs)
#         kwargs.pop('params', None)
#         kwargs.pop('json', None)
#         kwargs['timeout'] = 3
# 
#         try:
#             response = requests.get(url, params={'query': introspection_query}, **kwargs)
#             schema = response.json()['data']['__schema']  # get root `Query` type
#             query_type = schema['queryType']['name']
#         except:
#             response = requests.post(url, json={'query': introspection_query}, **kwargs)
#             schema = response.json()['data']['__schema']  # get root `Query` type
#             query_type = schema['queryType']['name']
# 
#         types = {}
#         for t in schema['types']:
#             types[t['name']] = t
#             fields = {f['name']: f for f in (t['fields'] or [])}
#             t['fields'] = fields
# 
#         view.settings().set('requester.gql_schema', (query_type, types))
# 
#     thread = Thread(target=lambda: _set(view, req.url.split('?')[0]))
#     thread.start()


# Path: commands/request.py
import sublime
import sublime_plugin
import os
import json
import time
from sys import maxsize
from urllib import parse
from collections import namedtuple
from ..deps.requests import options
from .graphql import set_graphql_schema_on_view
from ..core import RequestCommandMixin
from ..core.parsers import parse_requests
from ..core.responses import prepare_request
from ..core.helpers import clean_url, truncate

        if not len(views):  # if there are no matching response tabs, create a new one
            view = window.new_file()
            pinned = self.config.get('pin_tabs_by_default', False)
            if pinned:
                view.settings().set('requester.response_pinned', True)
        else:
            view = views[0]
        window.focus_sheet(requester_sheet)  # keep focus on requester view
        self.prepare_response_view(view, response)

    def prepare_response_view(self, view, response):
        """Insert response content into response view, and set settings on it.
        """
        req, res, err = response
        self._response_view = view  # cache this to change focus after all responses return
        view.set_scratch(True)

        # this setting allows keymap to target response views separately
        view.settings().set('requester.response_view', True)
        self.set_env_on_view(view)

        content, point = get_response_view_content(response)
        view.run_command('requester_replace_view_text', {'text': content, 'point': point})
        view.set_syntax_file('Packages/Requester/syntax/requester-response.sublime-syntax')
        set_request_on_view(view, response)

        # should response tabs be reordered after requests return?
        if self.config.get('reorder_tabs_after_requests', False):
            self.view.run_command('requester_reorder_response_tabs')
        set_response_view_name(view, response)

        set_graphql_schema_on_view(view, req)