예제 #1
0
def get_fields(info):
    fragments = {}
    node = ast_to_dict(info.field_asts[0])

    for name, value in info.fragments.items():
        fragments[name] = ast_to_dict(value)

    return collect_fields(node, fragments)
예제 #2
0
파일: utils.py 프로젝트: assembl/assembl
def get_fields(info):
    """Return a nested dict of the fields requested by a graphene resolver."""
    fragments = {}
    node = ast_to_dict(info.field_asts[0])

    for name, value in info.fragments.items():
        fragments[name] = ast_to_dict(value)

    fields = collect_fields(node, fragments, info.variable_values)
    return fields
def test_converts_simple_ast_to_dict():
    node = ast.Name(value='test', loc=Loc(start=5, end=10))

    assert ast_to_dict(node) == {'kind': 'Name', 'value': 'test'}
    assert ast_to_dict(node, include_loc=True) == {
        'kind': 'Name', 'value': 'test', 'loc': {
            'start': 5,
            'end': 10
        }
    }
예제 #4
0
def get_fields(info):
    """Return a nested dict of the fields requested by a graphene resolver."""
    fragments = {}
    node = ast_to_dict(info.field_asts[0])

    for name, value in info.fragments.items():
        fragments[name] = ast_to_dict(value)

    fields = collect_fields(node, fragments, info.variable_values)
    return fields
예제 #5
0
def test_converts_simple_ast_to_dict():
    node = ast.Name(value='test', loc=Loc(start=5, end=10))

    assert ast_to_dict(node) == {'kind': 'Name', 'value': 'test'}
    assert ast_to_dict(node, include_loc=True) == {
        'kind': 'Name',
        'value': 'test',
        'loc': {
            'start': 5,
            'end': 10
        }
    }
예제 #6
0
def test_converts_simple_ast_to_dict():
    node = ast.Name(value="test", loc=Loc(start=5, end=10))

    assert ast_to_dict(node) == {"kind": "Name", "value": "test"}
    assert ast_to_dict(node, include_loc=True) == {
        "kind": "Name",
        "value": "test",
        "loc": {
            "start": 5,
            "end": 10
        },
    }
def test(info):
    """A convenience function to call collect_fields with info
    Args:
        info (ResolveInfo)
    Returns:
        dict: Returned from collect_fields
    """
    prev_fragment_names = set()
    fragments = {}
    node = ast_to_dict(info.field_asts[0])
    for name, value in info.fragments.items():
        fragments[name] = ast_to_dict(value)

    return test_collect_fields(node, fragments)
예제 #8
0
def get_fields(info):
    if not info.field_asts:
        return {}

    node = ast_to_dict(info.field_asts[0])

    return collect_fields(node)
예제 #9
0
 def resolve_all_option_collections(self, info, **kwargs):
     field_map = {
         "option": ("option", "select"),
     }
     return helpers.optimize(OptionCollection.objects.all(),
                             ast_to_dict(info.field_asts),
                             field_map)
예제 #10
0
 def resolve_all_option_collections(self, args, context, info):
     field_map = {
         "option": ("option", "select"),
     }
     return helpers.optimize(OptionCollection.objects.all(),
                             ast_to_dict(info.field_asts),
                             field_map)
예제 #11
0
파일: schema.py 프로젝트: bclary/treeherder
 def resolve_all_option_collections(self, info, **kwargs):
     field_map = {
         "option": ("option", "select"),
     }
     return optimize(OptionCollection.objects.all(),
                     ast_to_dict(info.field_asts),
                     field_map)
