当前位置: 首页>>代码示例>>Python>>正文


Python graphql_relay.to_global_id方法代码示例

本文整理汇总了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) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:20,代码来源:test_object_identification.py

示例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) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:24,代码来源:test_object_identification.py

示例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) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:21,代码来源:test_object_identification.py

示例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) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:23,代码来源:test_object_identification.py

示例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 
开发者ID:tfoxy,项目名称:graphene-django-optimizer,代码行数:23,代码来源:test_types.py

示例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 
开发者ID:graphql-python,项目名称:graphql-relay-py,代码行数:22,代码来源:test_node.py

示例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 
开发者ID:projectcaluma,项目名称:caluma,代码行数:21,代码来源:test_type.py

示例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 
开发者ID:projectcaluma,项目名称:caluma,代码行数:19,代码来源:test_type.py

示例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 
开发者ID:projectcaluma,项目名称:caluma,代码行数:26,代码来源:test_schema.py

示例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() 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:12,代码来源:fields.py

示例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)) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:30,代码来源:test_types.py

示例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) 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:test_global_id.py

示例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) 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:test_global_id.py

示例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"}} 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:test_node.py

示例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": "----",
        }
    } 
开发者ID:graphql-python,项目名称:graphene,代码行数:15,代码来源:test_node.py


注:本文中的graphql_relay.to_global_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。