本文整理汇总了Python中graphene.String方法的典型用法代码示例。如果您正苦于以下问题:Python graphene.String方法的具体用法?Python graphene.String怎么用?Python graphene.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphene
的用法示例。
在下文中一共展示了graphene.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_service_query
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def get_service_query(schema):
sdl_str = get_sdl(schema, custom_entities)
class _Service(ObjectType):
sdl = String()
def resolve_sdl(parent, _):
return sdl_str
class ServiceQuery(ObjectType):
_service = Field(_Service, name="_service")
def resolve__service(parent, info):
return _Service()
return ServiceQuery
示例2: to_graphql_fields
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def to_graphql_fields(self):
return {
self.limit_query_param: Int(
default_value=self.default_limit,
description="Number of results to return per page. Default "
"'default_limit': {}, and 'max_limit': {}".format(
self.default_limit, self.max_limit
),
),
self.offset_query_param: Int(
description="The initial index from which to return the results. Default: 0"
),
self.ordering_param: String(
description="A string or comma delimited string values that indicate the "
"default ordering when obtaining lists of objects."
),
}
示例3: test_should_composite_convert
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def test_should_composite_convert():
registry = Registry()
class CompositeClass:
def __init__(self, col1, col2):
self.col1 = col1
self.col2 = col2
@convert_sqlalchemy_composite.register(CompositeClass, registry)
def convert_composite_class(composite, registry):
return graphene.String(description=composite.doc)
field = convert_sqlalchemy_composite(
composite(CompositeClass, (Column(types.Unicode(50)), Column(types.Unicode(50))), doc="Custom Help Text"),
registry,
mock_resolver,
)
assert isinstance(field, graphene.String)
示例4: test_does_not_auto_camel_case
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def test_does_not_auto_camel_case(self):
# a query to test with a snake case field
class TestQuery(ObjectType):
test_field = String()
def resolve_test_field(self, args, info):
return 'hello'
# assign the query to the schema
self.schema.query = TestQuery
# the query to test
test_query = "query {test_field}"
# execute the query
resolved_query = self.schema.execute(test_query)
assert 'test_field' in resolved_query.data, (
"Schema did not have snake_case field."
)
assert resolved_query.data['test_field'] == 'hello', (
"Snake_case field did not have the right value"
)
示例5: test_should_postgres_array_multiple_convert_list
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def test_should_postgres_array_multiple_convert_list():
field = assert_conversion(
ArrayField, graphene.List, ArrayField(models.CharField(max_length=100))
)
assert isinstance(field.type, graphene.NonNull)
assert isinstance(field.type.of_type, graphene.List)
assert isinstance(field.type.of_type.of_type, graphene.List)
assert isinstance(field.type.of_type.of_type.of_type, graphene.NonNull)
assert field.type.of_type.of_type.of_type.of_type == graphene.String
field = assert_conversion(
ArrayField,
graphene.List,
ArrayField(models.CharField(max_length=100, null=True)),
)
assert isinstance(field.type, graphene.NonNull)
assert isinstance(field.type.of_type, graphene.List)
assert isinstance(field.type.of_type.of_type, graphene.List)
assert field.type.of_type.of_type.of_type == graphene.String
示例6: convert_ndb_string_property
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def convert_ndb_string_property(ndb_prop, registry=None):
return convert_ndb_scalar_property(String, ndb_prop)
示例7: convert_ndb_key_propety
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def convert_ndb_key_propety(ndb_key_prop, registry=None):
"""
Two conventions for handling KeyProperties:
#1.
Given:
store_key = ndb.KeyProperty(...)
Result is 2 fields:
store_id = graphene.String() -> resolves to store_key.urlsafe()
store = NdbKeyField() -> resolves to entity
#2.
Given:
store = ndb.KeyProperty(...)
Result is 2 fields:
store_id = graphene.String() -> resolves to store_key.urlsafe()
store = NdbKeyField() -> resolves to entity
"""
is_repeated = ndb_key_prop._repeated
name = ndb_key_prop._code_name
if name.endswith('_key') or name.endswith('_keys'):
# Case #1 - name is of form 'store_key' or 'store_keys'
string_prop_name = rreplace(name, '_key', '_id', 1)
resolved_prop_name = name[:-4] if name.endswith('_key') else p.plural(name[:-5])
else:
# Case #2 - name is of form 'store'
singular_name = p.singular_noun(name) if p.singular_noun(name) else name
string_prop_name = singular_name + '_ids' if is_repeated else singular_name + '_id'
resolved_prop_name = name
return [
ConversionResult(name=string_prop_name, field=DynamicNdbKeyStringField(ndb_key_prop, registry=registry)),
ConversionResult(name=resolved_prop_name, field=DynamicNdbKeyReferenceField(ndb_key_prop, registry=registry))
]
示例8: convert_computed_property
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def convert_computed_property(ndb_computed_prop, registry=None):
return convert_ndb_scalar_property(String, ndb_computed_prop)
示例9: testGET_support_json_variables
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testGET_support_json_variables(self):
response = self.app.get('/graphql', params=dict(
query='query helloWho($who: String){ greet(who: $who) }',
variables=json.dumps({'who': "ekampf"})
))
response_dict = json.loads(response.body)
self.assertDictEqual(
response_dict.get('data'), {'greet': 'Hello ekampf!'}
)
示例10: testPOST_support_json_variables
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testPOST_support_json_variables(self):
response = self.app.post('/graphql', params=json.dumps(dict(
query='query helloWho($who: String){ greet(who: $who) }',
variables={'who': "ekampf"}
)))
response_dict = json.loads(response.body)
self.assertDictEqual(
response_dict.get('data'), {'greet': 'Hello ekampf!'}
)
示例11: test_handles_poorly_formed_variables
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def test_handles_poorly_formed_variables(self):
for method in (self.get, self.post):
response = method('/graphql', expect_errors=True, params=dict(
query='query helloWho($who: String){ greet(who: $who) }',
variables='who:You'
))
response_data = json.loads(response.body)
self.assertEqual(response.status_int, 400)
self.assertEqual(response_data['errors'][0]['message'], 'Variables are invalid JSON.')
示例12: testStringProperty_shouldConvertToString
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testStringProperty_shouldConvertToString(self):
self.__assert_conversion(ndb.StringProperty, graphene.String)
示例13: testStringProperty_repeated_shouldConvertToList
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testStringProperty_repeated_shouldConvertToList(self):
ndb_prop = ndb.StringProperty(repeated=True)
result = convert_ndb_property(ndb_prop)
graphene_type = result.field._type
self.assertIsInstance(graphene_type, graphene.List)
self.assertEqual(graphene_type.of_type, graphene.String)
示例14: testStringProperty_required_shouldConvertToList
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testStringProperty_required_shouldConvertToList(self):
ndb_prop = ndb.StringProperty(required=True)
result = convert_ndb_property(ndb_prop)
graphene_type = result.field._type
self.assertIsInstance(graphene_type, graphene.NonNull)
self.assertEqual(graphene_type.of_type, graphene.String)
示例15: testTextProperty_shouldConvertToString
# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import String [as 别名]
def testTextProperty_shouldConvertToString(self):
self.__assert_conversion(ndb.TextProperty, graphene.String)