예제 #12
0
def get_query_fields(info):
    """A convenience function to call collect_query_fields with info

    Args:
        info (ResolveInfo)

    Returns:
        dict: Returned from collect_query_fields
    """

    fragments = {}
    node = ast_to_dict(info.field_asts[0])

    for name, value in info.fragments.items():
        fragments[name] = ast_to_dict(value)

    query = collect_query_fields(node, fragments)
    if "edges" in query:
        return query["edges"]["node"].keys()
    return query
 def resolve_jobs(self, info, **kwargs):
     field_map = {
         "buildPlatform": ("build_platform", "select"),
         "jobLog": ("job_log", "prefetch"),
         "jobType": ("job_type", "select"),
         "jobGroup": ("job_group", "select"),
         "failureClassification": ("failure_classification", "prefetch"),
         "failureLine": ("job_log__failure_line", "prefetch"),
         "group": ("job_log__failure_line__group", "prefetch"),
         "textLogStep": ("text_log_step", "prefetch"),
         "errors": ("text_log_step__errors", "prefetch"),
     }
     return optimize(Job.objects.filter(push=self, **kwargs),
                     ast_to_dict(info.field_asts), field_map)
예제 #14
0
파일: schema.py 프로젝트: bclary/treeherder
 def resolve_jobs(self, info, **kwargs):
     field_map = {
         "buildPlatform": ("build_platform", "select"),
         "jobLog": ("job_log", "prefetch"),
         "jobType": ("job_type", "select"),
         "jobGroup": ("job_group", "select"),
         "failureClassification": ("failure_classification", "prefetch"),
         "failureLine": ("job_log__failure_line", "prefetch"),
         "group": ("job_log__failure_line__group", "prefetch"),
         "textLogStep": ("text_log_step", "prefetch"),
         "errors": ("text_log_step__errors", "prefetch"),
     }
     return optimize(Job.objects.filter(push=self, **kwargs),
                     ast_to_dict(info.field_asts),
                     field_map)
예제 #15
0
def get_fields(info):
    """Return a nested dict of the fields requested by a graphene resolver"""
    node = ast_to_dict(info.field_asts)

    return collect_fields(node)
def test_converts_nested_ast_to_dict():
    parsed_ast = parse('''
        query x {
            someQuery(arg: "x") {
                a
                b
            }
            fragment Test on TestFoo {
                c
                d
            }
        }
    ''')

    expected_ast_dict = {'definitions': [{'directives': [],
                                          'kind': 'OperationDefinition',
                                          'name': {'kind': 'Name', 'value': 'x'},
                                          'operation': 'query',
                                          'selection_set': {'kind': 'SelectionSet',
                                                            'selections': [{'alias': None,
                                                                            'arguments': [{'kind': 'Argument',
                                                                                           'name': {'kind': 'Name',
                                                                                                    'value': 'arg'},
                                                                                           'value': {
                                                                                               'kind': 'StringValue',
                                                                                               'value': 'x'}}],
                                                                            'directives': [],
                                                                            'kind': 'Field',
                                                                            'name': {'kind': 'Name',
                                                                                     'value': 'someQuery'},
                                                                            'selection_set': {'kind': 'SelectionSet',
                                                                                              'selections': [
                                                                                                  {'alias': None,
                                                                                                   'arguments': [],
                                                                                                   'directives': [],
                                                                                                   'kind': 'Field',
                                                                                                   'name': {
                                                                                                       'kind': 'Name',
                                                                                                       'value': 'a'},
                                                                                                   'selection_set': None},
                                                                                                  {'alias': None,
                                                                                                   'arguments': [],
                                                                                                   'directives': [],
                                                                                                   'kind': 'Field',
                                                                                                   'name': {
                                                                                                       'kind': 'Name',
                                                                                                       'value': 'b'},
                                                                                                   'selection_set': None}]}},
                                                                           {'alias': None,
                                                                            'arguments': [],
                                                                            'directives': [],
                                                                            'kind': 'Field',
                                                                            'name': {'kind': 'Name',
                                                                                     'value': 'fragment'},
                                                                            'selection_set': None},
                                                                           {'alias': None,
                                                                            'arguments': [],
                                                                            'directives': [],
                                                                            'kind': 'Field',
                                                                            'name': {'kind': 'Name',
                                                                                     'value': 'Test'},
                                                                            'selection_set': None},
                                                                           {'alias': None,
                                                                            'arguments': [],
                                                                            'directives': [],
                                                                            'kind': 'Field',
                                                                            'name': {'kind': 'Name',
                                                                                     'value': 'on'},
                                                                            'selection_set': None},
                                                                           {'alias': None,
                                                                            'arguments': [],
                                                                            'directives': [],
                                                                            'kind': 'Field',
                                                                            'name': {'kind': 'Name',
                                                                                     'value': 'TestFoo'},
                                                                            'selection_set': {'kind': 'SelectionSet',
                                                                                              'selections': [
                                                                                                  {'alias': None,
                                                                                                   'arguments': [],
                                                                                                   'directives': [],
                                                                                                   'kind': 'Field',
                                                                                                   'name': {
                                                                                                       'kind': 'Name',
                                                                                                       'value': 'c'},
                                                                                                   'selection_set': None},
                                                                                                  {'alias': None,
                                                                                                   'arguments': [],
                                                                                                   'directives': [],
                                                                                                   'kind': 'Field',
                                                                                                   'name': {
                                                                                                       'kind': 'Name',
                                                                                                       'value': 'd'},
                                                                                                   'selection_set': None}]}}]},
                                          'variable_definitions': []}],
                         'kind': 'Document'}

    assert ast_to_dict(parsed_ast) == expected_ast_dict
