本文整理汇总了Python中graphql.language.ast.StringValueNode方法的典型用法代码示例。如果您正苦于以下问题:Python ast.StringValueNode方法的具体用法?Python ast.StringValueNode怎么用?Python ast.StringValueNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.language.ast
的用法示例。
在下文中一共展示了ast.StringValueNode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _encode
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def _encode(value):
if value is None:
return ast.NullValueNode()
elif isinstance(value, bool):
return ast.BooleanValueNode(value=value)
elif isinstance(value, int):
return ast.IntValueNode(value=str(value))
elif isinstance(value, float):
return ast.FloatValueNode(value=str(value))
elif isinstance(value, str):
return ast.StringValueNode(value=value)
elif isinstance(value, list):
return ast.ListValueNode(values=[_encode(v) for v in value])
elif isinstance(value, dict):
return ast.ObjectValueNode(fields=[
ast.ObjectFieldNode(name=_name(key), value=_encode(val))
for key, val in value.items()
])
else:
raise TypeError('Unsupported type: {!r}'.format(value))
示例2: parse_date_literal
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def parse_date_literal(ast, variable_values=None): # pylint: disable=unused-argument
if not isinstance(ast, StringValueNode):
raise ValueError()
formatted_date = ast.value
parsed_datetime = datetime.strptime(formatted_date, "%Y-%m-%d")
return parsed_datetime.date()
示例3: value_node_from_pyvalue
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def value_node_from_pyvalue(val: Any):
if val is None:
return None
elif isinstance(val, str):
val = val.replace('\\', '\\\\')
value = eql_quote.quote_literal(val)
return gql_ast.StringValueNode(value=value[1:-1])
elif isinstance(val, bool):
return gql_ast.BooleanValueNode(value=bool(val))
elif isinstance(val, int):
return gql_ast.IntValueNode(value=str(val))
elif isinstance(val, (float, decimal.Decimal)):
return gql_ast.FloatValueNode(value=str(val))
elif isinstance(val, list):
return gql_ast.ListValueNode(
values=[value_node_from_pyvalue(v) for v in val])
elif isinstance(val, dict):
return gql_ast.ObjectValueNode(
fields=[
gql_ast.ObjectFieldNode(
name=n,
value=value_node_from_pyvalue(v)
)
for n, v in val.items()
])
else:
raise ValueError(f'unexpected constant type: {type(val)!r}')
示例4: convert_default
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def convert_default(
node: gql_ast.ValueNode,
varname: str
) -> Union[str, float, int, bool]:
if isinstance(node, (gql_ast.StringValueNode, gql_ast.BooleanValueNode)):
return node.value
elif isinstance(node, gql_ast.IntValueNode):
return int(node.value)
elif isinstance(node, gql_ast.FloatValueNode):
return float(node.value)
else:
raise errors.QueryError(
f"Only scalar defaults are allowed. "
f"Variable {varname!r} has non-scalar default value.")
示例5: parse_literal_decimal
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def parse_literal_decimal(ast, _variables=None): # pragma: no cover
if not isinstance(ast, StringValueNode):
return INVALID
try:
return Decimal(ast.value)
except ValueError:
return INVALID
示例6: parse_literal
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def parse_literal(node):
if isinstance(node, StringValueNode):
return json.loads(node.value)
示例7: parse_literal
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def parse_literal(cls, node):
if isinstance(node, StringValueNode):
return cls.parse_value(node.value)
示例8: parse_literal
# 需要导入模块: from graphql.language import ast [as 别名]
# 或者: from graphql.language.ast import StringValueNode [as 别名]
def parse_literal(node):
if isinstance(node, StringValueNode):
return _UUID(node.value)