本文整理匯總了Python中graphql_relay.to_global_id方法的典型用法代碼示例。如果您正苦於以下問題:Python graphql_relay.to_global_id方法的具體用法?Python graphql_relay.to_global_id怎麽用?Python graphql_relay.to_global_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graphql_relay
的用法示例。
在下文中一共展示了graphql_relay.to_global_id方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_correctly_fetches_id_name_rebels
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_correctly_fetches_id_name_rebels(self):
query = '''
query RebelsQuery {
rebels {
id,
name
}
}
'''
expected = {
'rebels': {
'id': to_global_id('Faction', ndb.Key('Faction', 'rebels').urlsafe()),
'name': 'Alliance to Restore the Republic'
}
}
result = schema.execute(query)
self.assertFalse(result.errors, msg=str(result.errors))
self.assertDictEqual(result.data, expected)
示例2: test_correctly_refetches_rebels
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_correctly_refetches_rebels(self):
rebels_key = to_global_id('Faction', ndb.Key('Faction', 'rebels').urlsafe())
query = '''
query RebelsRefetchQuery {
node(id: "%s") {
id
... on Faction {
name
}
}
}
''' % rebels_key
expected = {
'node': {
'id': rebels_key,
'name': 'Alliance to Restore the Republic'
}
}
result = schema.execute(query)
self.assertFalse(result.errors, msg=str(result.errors))
self.assertDictEqual(result.data, expected)
示例3: test_correctly_fetches_id_name_empire
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_correctly_fetches_id_name_empire(self):
empire_key = to_global_id('Faction', ndb.Key('Faction', 'empire').urlsafe())
query = '''
query EmpireQuery {
empire {
id
name
}
}
'''
expected = {
'empire': {
'id': empire_key,
'name': 'Galactic Empire'
}
}
result = schema.execute(query)
self.assertFalse(result.errors, msg=str(result.errors))
self.assertDictEqual(result.data, expected)
示例4: test_correctly_refetches_id_name_empire
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_correctly_refetches_id_name_empire(self):
empire_key = to_global_id('Faction', ndb.Key('Faction', 'empire').urlsafe())
query = '''
query EmpireRefetchQuery {
node(id: "%s") {
id
... on Faction {
name
}
}
}
''' % empire_key
expected = {
'node': {
'id': empire_key,
'name': 'Galactic Empire'
}
}
result = schema.execute(query)
self.assertFalse(result.errors, msg=str(result.errors))
self.assertDictEqual(result.data, expected)
示例5: test_mutating_should_not_optimize
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_mutating_should_not_optimize(mocked_optimizer):
Item.objects.create(id=7)
info = create_resolve_info(schema, '''
query {
items(id: $id) {
id
foo
children {
id
foo
}
}
}
''')
info.return_type = schema.get_type('SomeOtherItemType')
result = DummyItemMutation.mutate(info, to_global_id('ItemNode', 7))
assert result
assert result.pk == 7
assert mocked_optimizer.call_count == 0
示例6: describe_convert_global_ids
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def describe_convert_global_ids():
def to_global_id_converts_unicode_strings_correctly():
my_unicode_id = "ûñö"
g_id = to_global_id("MyType", my_unicode_id)
assert g_id == "TXlUeXBlOsO7w7HDtg=="
my_unicode_id = "\u06ED"
g_id = to_global_id("MyType", my_unicode_id)
assert g_id == "TXlUeXBlOtut"
def from_global_id_converts_unicode_strings_correctly():
my_unicode_id = "ûñö"
my_type, my_id = from_global_id("TXlUeXBlOsO7w7HDtg==")
assert my_type == "MyType"
assert my_id == my_unicode_id
my_unicode_id = "\u06ED"
my_type, my_id = from_global_id("TXlUeXBlOtut")
assert my_type == "MyType"
assert my_id == my_unicode_id
示例7: test_answer_types
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_answer_types(
db, question, expected_typename, success, answer_factory, schema_executor
):
answer = answer_factory(question=question)
global_id = to_global_id(expected_typename, answer.pk)
query = """
query Answer($id: ID!) {
node(id: $id) {
id
__typename
}
}
"""
result = schema_executor(query, variable_values={"id": global_id})
assert not result.errors == success
if success:
assert result.data["node"]["__typename"] == expected_typename
示例8: test_question_types
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_question_types(
db, question, expected_typename, answer_factory, schema_executor
):
global_id = to_global_id(expected_typename, question.pk)
query = """
query Question($id: ID!) {
node(id: $id) {
id
__typename
}
}
"""
result = schema_executor(query, variable_values={"id": global_id})
assert not result.errors
assert result.data["node"]["__typename"] == expected_typename
示例9: test_schema_node
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_schema_node(db, snapshot, request, node_type):
"""
Add your model to parametrize for automatic global node testing.
Requirement is that node and model have the same name
"""
node_instance = request.getfixturevalue(node_type)
global_id = to_global_id(node_instance.__class__.__name__, node_instance.pk)
node_query = """
query %(name)s($id: ID!) {
node(id: $id) {
... on %(name)s {
id
}
}
}
""" % {
"name": node_instance.__class__.__name__
}
result = schema.execute(node_query, variable_values={"id": global_id})
assert not result.errors
assert result.data["node"]["id"] == global_id
示例10: resolve_key_to_string
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def resolve_key_to_string(self, entity, info, ndb=False):
is_global_id = not ndb
key_value = self.__ndb_key_prop._get_user_value(entity)
if not key_value:
return None
if isinstance(key_value, list):
return [to_global_id(self.__graphql_type_name, k.urlsafe()) for k in key_value] if is_global_id else [k.id() for k in key_value]
return to_global_id(self.__graphql_type_name, key_value.urlsafe()) if is_global_id else key_value.id()
示例11: testQuery_repeatedKeyProperty
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def testQuery_repeatedKeyProperty(self):
tk1 = Tag(name="t1").put()
tk2 = Tag(name="t2").put()
tk3 = Tag(name="t3").put()
tk4 = Tag(name="t4").put()
Article(headline="h1", summary="s1", tags=[tk1, tk2, tk3, tk4]).put()
result = schema.execute('''
query ArticleWithAuthorID {
articles {
headline
authorId
tagIds
tags {
name
}
}
}
''')
self.assertEmpty(result.errors)
article = dict(result.data['articles'][0])
self.assertListEqual(map(lambda k: to_global_id('TagType', k.urlsafe()), [tk1, tk2, tk3, tk4]), article['tagIds'])
self.assertLength(article['tags'], 4)
for i in range(0, 3):
self.assertEqual(article['tags'][i]['name'], 't%s' % (i + 1))
示例12: test_global_id_defaults_to_info_parent_type
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_global_id_defaults_to_info_parent_type():
my_id = "1"
gid = GlobalID()
id_resolver = gid.get_resolver(lambda *_: my_id)
my_global_id = id_resolver(None, Info(User))
assert my_global_id == to_global_id(User._meta.name, my_id)
示例13: test_global_id_allows_setting_customer_parent_type
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_global_id_allows_setting_customer_parent_type():
my_id = "1"
gid = GlobalID(parent_type=User)
id_resolver = gid.get_resolver(lambda *_: my_id)
my_global_id = id_resolver(None, None)
assert my_global_id == to_global_id(User._meta.name, my_id)
示例14: test_node_query
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_node_query():
executed = schema.execute(
'{ node(id:"%s") { ... on MyNode { name } } }' % Node.to_global_id("MyNode", 1)
)
assert not executed.errors
assert executed.data == {"node": {"name": "1"}}
示例15: test_subclassed_node_query
# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import to_global_id [as 別名]
def test_subclassed_node_query():
executed = schema.execute(
'{ node(id:"%s") { ... on MyOtherNode { shared, extraField, somethingElse } } }'
% to_global_id("MyOtherNode", 1)
)
assert not executed.errors
assert executed.data == {
"node": {
"shared": "1",
"extraField": "extra field info.",
"somethingElse": "----",
}
}