{"action":"created","comment":{"url":"https://api.github.com/repos/dittos/graphqllib/pulls/comments/40170638","id":40170638,"diff_hunk":"@@ -0,0 +1,287 @@\n+import collections\n+import functools\n+\n+from graphql.core import ExecutionResult, Source, parse, validate\n+from graphql.core.defer import Deferred, DeferredDict, DeferredList, defer, fail, succeed\n+from graphql.core.error import GraphQLError, format_error\n+from graphql.core.execution import ExecutionContext, ResolveInfo, Undefined, collect_fields, default_resolve_fn, \\\n+    get_argument_values, get_field_def, get_operation_root_type\n+from graphql.core.language import ast\n+from graphql.core.type import GraphQLEnumType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, \\\n+    GraphQLScalarType, GraphQLUnionType\n+from graphql.core.utils import is_nullish\n+\n+\n+class Executor(object):\n+    def __init__(self, schema, execution_middlewares=None):\n+        self.execution_middlewares = execution_middlewares or []\n+        self.schema = schema\n+\n+    def execute(self, request='', root=None, args=None, operation_name=None, execute_serially=False, validate_ast=True):\n+        if not isinstance(request, ast.Document):\n+            if not isinstance(request, Source):\n+                request = Source(request, 'GraphQL request')\n+\n+            request = parse(request)\n+\n+        if validate_ast:\n+            validation_errors = validate(self.schema, request)\n+            if validation_errors:\n+                return ExecutionResult(\n+                    data=None,\n+                    errors=validation_errors,\n+                )\n+\n+        curried_execution_function = functools.partial(\n+            self._execute_graphql_query,\n+            root or object(),\n+            request,\n+            operation_name,\n+            args or {},\n+            execute_serially)\n+\n+        for middleware in self.execution_middlewares:\n+            if hasattr(middleware, 'execution_result'):\n+                curried_execution_function = functools.partial(middleware.execution_result, curried_execution_function)\n+\n+        return curried_execution_function()\n+\n+    def _execute_graphql_query(self, root, ast, operation_name, args, execute_serially=False):\n+        ctx = ExecutionContext(self.schema, root, ast, operation_name, args)\n+\n+        d = defer(self._execute_operation, ctx, root, ctx.operation, execute_serially)\n+        d.add_errback(\n+            lambda error: ctx.errors.append(error)","path":"graphql/core/execution/parallel_execution.py","position":54,"original_position":54,"commit_id":"a34e6e164e864c14d150fd571ec52d55f1f78f4b","original_commit_id":"a34e6e164e864c14d150fd571ec52d55f1f78f4b","user":{"login":"dittos","id":2622,"avatar_url":"https://avatars.githubusercontent.com/u/2622?v=3","gravatar_id":"","url":"https://api.github.com/users/dittos","html_url":"https://github.com/dittos","followers_url":"https://api.github.com/users/dittos/followers","following_url":"https://api.github.com/users/dittos/following{/other_user}","gists_url":"https://api.github.com/users/dittos/gists{/gist_id}","starred_url":"https://api.github.com/users/dittos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dittos/subscriptions","organizations_url":"https://api.github.com/users/dittos/orgs","repos_url":"https://api.github.com/users/dittos/repos","events_url":"https://api.github.com/users/dittos/events{/privacy}","received_events_url":"https://api.github.com/users/dittos/received_events","type":"User","site_admin":false},"body":"Return `ExecutionResult(None, list(map(format_error, ctx.errors)))` here?","created_at":"2015-09-23T04:43:54Z","updated_at":"2015-09-23T04:43:54Z","html_url":"https://github.com/dittos/graphqllib/pull/51#discussion_r40170638","pull_request_url":"https://api.github.com/repos/dittos/graphqllib/pulls/51","_links":{"self":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/comments/40170638"},"html":{"href":"https://github.com/dittos/graphqllib/pull/51#discussion_r40170638"},"pull_request":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/51"}}},"pull_request":{"url":"https://api.github.com/repos/dittos/graphqllib/pulls/51","id":45724143,"html_url":"https://github.com/dittos/graphqllib/pull/51","diff_url":"https://github.com/dittos/graphqllib/pull/51.diff","patch_url":"https://github.com/dittos/graphqllib/pull/51.patch","issue_url":"https://api.github.com/repos/dittos/graphqllib/issues/51","number":51,"state":"open","locked":false,"title":"[WIP] Initial Parallel Execution Concept","user":{"login":"jhgg","id":5489149,"avatar_url":"https://avatars.githubusercontent.com/u/5489149?v=3","gravatar_id":"","url":"https://api.github.com/users/jhgg","html_url":"https://github.com/jhgg","followers_url":"https://api.github.com/users/jhgg/followers","following_url":"https://api.github.com/users/jhgg/following{/other_user}","gists_url":"https://api.github.com/users/jhgg/gists{/gist_id}","starred_url":"https://api.github.com/users/jhgg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhgg/subscriptions","organizations_url":"https://api.github.com/users/jhgg/orgs","repos_url":"https://api.github.com/users/jhgg/repos","events_url":"https://api.github.com/users/jhgg/events{/privacy}","received_events_url":"https://api.github.com/users/jhgg/received_events","type":"User","site_admin":false},"body":"#28 - I’ve taken apart the Executor and put it back together. This is the initial concept of Parallel Execution. \r\n\r\nSo, I've finished up the execution engine, supporting parallel execution of each resolved fields. Born from this was an `Executor`, which can be configured to support multiple `Execution Middlewares`. For now, we have a `SynchronousExecutionMiddleware`, which when provided will make the Executor behave like the current synchronous one. \r\n\r\nThis is a proof of concept about my pluggable execution idea. You can see the limited tests in `tests/core_execution/parallel_executor.py`. \r\n\r\n- [ ] Write more unit tests and figure out bugs.\r\n- [x] Fix error propegation when a NonNullable field throws an error.\r\n- [X] Write asyncio middleware.  https://github.com/jhgg/graphqllib/commit/208b0a152b0145ee79a26a31beae83b1ac69be53\r\n- [ ] Write greenlet/thread middleware. ","created_at":"2015-09-22T22:15:15Z","updated_at":"2015-09-23T04:43:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f542fcd45e730ee40b736e7d516ee428bc3ad635","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dittos/graphqllib/pulls/51/commits","review_comments_url":"https://api.github.com/repos/dittos/graphqllib/pulls/51/comments","review_comment_url":"https://api.github.com/repos/dittos/graphqllib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dittos/graphqllib/issues/51/comments","statuses_url":"https://api.github.com/repos/dittos/graphqllib/statuses/a34e6e164e864c14d150fd571ec52d55f1f78f4b","head":{"label":"jhgg:parallel-execution","ref":"parallel-execution","sha":"a34e6e164e864c14d150fd571ec52d55f1f78f4b","user":{"login":"jhgg","id":5489149,"avatar_url":"https://avatars.githubusercontent.com/u/5489149?v=3","gravatar_id":"","url":"https://api.github.com/users/jhgg","html_url":"https://github.com/jhgg","followers_url":"https://api.github.com/users/jhgg/followers","following_url":"https://api.github.com/users/jhgg/following{/other_user}","gists_url":"https://api.github.com/users/jhgg/gists{/gist_id}","starred_url":"https://api.github.com/users/jhgg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhgg/subscriptions","organizations_url":"https://api.github.com/users/jhgg/orgs","repos_url":"https://api.github.com/users/jhgg/repos","events_url":"https://api.github.com/users/jhgg/events{/privacy}","received_events_url":"https://api.github.com/users/jhgg/received_events","type":"User","site_admin":false},"repo":{"id":42663986,"name":"graphqllib","full_name":"jhgg/graphqllib","owner":{"login":"jhgg","id":5489149,"avatar_url":"https://avatars.githubusercontent.com/u/5489149?v=3","gravatar_id":"","url":"https://api.github.com/users/jhgg","html_url":"https://github.com/jhgg","followers_url":"https://api.github.com/users/jhgg/followers","following_url":"https://api.github.com/users/jhgg/following{/other_user}","gists_url":"https://api.github.com/users/jhgg/gists{/gist_id}","starred_url":"https://api.github.com/users/jhgg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhgg/subscriptions","organizations_url":"https://api.github.com/users/jhgg/orgs","repos_url":"https://api.github.com/users/jhgg/repos","events_url":"https://api.github.com/users/jhgg/events{/privacy}","received_events_url":"https://api.github.com/users/jhgg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jhgg/graphqllib","description":"GraphQL implementation for Python","fork":true,"url":"https://api.github.com/repos/jhgg/graphqllib","forks_url":"https://api.github.com/repos/jhgg/graphqllib/forks","keys_url":"https://api.github.com/repos/jhgg/graphqllib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jhgg/graphqllib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jhgg/graphqllib/teams","hooks_url":"https://api.github.com/repos/jhgg/graphqllib/hooks","issue_events_url":"https://api.github.com/repos/jhgg/graphqllib/issues/events{/number}","events_url":"https://api.github.com/repos/jhgg/graphqllib/events","assignees_url":"https://api.github.com/repos/jhgg/graphqllib/assignees{/user}","branches_url":"https://api.github.com/repos/jhgg/graphqllib/branches{/branch}","tags_url":"https://api.github.com/repos/jhgg/graphqllib/tags","blobs_url":"https://api.github.com/repos/jhgg/graphqllib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jhgg/graphqllib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jhgg/graphqllib/git/refs{/sha}","trees_url":"https://api.github.com/repos/jhgg/graphqllib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jhgg/graphqllib/statuses/{sha}","languages_url":"https://api.github.com/repos/jhgg/graphqllib/languages","stargazers_url":"https://api.github.com/repos/jhgg/graphqllib/stargazers","contributors_url":"https://api.github.com/repos/jhgg/graphqllib/contributors","subscribers_url":"https://api.github.com/repos/jhgg/graphqllib/subscribers","subscription_url":"https://api.github.com/repos/jhgg/graphqllib/subscription","commits_url":"https://api.github.com/repos/jhgg/graphqllib/commits{/sha}","git_commits_url":"https://api.github.com/repos/jhgg/graphqllib/git/commits{/sha}","comments_url":"https://api.github.com/repos/jhgg/graphqllib/comments{/number}","issue_comment_url":"https://api.github.com/repos/jhgg/graphqllib/issues/comments{/number}","contents_url":"https://api.github.com/repos/jhgg/graphqllib/contents/{+path}","compare_url":"https://api.github.com/repos/jhgg/graphqllib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jhgg/graphqllib/merges","archive_url":"https://api.github.com/repos/jhgg/graphqllib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jhgg/graphqllib/downloads","issues_url":"https://api.github.com/repos/jhgg/graphqllib/issues{/number}","pulls_url":"https://api.github.com/repos/jhgg/graphqllib/pulls{/number}","milestones_url":"https://api.github.com/repos/jhgg/graphqllib/milestones{/number}","notifications_url":"https://api.github.com/repos/jhgg/graphqllib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jhgg/graphqllib/labels{/name}","releases_url":"https://api.github.com/repos/jhgg/graphqllib/releases{/id}","created_at":"2015-09-17T15:20:15Z","updated_at":"2015-09-19T20:02:08Z","pushed_at":"2015-09-23T04:29:48Z","git_url":"git://github.com/jhgg/graphqllib.git","ssh_url":"git@github.com:jhgg/graphqllib.git","clone_url":"https://github.com/jhgg/graphqllib.git","svn_url":"https://github.com/jhgg/graphqllib","homepage":"","size":425,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dittos:master","ref":"master","sha":"6a121fc72fa067345264470529f02c5364d159d5","user":{"login":"dittos","id":2622,"avatar_url":"https://avatars.githubusercontent.com/u/2622?v=3","gravatar_id":"","url":"https://api.github.com/users/dittos","html_url":"https://github.com/dittos","followers_url":"https://api.github.com/users/dittos/followers","following_url":"https://api.github.com/users/dittos/following{/other_user}","gists_url":"https://api.github.com/users/dittos/gists{/gist_id}","starred_url":"https://api.github.com/users/dittos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dittos/subscriptions","organizations_url":"https://api.github.com/users/dittos/orgs","repos_url":"https://api.github.com/users/dittos/repos","events_url":"https://api.github.com/users/dittos/events{/privacy}","received_events_url":"https://api.github.com/users/dittos/received_events","type":"User","site_admin":false},"repo":{"id":38499908,"name":"graphqllib","full_name":"dittos/graphqllib","owner":{"login":"dittos","id":2622,"avatar_url":"https://avatars.githubusercontent.com/u/2622?v=3","gravatar_id":"","url":"https://api.github.com/users/dittos","html_url":"https://github.com/dittos","followers_url":"https://api.github.com/users/dittos/followers","following_url":"https://api.github.com/users/dittos/following{/other_user}","gists_url":"https://api.github.com/users/dittos/gists{/gist_id}","starred_url":"https://api.github.com/users/dittos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dittos/subscriptions","organizations_url":"https://api.github.com/users/dittos/orgs","repos_url":"https://api.github.com/users/dittos/repos","events_url":"https://api.github.com/users/dittos/events{/privacy}","received_events_url":"https://api.github.com/users/dittos/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dittos/graphqllib","description":"GraphQL implementation for Python","fork":false,"url":"https://api.github.com/repos/dittos/graphqllib","forks_url":"https://api.github.com/repos/dittos/graphqllib/forks","keys_url":"https://api.github.com/repos/dittos/graphqllib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dittos/graphqllib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dittos/graphqllib/teams","hooks_url":"https://api.github.com/repos/dittos/graphqllib/hooks","issue_events_url":"https://api.github.com/repos/dittos/graphqllib/issues/events{/number}","events_url":"https://api.github.com/repos/dittos/graphqllib/events","assignees_url":"https://api.github.com/repos/dittos/graphqllib/assignees{/user}","branches_url":"https://api.github.com/repos/dittos/graphqllib/branches{/branch}","tags_url":"https://api.github.com/repos/dittos/graphqllib/tags","blobs_url":"https://api.github.com/repos/dittos/graphqllib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dittos/graphqllib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dittos/graphqllib/git/refs{/sha}","trees_url":"https://api.github.com/repos/dittos/graphqllib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dittos/graphqllib/statuses/{sha}","languages_url":"https://api.github.com/repos/dittos/graphqllib/languages","stargazers_url":"https://api.github.com/repos/dittos/graphqllib/stargazers","contributors_url":"https://api.github.com/repos/dittos/graphqllib/contributors","subscribers_url":"https://api.github.com/repos/dittos/graphqllib/subscribers","subscription_url":"https://api.github.com/repos/dittos/graphqllib/subscription","commits_url":"https://api.github.com/repos/dittos/graphqllib/commits{/sha}","git_commits_url":"https://api.github.com/repos/dittos/graphqllib/git/commits{/sha}","comments_url":"https://api.github.com/repos/dittos/graphqllib/comments{/number}","issue_comment_url":"https://api.github.com/repos/dittos/graphqllib/issues/comments{/number}","contents_url":"https://api.github.com/repos/dittos/graphqllib/contents/{+path}","compare_url":"https://api.github.com/repos/dittos/graphqllib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dittos/graphqllib/merges","archive_url":"https://api.github.com/repos/dittos/graphqllib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dittos/graphqllib/downloads","issues_url":"https://api.github.com/repos/dittos/graphqllib/issues{/number}","pulls_url":"https://api.github.com/repos/dittos/graphqllib/pulls{/number}","milestones_url":"https://api.github.com/repos/dittos/graphqllib/milestones{/number}","notifications_url":"https://api.github.com/repos/dittos/graphqllib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dittos/graphqllib/labels{/name}","releases_url":"https://api.github.com/repos/dittos/graphqllib/releases{/id}","created_at":"2015-07-03T15:43:27Z","updated_at":"2015-09-22T20:36:51Z","pushed_at":"2015-09-23T04:29:48Z","git_url":"git://github.com/dittos/graphqllib.git","ssh_url":"git@github.com:dittos/graphqllib.git","clone_url":"https://github.com/dittos/graphqllib.git","svn_url":"https://github.com/dittos/graphqllib","homepage":"","size":677,"stargazers_count":72,"watchers_count":72,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":72,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/51"},"html":{"href":"https://github.com/dittos/graphqllib/pull/51"},"issue":{"href":"https://api.github.com/repos/dittos/graphqllib/issues/51"},"comments":{"href":"https://api.github.com/repos/dittos/graphqllib/issues/51/comments"},"review_comments":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/51/comments"},"review_comment":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dittos/graphqllib/pulls/51/commits"},"statuses":{"href":"https://api.github.com/repos/dittos/graphqllib/statuses/a34e6e164e864c14d150fd571ec52d55f1f78f4b"}}}}