當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。