当前位置: 首页>>代码示例>>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;未经允许,请勿转载。