当前位置: 首页>>代码示例>>Python>>正文


Python error.GraphQLError方法代码示例

本文整理汇总了Python中graphql.error.GraphQLError方法的典型用法代码示例。如果您正苦于以下问题:Python error.GraphQLError方法的具体用法?Python error.GraphQLError怎么用?Python error.GraphQLError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphql.error的用法示例。


在下文中一共展示了error.GraphQLError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_errors

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def convert_errors(
    errs: List[gql_error.GraphQLError], *,
    substitutions: Optional[Dict[str, Tuple[str, int, int]]],
) -> List[gql_error.GraphQLErrors]:
    result = []
    for err in errs:
        m = REWRITE_TYPE_ERROR.match(err.message)
        if not m:
            # we allow conversion from Int to Float, and that is allowed by
            # graphql spec. It's unclear why graphql-core chokes on this
            if INT_FLOAT_ERROR.match(err.message):
                continue

            result.append(err)
            continue
        if (m.group("used"), m.group("expected")) in _IMPLICIT_CONVERSIONS:
            # skip the error, we avoid it in the execution code
            continue
        value, line, col = substitutions[m.group("var_name")]
        err = gql_error.GraphQLError(
            f"Expected type {m.group('expected')}, found {value}.")
        err.locations = [gql_lang.SourceLocation(line, col)]
        result.append(err)
    return result 
开发者ID:edgedb,项目名称:edgedb,代码行数:26,代码来源:translator.py

示例2: describe_located_error

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def describe_located_error():
    def throws_without_an_original_error():
        with raises(TypeError) as exc_info:
            # noinspection PyTypeChecker
            located_error([], [], [])  # type: ignore
        assert str(exc_info.value) == "Expected an Exception."

    def passes_graphql_error_through():
        path = ["path", 3, "to", "field"]
        e = GraphQLError("msg", None, None, None, cast(Any, path))
        assert located_error(e, [], []) == e

    def passes_graphql_error_ish_through():
        e = GraphQLError("I am a located GraphQL error")
        e.path = []
        assert located_error(e, [], []) is e

    def does_not_pass_through_elasticsearch_like_errors():
        e = Exception("I am from elasticsearch")
        cast(Any, e).path = "/something/feed/_search"
        assert located_error(e, [], []) is not e 
开发者ID:graphql-python,项目名称:graphql-core,代码行数:23,代码来源:test_located_error.py

示例3: describe_assert_valid_name

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def describe_assert_valid_name():
    def pass_through_valid_name():
        assert assert_valid_name("_ValidName123") == "_ValidName123"

    def throws_for_use_of_leading_double_underscore():
        with raises(GraphQLError) as exc_info:
            assert assert_valid_name("__bad")
        msg = exc_info.value.message
        assert msg == (
            "Name '__bad' must not begin with '__',"
            " which is reserved by GraphQL introspection."
        )

    def throws_for_non_strings():
        with raises(TypeError) as exc_info:
            # noinspection PyTypeChecker
            assert_valid_name({})  # type: ignore
        msg = str(exc_info.value)
        assert msg == "Expected name to be a string."

    def throws_for_names_with_invalid_characters():
        with raises(GraphQLError, match="Names must match"):
            assert_valid_name(">--()-->") 
开发者ID:graphql-python,项目名称:graphql-core,代码行数:25,代码来源:test_assert_valid_name.py

示例4: get_node

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def get_node(cls, info, node_id, field='id', only_type=None):
        """Get the node object given a relay global id."""
        if not node_id:
            return None

        try:
            node = get_node(node_id, only_type)
        except (AssertionError, GraphQLError) as e:
            raise ValidationError({field: str(e)})
        else:
            if node is None:  # pragma: no cover
                raise ValidationError(
                    {field: "Couldn't resolve to a node: {}".format(node_id)}
                )

        return node 
开发者ID:0soft,项目名称:graphene-django-plus,代码行数:18,代码来源:mutations.py

示例5: test_errors_on_deep_nested_errors_and_with_many_errors

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_errors_on_deep_nested_errors_and_with_many_errors(self):
        # type: () -> None
        nested_doc = """
          query q($input: TestNestedInputObject) {
            fieldWithNestedObjectInput(input: $input)
          }
        """

        params = {"input": {"na": {"a": "foo"}}}
        with raises(GraphQLError) as excinfo:
            check(nested_doc, {}, params)

        assert format_error(excinfo.value) == {
            "locations": [{"column": 19, "line": 2}],
            "message": 'Variable "$input" got invalid value {}.\n'
            'In field "na": In field "c": Expected "String!", found null.\n'
            'In field "nb": Expected "String!", found null.'.format(
                stringify(params["input"])
            ),
        } 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:22,代码来源:test_variables.py

示例6: test_does_not_allow_lists_of_non_nulls_to_contain_null

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_does_not_allow_lists_of_non_nulls_to_contain_null():
    # type: () -> None
    doc = """
    query q($input: [String!]) {
        listNN(input: $input)
    }
    """

    params = {"input": ["A", None, "B"]}

    with raises(GraphQLError) as excinfo:
        check(doc, {}, params)

    assert format_error(excinfo.value) == {
        "locations": [{"column": 13, "line": 2}],
        "message": 'Variable "$input" got invalid value {}.\n'
        'In element #1: Expected "String!", found null.'.format(
            stringify(params["input"])
        ),
    } 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:22,代码来源:test_variables.py

