Beispiel #1
0
def test_schema_introspect():
    schema = Schema(name='My own schema')

    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    introspection = schema.introspect()
    assert '__schema' in introspection
Beispiel #2
0
def test_schema_introspect():
    schema = Schema(name="My own schema")

    class MyType(ObjectType):
        type = String(resolver=lambda *_: "Dog")

    schema.query = MyType

    introspection = schema.introspect()
    assert "__schema" in introspection
Beispiel #3
0
def test_schema_introspect():
    schema = Schema(name='My own schema')

    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    introspection = schema.introspect()
    assert '__schema' in introspection
from graphene import ObjectType, String, Schema
import json


class Query(ObjectType):
    hello = String(name=String(default_value="stranger"))
    goodbye = String()

    def resolve_hello(root, info, name):
        return f'Hello {name}!'

    def resolve_goodbye(root, info):
        return 'See ya!'


schema = Schema(query=Query)

introspect_dict = schema.introspect()
print(json.dumps(introspect_dict, indent=2))
Beispiel #5
0
class ServerRootQuery(ObjectType):
    node = relay.Node.Field()


class Subscription(ObjectType):
    kernel = Field(stitch(KernelRootQuery))

    def resolve_kernel(self, info):
        assert len(info.field_asts) == 1
        assert info.field_asts[0].name.value == 'kernel'

        return rx.Observable.merge(
                rx.Observable.just(True),  # Send data at least once
                info.context.reloadable
            ).flat_map(
                lambda _: rx.Observable.from_future(
                    asyncio.get_running_loop().create_task(
                        info.context.reloadable.call(
                            info.context.kernel.query,
                            construct_stitched_query(info),
                            variables=info.variable_values)))
            ).map(lambda result: stitch(KernelRootQuery)(json.loads(result)))


schema = Schema(query=ServerRootQuery, subscription=Subscription)


if __name__ == '__main__':
    print(json.dumps({'data': schema.introspect()}))
Beispiel #6
0
from graphene import ObjectType, Schema
from graphene.relay import NodeField
from graphene.contrib.sqlalchemy import SQLAlchemyNode, \
    SQLAlchemyConnectionField

from test_graphene import models

schema = Schema()


@schema.register
class Note(SQLAlchemyNode):
    class Meta:
        model = models.Note


class Query(ObjectType):
    node = NodeField()
    all_notes = SQLAlchemyConnectionField(Note)


schema.query = Query

if __name__ == "__main__":
    import sys
    import json
    if len(sys.argv) > 1 and sys.argv[1] == "--json":
        print(json.dumps(schema.introspect(), indent=2))
    else:
        print(schema)