Esempio n. 1
0
def test_any_in_option():
    graph = Graph([
        Root([
            Field('get', None, None, options=[
                Option('foo', Mapping[String, Any]),
            ]),
        ]),
    ])
    assert validate(graph, q.Node([
        q.Field('get', options={'foo': {u'key': 1}}),
    ])) == []
    assert validate(graph, q.Node([
        q.Field('get', options={'foo': 'bar'}),
    ])) == ['Invalid value for option "root.get:foo", '
            '"str" instead of Mapping[String, Any]']
Esempio n. 2
0
def test_typeref_in_option():
    data_types = {
        'Foo': Record[{
            'key': Integer,
        }],
    }
    graph = Graph([
        Root([
            Field('get', None, None, options=[Option('foo', TypeRef['Foo'])]),
        ]),
    ], data_types=data_types)
    assert validate(graph, q.Node([
        q.Field('get', options={'foo': {'key': 1}}),
    ])) == []
    assert validate(graph, q.Node([
        q.Field('get', options={'foo': {'key': '1'}}),
    ])) == ['Invalid value for option "root.get:foo", "str" instead of Integer']
def introspect(graph):
    engine = Engine(SyncExecutor())
    graph = apply(graph, [GraphQLIntrospection()])

    query = read(QUERY)
    errors = validate(graph, query)
    assert not errors

    norm_result = engine.execute(graph, query)
    return denormalize(graph, norm_result, query)
Esempio n. 4
0
def introspect(query_graph, mutation_graph=None):
    engine = Engine(SyncExecutor())
    query_graph = apply(query_graph, [
        GraphQLIntrospection(query_graph, mutation_graph),
    ])

    query = read(QUERY)
    errors = validate(query_graph, query)
    assert not errors

    norm_result = engine.execute(query_graph, query)
    return denormalize(query_graph, norm_result)
Esempio n. 5
0
async def handler(request):
    hiku_engine = request.app['HIKU_ENGINE']
    data = await request.json()
    try:
        query = read(data['query'], data.get('variables'))
        errors = validate(request.app['GRAPH'], query)
        if errors:
            result = {'errors': [{'message': e} for e in errors]}
        else:
            result = await hiku_engine.execute(request.app['GRAPH'], query)
            result = {'data': denormalize(request.app['GRAPH'], result, query)}
    except Exception as err:
        result = {'errors': [{'message': repr(err)}]}
    return web.json_response(result)
Esempio n. 6
0
def handler():
    hiku_engine = app.config['HIKU_ENGINE']
    data = request.get_json()
    try:
        query = read(data['query'], data.get('variables'))
        errors = validate(app.config['GRAPH'], query)
        if errors:
            result = {'errors': [{'message': e} for e in errors]}
        else:
            result = hiku_engine.execute(app.config['GRAPH'],
                                         query,
                                         ctx=app.config['HIKU_CTX'])
            result = {'data': denormalize(app.config['GRAPH'], result, query)}
    except Exception as err:
        result = {'errors': [{'message': repr(err)}]}
    return jsonify(result)
Esempio n. 7
0
def test_distinct_by_options_links():
    graph = Graph([
        Node('X', [
            Field('a', None, None),
        ]),
        Root([
            Link('x', TypeRef['X'], None, requires=None,
                 options=[Option('e', Optional[Integer], default=None)]),
        ]),
    ])
    errors = validate(graph, q.Node([
        q.Link('x', q.Node([q.Field('a')])),
        q.Link('x', q.Node([q.Field('a')]), options={'e': 1}),
    ]))
    assert errors == [
        'Found distinct fields with the same resulting name "x" for the '
        'node "root"'
    ]
Esempio n. 8
0
def test_distinct_by_name_links():
    graph = Graph([
        Node('X', [
            Field('a', None, None),
        ]),
        Root([
            Link('x1', TypeRef['X'], None, requires=None),
            Link('x2', TypeRef['X'], None, requires=None),
        ]),
    ])
    errors = validate(graph, q.Node([
        q.Link('x1', q.Node([q.Field('a')])),
        q.Link('x2', q.Node([q.Field('a')]), alias='x1'),
    ]))
    assert errors == [
        'Found distinct fields with the same resulting name "x1" for the '
        'node "root"'
    ]
Esempio n. 9
0
def check_option_errors(options, query_options, errors):
    graph = Graph([Root([Field('glinty', None, _, options=options)])])
    query = q.Node([q.Field('glinty', options=query_options)])
    assert validate(graph, query) == [e.format(field='root.glinty')
                                      for e in errors]
Esempio n. 10
0
def check_errors(query, errors):
    assert validate(GRAPH, query) == errors