本文整理匯總了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)