예제 #17
0
def test_converts_nested_ast_to_dict():
    parsed_ast = parse("""
        query x {
            someQuery(arg: "x") {
                a
                b
            }
            fragment Test on TestFoo {
                c
                d
            }
        }
    """)

    expected_ast_dict = {
        "definitions": [{
            "directives": [],
            "kind": "OperationDefinition",
            "name": {
                "kind": "Name",
                "value": "x"
            },
            "operation": "query",
            "selection_set": {
                "kind":
                "SelectionSet",
                "selections": [
                    {
                        "alias":
                        None,
                        "arguments": [{
                            "kind": "Argument",
                            "name": {
                                "kind": "Name",
                                "value": "arg"
                            },
                            "value": {
                                "kind": "StringValue",
                                "value": "x"
                            },
                        }],
                        "directives": [],
                        "kind":
                        "Field",
                        "name": {
                            "kind": "Name",
                            "value": "someQuery"
                        },
                        "selection_set": {
                            "kind":
                            "SelectionSet",
                            "selections": [
                                {
                                    "alias": None,
                                    "arguments": [],
                                    "directives": [],
                                    "kind": "Field",
                                    "name": {
                                        "kind": "Name",
                                        "value": "a"
                                    },
                                    "selection_set": None,
                                },
                                {
                                    "alias": None,
                                    "arguments": [],
                                    "directives": [],
                                    "kind": "Field",
                                    "name": {
                                        "kind": "Name",
                                        "value": "b"
                                    },
                                    "selection_set": None,
                                },
                            ],
                        },
                    },
                    {
                        "alias": None,
                        "arguments": [],
                        "directives": [],
                        "kind": "Field",
                        "name": {
                            "kind": "Name",
                            "value": "fragment"
                        },
                        "selection_set": None,
                    },
                    {
                        "alias": None,
                        "arguments": [],
                        "directives": [],
                        "kind": "Field",
                        "name": {
                            "kind": "Name",
                            "value": "Test"
                        },
                        "selection_set": None,
                    },
                    {
                        "alias": None,
                        "arguments": [],
                        "directives": [],
                        "kind": "Field",
                        "name": {
                            "kind": "Name",
                            "value": "on"
                        },
                        "selection_set": None,
                    },
                    {
                        "alias": None,
                        "arguments": [],
                        "directives": [],
                        "kind": "Field",
                        "name": {
                            "kind": "Name",
                            "value": "TestFoo"
                        },
                        "selection_set": {
                            "kind":
                            "SelectionSet",
                            "selections": [
                                {
                                    "alias": None,
                                    "arguments": [],
                                    "directives": [],
                                    "kind": "Field",
                                    "name": {
                                        "kind": "Name",
                                        "value": "c"
                                    },
                                    "selection_set": None,
                                },
                                {
                                    "alias": None,
                                    "arguments": [],
                                    "directives": [],
                                    "kind": "Field",
                                    "name": {
                                        "kind": "Name",
                                        "value": "d"
                                    },
                                    "selection_set": None,
                                },
                            ],
                        },
                    },
                ],
            },
            "variable_definitions": [],
        }],
        "kind":
        "Document",
    }

    assert ast_to_dict(parsed_ast) == expected_ast_dict
