Ejemplo n.º 1
0
def resolve_raises(*_):
    raise Exception("Throws!")


QueryRootType = GraphQLObjectType(
    name='QueryRoot',
    fields={
        'thrower':
        GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
        'request':
        GraphQLField(
            GraphQLNonNull(GraphQLString),
            resolver=lambda obj, args, context, info: context.args.get('q')),
        'test':
        GraphQLField(type=GraphQLString,
                     args={'who': GraphQLArgument(GraphQLString)},
                     resolver=lambda obj, args, context, info: 'Hello %s' %
                     (args.get('who') or 'World'))
    })

MutationRootType = GraphQLObjectType(name='MutationRoot',
                                     fields={
                                         'writeTest':
                                         GraphQLField(
                                             type=QueryRootType,
                                             resolver=lambda *_: QueryRootType)
                                     })

Schema = GraphQLSchema(QueryRootType, MutationRootType)
Ejemplo n.º 2
0
            type_=GraphQLString,
            args={"who": GraphQLArgument(GraphQLString)},
            resolve=lambda obj, info, who=None: "Hello %s" % (who or "World"),
        ),
    },
)

MutationRootType = GraphQLObjectType(
    name="MutationRoot",
    fields={
        "writeTest":
        GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType)
    },
)

Schema = GraphQLSchema(QueryRootType, MutationRootType)


# Schema with async methods
async def resolver_field_async_1(_obj, info):
    await asyncio.sleep(0.001)
    return "hey"


async def resolver_field_async_2(_obj, info):
    await asyncio.sleep(0.003)
    return "hey2"


def resolver_field_sync(_obj, info):
    return "hey3"
Ejemplo n.º 3
0
    name="MutationRoot",
    fields={
        "writeTest":
        GraphQLField(type_=QueryRootType, resolve=lambda *args: QueryRootType)
    },
)

SubscriptionsRootType = GraphQLObjectType(
    name="SubscriptionsRoot",
    fields={
        "subscriptionsTest":
        GraphQLField(type_=QueryRootType, resolve=lambda *args: QueryRootType)
    },
)

Schema = GraphQLSchema(QueryRootType, MutationRootType, SubscriptionsRootType)


# Schema with async methods
async def resolver_field_async_1(_obj, info):
    await asyncio.sleep(0.001)
    return "hey"


async def resolver_field_async_2(_obj, info):
    await asyncio.sleep(0.003)
    return "hey2"


def resolver_field_sync(_obj, info):
    return "hey3"
Ejemplo n.º 4
0
from queries import QueryRootType
from graphql.type.schema import GraphQLSchema

schema = GraphQLSchema(QueryRootType)
                                "Node",
                                {
                                    "id": GraphQLField(GraphQLID),
                                    "name": GraphQLField(GraphQLString),
                                },
                            ))
                    },
                )))
    },
)

schema = GraphQLSchema(
    GraphQLObjectType(
        "QueryRoot",
        {
            "someBox": GraphQLField(SomeBox),
            "connection": GraphQLField(Connection)
        },
    ),
    types=[IntBox, StringBox, NonNullStringBox1Impl, NonNullStringBox2Impl],
)


def test_conflicting_return_types_which_potentially_overlap():
    expect_fails_rule_with_schema(
        schema,
        OverlappingFieldsCanBeMerged,
        """
    {
        someBox {
            ...on IntBox {
                scalar
Ejemplo n.º 6
0
    'deepBox': GraphQLField(StringBox),
}, interfaces=[SomeBox, NonNullStringBox2])

Connection = GraphQLObjectType('Connection', {
    'edges': GraphQLField(GraphQLList(GraphQLObjectType('Edge', {
        'node': GraphQLField(GraphQLObjectType('Node', {
            'id': GraphQLField(GraphQLID),
            'name': GraphQLField(GraphQLString)
        }))
    })))
})

schema = GraphQLSchema(
    GraphQLObjectType('QueryRoot', {
        'someBox': GraphQLField(SomeBox),
        'connection': GraphQLField(Connection),
    }),
    types=[IntBox, StringBox, NonNullStringBox1Impl, NonNullStringBox2Impl]
)


def test_conflicting_return_types_which_potentially_overlap():
    expect_fails_rule_with_schema(schema, OverlappingFieldsCanBeMerged, '''
    {
        someBox {
            ...on IntBox {
                scalar
            }
            ...on NonNullStringBox1 {
                scalar
            }
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
from graphql.type.scalars import GraphQLString, GraphQLBoolean
from graphql.type.schema import GraphQLSchema

Query = GraphQLObjectType(
    name='Query',
    fields={
        'testString':
        GraphQLField(
            GraphQLNonNull(GraphQLString),
            resolver=lambda root, args, context, info: 'string returned')
    })

Subscription = GraphQLObjectType(
    name='Subscription',
    fields={
        'test_subscription':
        GraphQLField(type=GraphQLNonNull(GraphQLString),
                     resolver=lambda root, args, context, info: root),
        'test_filter_sub':
        GraphQLField(type=GraphQLNonNull(GraphQLString),
                     args={'filter_bool': GraphQLArgument(GraphQLBoolean)},
                     resolver=lambda root, args, context, info: 'SUCCESS'),
    })

Schema = GraphQLSchema(Query, subscription=Subscription)