當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。