예제 #18
0
def test_converts_nested_ast_to_dict():
    parsed_ast = parse('''
        query x {
            someQuery(arg: "x") {
                a
                b
            }
            fragment Test on TestFoo {
                c
                d
            }
        }
    ''')

    expected_ast_dict = {
        'definitions': [{
            'directives': [],
            'kind': 'OperationDefinition',
            'name': {
                'kind': 'Name',
                'value': 'x'
            },
            'operation': 'query',
            'selection_set': {
                'kind':
                'SelectionSet',
                'selections': [{
                    'alias':
                    None,
                    'arguments': [{
                        'kind': 'Argument',
                        'name': {
                            'kind': 'Name',
                            'value': 'arg'
                        },
                        'value': {
                            'kind': 'StringValue',
                            'value': 'x'
                        }
                    }],
                    'directives': [],
                    'kind':
                    'Field',
                    'name': {
                        'kind': 'Name',
                        'value': 'someQuery'
                    },
                    'selection_set': {
                        'kind':
                        'SelectionSet',
                        'selections': [{
                            'alias': None,
                            'arguments': [],
                            'directives': [],
                            'kind': 'Field',
                            'name': {
                                'kind': 'Name',
                                'value': 'a'
                            },
                            'selection_set': None
                        }, {
                            'alias': None,
                            'arguments': [],
                            'directives': [],
                            'kind': 'Field',
                            'name': {
                                'kind': 'Name',
                                'value': 'b'
                            },
                            'selection_set': None
                        }]
                    }
                }, {
                    'alias': None,
                    'arguments': [],
                    'directives': [],
                    'kind': 'Field',
                    'name': {
                        'kind': 'Name',
                        'value': 'fragment'
                    },
                    'selection_set': None
                }, {
                    'alias': None,
                    'arguments': [],
                    'directives': [],
                    'kind': 'Field',
                    'name': {
                        'kind': 'Name',
                        'value': 'Test'
                    },
                    'selection_set': None
                }, {
                    'alias': None,
                    'arguments': [],
                    'directives': [],
                    'kind': 'Field',
                    'name': {
                        'kind': 'Name',
                        'value': 'on'
                    },
                    'selection_set': None
                }, {
                    'alias': None,
                    'arguments': [],
                    'directives': [],
                    'kind': 'Field',
                    'name': {
                        'kind': 'Name',
                        'value': 'TestFoo'
                    },
                    'selection_set': {
                        'kind':
                        'SelectionSet',
                        'selections': [{
                            'alias': None,
                            'arguments': [],
                            'directives': [],
                            'kind': 'Field',
                            'name': {
                                'kind': 'Name',
                                'value': 'c'
                            },
                            'selection_set': None
                        }, {
                            'alias': None,
                            'arguments': [],
                            'directives': [],
                            'kind': 'Field',
                            'name': {
                                'kind': 'Name',
                                'value': 'd'
                            },
                            'selection_set': None
                        }]
                    }
                }]
            },
            'variable_definitions': []
        }],
        'kind':
        'Document'
    }

    assert ast_to_dict(parsed_ast) == expected_ast_dict