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


Python graphql.Source方法代码示例

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


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

示例1: check_gql

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def check_gql(self):
        if not self.tree or not self.lines:
            self.load_file()

        visitor = self.visitor_class(self.filename, self.options)
        visitor.visit(self.tree)

        for node in visitor.calls:
            # Lines with the noqa flag are ignored entirely
            if pycodestyle.noqa(self.lines[node.lineno - 1]):
                continue

            query = visitor.node_query(node)
            if not query:
                continue

            try:
                source = Source(query, 'gql query')
                ast = parse(source)
            except Exception as e:
                message = str(e)
                yield self.error(node, GQL_SYNTAX_ERROR, message)
                continue

            validation_errors = self.validation_errors(ast)
            if validation_errors:
                for error in validation_errors:
                    message = str(error)
                    yield self.error(node, GQL_VALIDATION_ERROR, message) 
开发者ID:graphql-python,项目名称:gql,代码行数:31,代码来源:__init__.py

示例2: gql

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def gql(request_string: str) -> DocumentNode:
    source = Source(request_string, "GraphQL request")
    return parse(source) 
开发者ID:graphql-python,项目名称:gql,代码行数:5,代码来源:gql.py

示例3: test_encode_execution_results_with_error

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def test_encode_execution_results_with_error():
    execution_results = [
        ExecutionResult(
            None,
            [
                GraphQLError(
                    "Some error",
                    source=Source(body="Some error"),
                    positions=[1],
                    path=["somePath"],
                )
            ],
        ),
        ExecutionResult({"result": 42}, None),
    ]

    output = encode_execution_results(execution_results)
    assert isinstance(output, ServerResponse)
    assert isinstance(output.body, str)
    assert isinstance(output.status_code, int)
    assert json.loads(output.body) == {
        "errors": [
            {
                "message": "Some error",
                "locations": [{"line": 1, "column": 2}],
                "path": ["somePath"],
            }
        ],
        "data": None,
    }
    assert output.status_code == 200 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:33,代码来源:test_helpers.py

示例4: test_encode_execution_results_with_format_error

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def test_encode_execution_results_with_format_error():
    execution_results = [
        ExecutionResult(
            None,
            [
                GraphQLError(
                    "Some msg",
                    source=Source("Some msg"),
                    positions=[1],
                    path=["some", "path"],
                )
            ],
        )
    ]

    def format_error(error):
        return {
            "msg": error.message,
            "loc": "{}:{}".format(error.locations[0].line, error.locations[0].column),
            "pth": "/".join(error.path),
        }

    output = encode_execution_results(execution_results, format_error=format_error)
    assert isinstance(output, ServerResponse)
    assert isinstance(output.body, str)
    assert isinstance(output.status_code, int)
    assert json.loads(output.body) == {
        "errors": [{"msg": "Some msg", "loc": "1:2", "pth": "some/path"}],
        "data": None,
    }
    assert output.status_code == 200 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:33,代码来源:test_helpers.py

示例5: parse_tokens

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [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

示例6: get_operation_ast

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def get_operation_ast(self, request):
        data = self.parse_body(request)
        query = request.GET.get("query") or data.get("query")

        if not query:
            return None

        source = Source(query, name="GraphQL request")

        document_ast = parse(source)
        operation_ast = get_operation_ast(document_ast, None)

        return operation_ast 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:15,代码来源:views.py

示例7: execute_graphql_request

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def execute_graphql_request(self, request):
        query, variables, operation_name = self.get_graphql_params(request, self.parse_body(request))

        if not query:
            raise HttpError(HttpResponseBadRequest('Must provide query string.'))

        source = Source(query, name='GraphQL request')

        try:
            document_ast = parse(source)
            validation_errors = validate(self.schema, document_ast)
            if validation_errors:
                return ExecutionResult(
                    errors=validation_errors,
                    invalid=True,
                )
        except Exception as e:
            return ExecutionResult(errors=[e], invalid=True)

        if request.method.lower() == 'get':
            operation_ast = get_operation_ast(document_ast, operation_name)
            if operation_ast and operation_ast.operation != 'query':
                raise HttpError(HttpResponseNotAllowed(
                    ['POST'], 'Can only perform a {} operation from a POST request.'.format(operation_ast.operation)
                ))

        try:
            return self.execute(
                document_ast,
                root_value=self.get_root_value(request),
                variable_values=variables,
                operation_name=operation_name,
                context_value=self.get_context(request),
                executor=self.executor,
            )
        except Exception as e:
            return ExecutionResult(errors=[e], invalid=True) 
开发者ID:GraphQL-python-archive,项目名称:graphql-django-view,代码行数:39,代码来源:__init__.py

示例8: test_it_concatenates_two_acts_together

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def test_it_concatenates_two_acts_together():
    source_a = Source("{ a, b, ... Frag }")
    source_b = Source(
        """
        fragment Frag on T {
            c
        }
    """
    )

    ast_a = parse(source_a)
    ast_b = parse(source_b)
    ast_c = concat_ast([ast_a, ast_b])

    assert (
        print_ast(ast_c)
        == """{
  a
  b
  ...Frag
}

fragment Frag on T {
  c
}
"""
    ) 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:29,代码来源:test_concat_ast.py

示例9: test_ast_to_code_using_kitchen_sink

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def test_ast_to_code_using_kitchen_sink():
    doc = parse(fixtures.KITCHEN_SINK)
    code_ast = ast_to_code(doc)
    source = Source(fixtures.KITCHEN_SINK)

    def loc(start, end):
        return Loc(start, end, source)

    parsed_code_ast = eval(code_ast, {}, {"ast": ast, "loc": loc})
    assert doc == parsed_code_ast 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:12,代码来源:test_ast_to_code.py

示例10: create_loc_fn

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import Source [as 别名]
def create_loc_fn(body):
    # type: (str) -> Callable
    source = Source(body)
    return lambda start, end: Loc(start, end, source) 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:6,代码来源:test_schema_parser.py


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