當前位置: 首頁>>代碼示例>>Python>>正文


Python graphene.Schema方法代碼示例

本文整理匯總了Python中graphene.Schema方法的典型用法代碼示例。如果您正苦於以下問題:Python graphene.Schema方法的具體用法?Python graphene.Schema怎麽用?Python graphene.Schema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphene的用法示例。


在下文中一共展示了graphene.Schema方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testQuery_excludedField

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def testQuery_excludedField(self):
        Article(headline="h1", summary="s1").put()

        class ArticleType(NdbObjectType):
            class Meta:
                model = Article
                exclude_fields = ['summary']

        class QueryType(graphene.ObjectType):
            articles = graphene.List(ArticleType)

            def resolve_articles(self, info):
                return Article.query()

        schema = graphene.Schema(query=QueryType)
        query = '''
            query ArticlesQuery {
              articles { headline, summary }
            }
        '''

        result = schema.execute(query)

        self.assertIsNotNone(result.errors)
        self.assertTrue('Cannot query field "summary"' in result.errors[0].message) 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:27,代碼來源:test_types.py

示例2: test_create_post

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_create_post():
    query_string = """
    mutation {
      createPost(text: "Try this out") {
        result {
          __typename
        }
      }
    }
    """

    schema = graphene.Schema(query=Query, mutation=Mutations)
    result = schema.execute(query_string)

    assert not result.errors
    assert result.data["createPost"]["result"]["__typename"] == "Success" 
開發者ID:graphql-python,項目名稱:graphene,代碼行數:18,代碼來源:test_313.py

示例3: test_get_session

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_get_session():
    session = "My SQLAlchemy session"

    class Query(ObjectType):
        x = String()

        def resolve_x(self, info):
            return get_session(info.context)

    query = """
        query ReporterQuery {
            x
        }
    """

    schema = Schema(query=Query)
    result = schema.execute(query, context_value={"session": session})
    assert not result.errors
    assert result.data["x"] == session 
開發者ID:graphql-python,項目名稱:graphene-sqlalchemy,代碼行數:21,代碼來源:test_utils.py

示例4: run_hook

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def run_hook(self,
                 app: FlaskUnchained,
                 bundles: List[Bundle],
                 unchained_config: Optional[Dict[str, Any]] = None,
                 ) -> None:
        """
        Create the root :class:`graphene.Schema` from queries, mutations, and types
        discovered by the other hooks and register it with the Graphene Bundle.
        """
        mutations = tuple(self.bundle.mutations.values())
        queries = tuple(self.bundle.queries.values())
        types = list(self.bundle.types.values())

        self.bundle.root_schema = graphene.Schema(
            query=queries and type('Queries', queries, {}) or None,
            mutation=mutations and type('Mutations', mutations, {}) or None,
            types=types or None) 
開發者ID:briancappello,項目名稱:flask-unchained,代碼行數:19,代碼來源:register_graphene_root_schema_hook.py

示例5: test_should_filter_by_id

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_should_filter_by_id(fixtures):
    # Notes: https://goo.gl/hMNRgs
    class Query(graphene.ObjectType):
        reporter = Node.Field(nodes.ReporterNode)

    query = """
        query ReporterQuery {
            reporter (id: "UmVwb3J0ZXJOb2RlOjE=") {
                id,
                firstName,
                awards
            }
        }
    """
    expected = {
        "reporter": {
            "id": "UmVwb3J0ZXJOb2RlOjE=",
            "firstName": "Allen",
            "awards": ["2010-mvp"],
        }
    }
    schema = graphene.Schema(query=Query)
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:27,代碼來源:test_relay_query.py

示例6: test_graphql_mutation_from_summary

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_graphql_mutation_from_summary(self):
        # create a mock mutation summary
        mock_summary = summarize_crud_mutation(model=MockModelService(), method="delete")
        # create the mutation
        mutation = graphql_mutation_from_summary(mock_summary)

        # create a schema to test the mutation
        mock_schema = graphene.Schema()
        # get the corresponding object type
        mutation_object = mock_schema.T(mutation)
        mutation_fields = list(mutation_object.get_fields().keys())

        # there should be one field named status
        assert mutation_fields == ['status'], (
            "Delete mutation did not have correct output"
        ) 
開發者ID:AlecAivazis,項目名稱:graphql-over-kafka,代碼行數:18,代碼來源:test_util.py