示例7: test_does_not_allow_non_null_lists_of_non_nulls_to_contain_null

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_does_not_allow_non_null_lists_of_non_nulls_to_contain_null():
    # type: () -> None
    doc = """
    query q($input: [String!]!) {
        nnListNN(input: $input)
    }
    """

    params = {"input": ["A", None, "B"]}

    with raises(GraphQLError) as excinfo:
        check(doc, {}, params)

    assert format_error(excinfo.value) == {
        "locations": [{"column": 13, "line": 2}],
        "message": 'Variable "$input" got invalid value {}.\n'
        'In element #1: Expected "String!", found null.'.format(
            stringify(params["input"])
        ),
    } 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:22,代码来源:test_variables.py

示例8: test_does_not_allow_unknown_types_to_be_used_as_values

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_does_not_allow_unknown_types_to_be_used_as_values():
    # type: () -> None
    doc = """
    query q($input: UnknownType!) {
        fieldWithObjectInput(input: $input)
    }
    """
    params = {"input": "whoknows"}

    with raises(GraphQLError) as excinfo:
        check(doc, {}, params)

    assert format_error(excinfo.value) == {
        "locations": [{"column": 13, "line": 2}],
        "message": 'Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.',
    }


# noinspection PyMethodMayBeStatic 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:21,代码来源:test_variables.py

示例9: test_errors_when_missing_operation_name

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_errors_when_missing_operation_name():
    results, params = run_http_query(
        schema,
        "get",
        {},
        query_data=dict(
            query="""
        query TestQuery { test }
        mutation TestMutation { writeTest { test } }
        """
        ),
    )

    assert as_dicts(results) == [
        {
            "data": None,
            "errors": [
                {
                    "locations": None,
                    "message": (
                        "Must provide operation name"
                        " if query contains multiple operations."
                    ),
                    "path": None,
                }
            ],
        }
    ]
    assert isinstance(results[0].errors[0], GraphQLError) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:31,代码来源:test_query.py

示例10: test_format_execution_result

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_format_execution_result():
    result = format_execution_result(None)
    assert result == GraphQLResponse(None, 200)
    data = {"answer": 42}
    result = format_execution_result(ExecutionResult(data, None))
    assert result == GraphQLResponse({"data": data}, 200)
    errors = [GraphQLError("bad")]
    result = format_execution_result(ExecutionResult(None, errors))
    assert result == GraphQLResponse({"errors": errors}, 400) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:11,代码来源:test_query.py

示例11: test_encode_execution_results

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_encode_execution_results():
    data = {"answer": 42}
    errors = [GraphQLError("bad")]
    results = [ExecutionResult(data, None), ExecutionResult(None, errors)]
    result = encode_execution_results(results)
    assert result == ('{"data":{"answer":42}}', 400) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:8,代码来源:test_query.py

示例12: test_encode_execution_results_batch

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def test_encode_execution_results_batch():
    data = {"answer": 42}
    errors = [GraphQLError("bad")]
    results = [ExecutionResult(data, None), ExecutionResult(None, errors)]
    result = encode_execution_results(results, is_batch=True)
    assert result == (
        '[{"data":{"answer":42}},'
        '{"errors":[{"message":"bad","locations":null,"path":null}]}]',
        400,
    ) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:12,代码来源:test_query.py

示例13: parse_text

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def parse_text(query: str) -> graphql.Document:
    try:
        return graphql.parse(query)
    except graphql.GraphQLError as err:
        err_loc = (err.locations[0].line,
                   err.locations[0].column)
        raise g_errors.GraphQLCoreError(err.message, loc=err_loc) from None 
开发者ID:edgedb,项目名称:edgedb,代码行数:9,代码来源:translator.py

示例14: parse_tokens

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def parse_tokens(
    text: str,
    tokens: List[Tuple[gql_lexer.TokenKind, int, int, int, int, str]]
) -> graphql.Document:
    try:
        src = graphql.Source(text)
        parser = graphql.language.parser.Parser(src)
        parser._lexer = TokenLexer(src, tokens, len(text))
        return parser.parse_document()
    except graphql.GraphQLError as err:
        err_loc = (err.locations[0].line,
                   err.locations[0].column)
        raise g_errors.GraphQLCoreError(err.message, loc=err_loc) from None 
开发者ID:edgedb,项目名称:edgedb,代码行数:15,代码来源:translator.py

示例15: parse_literal

# 需要导入模块: from graphql import error [as 别名]
# 或者: from graphql.error import GraphQLError [as 别名]
def parse_literal(cls, node):
        if not isinstance(node, StringValueNode):
            raise GraphQLError(
                f"Base64 cannot represent non-string value: {print_ast(node)}"
            )
        return cls.parse_value(node.value) 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:base64.py


注:本文中的graphql.error.GraphQLError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。