Python graphql.language.ast.StringValueNode() Examples
The following are 8
code examples of graphql.language.ast.StringValueNode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
graphql.language.ast
, or try the search function
.
Example #1
Source File: graphql.py From hiku with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #2
Source File: test_custom_scalars.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #3
Source File: translator.py From edgedb with Apache License 2.0 | 5 votes |
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}')
Example #4
Source File: translator.py From edgedb with Apache License 2.0 | 5 votes |
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.")
Example #5
Source File: scalars.py From pycon with MIT License | 5 votes |
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
Example #6
Source File: json.py From graphene with MIT License | 5 votes |
def parse_literal(node): if isinstance(node, StringValueNode): return json.loads(node.value)
Example #7
Source File: decimal.py From graphene with MIT License | 5 votes |
def parse_literal(cls, node): if isinstance(node, StringValueNode): return cls.parse_value(node.value)
Example #8
Source File: uuid.py From graphene with MIT License | 5 votes |
def parse_literal(node): if isinstance(node, StringValueNode): return _UUID(node.value)