示例7: test_graphql_mutation_with_object_io_from_summary

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_graphql_mutation_with_object_io_from_summary(self):
        # create a mock mutation summary with a io that's an object
        mock_summary = summarize_crud_mutation(model=MockModelService(), method="create")
        # create the mutation
        mutation = graphql_mutation_from_summary(mock_summary)

        # create a schema to test the mutation
        mock_schema = graphene.Schema()
        # get the corresponding object type
        mutation_object = mock_schema.T(mutation)
        # make sure there is a resulting 'testModel' in the mutation
        assert 'testModel' in mutation_object.get_fields(), (
            "Generated create mutation  from summary does not have a service record in its output."
        )
        # the fields of the mutation result
        output_fields = set(mutation_object.get_fields()['testModel'].type.get_fields().keys())
        # make sure the object has the right types
        assert output_fields == {'date', 'name', 'id'}, (
            "Mutation output did not have the correct fields."
        ) 
開發者ID:AlecAivazis,項目名稱:graphql-over-kafka,代碼行數:22,代碼來源:test_util.py

示例8: test_does_not_auto_camel_case

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [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"
        ) 
開發者ID:AlecAivazis,項目名稱:graphql-over-kafka,代碼行數:27,代碼來源:test_schema.py

示例9: show

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def show(cli_ctx):
    with cli_ctx.logger:
        schema = graphene.Schema(
            query=Queries,
            mutation=Mutations,
            auto_camelcase=False)
        log.info('======== GraphQL API Schema ========')
        print(str(schema)) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:10,代碼來源:gql.py

示例10: init

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def init(app: web.Application) -> None:
    app['admin.gql_executor'] = AsyncioExecutor()
    app['admin.gql_schema'] = graphene.Schema(
        query=Queries,
        mutation=Mutations,
        auto_camelcase=False) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:8,代碼來源:admin.py

示例11: test_noSchema_returns500

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_noSchema_returns500(self):
        graphql_application = webapp2.WSGIApplication([
            ('/graphql', GraphQLHandler)
        ])

        app = webtest.TestApp(graphql_application)
        for method in (app.get, app.post):
            response = method('/graphql', expect_errors=True)
            self.assertEqual(response.status_int, 500)
            self.assertEqual(response.json_body['errors'][0]['message'], 'GraphQL Schema is missing.') 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:12,代碼來源:test_graphql_handler.py

示例12: testQuery_onlyFields

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def testQuery_onlyFields(self):
        Article(headline="h1", summary="s1").put()

        class ArticleType(NdbObjectType):
            class Meta:
                model = Article
                only_fields = ['headline']

        class QueryType(graphene.ObjectType):
            articles = graphene.List(ArticleType)

            def resolve_articles(self, info):
                return Article.query()

        schema = graphene.Schema(query=QueryType)
        query = '''
                    query ArticlesQuery {
                      articles { headline }
                    }
                '''

        result = schema.execute(query)

        self.assertIsNotNone(result.data)
        self.assertEqual(result.data['articles'][0]['headline'], 'h1')

        query = '''
                    query ArticlesQuery {
                      articles { headline, summary }
                    }
                '''
        result = schema.execute(query)

        self.assertIsNotNone(result.errors)
        self.assertTrue('Cannot query field "summary"' in result.errors[0].message) 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:37,代碼來源:test_types.py

示例13: schema

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def schema(self, **kwargs):
        self._schema = graphene.Schema(**kwargs) 
開發者ID:flavors,項目名稱:django-graphql-social-auth,代碼行數:4,代碼來源:testcases.py

示例14: test_issue

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_issue():
    class Query(graphene.ObjectType):
        things = relay.ConnectionField(MyUnion)

    with raises(Exception) as exc_info:
        graphene.Schema(query=Query)

    assert str(exc_info.value) == (
        "Query fields cannot be resolved."
        " IterableConnectionField type has to be a subclass of Connection."
        ' Received "MyUnion".'
    ) 
開發者ID:graphql-python,項目名稱:graphene,代碼行數:14,代碼來源:test_356.py

示例15: test_issue

# 需要導入模塊: import graphene [as 別名]
# 或者: from graphene import Schema [as 別名]
def test_issue():
    query_string = """
    query myQuery {
      myField(input: {x: 1})
    }
    """

    schema = graphene.Schema(query=Query)
    result = schema.execute(query_string)

    assert not result.errors 
開發者ID:graphql-python,項目名稱:graphene,代碼行數:13,代碼來源:test_720.py


注:本文中的graphene.Schema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。