Пример #1
0
def test_fails_on_very_deep_lists():
    schema = GraphQLSchema(query=GraphQLObjectType(
        name='Query',
        fields={
            'foo':
            GraphQLField(
                GraphQLList(
                    GraphQLList(
                        GraphQLList(
                            GraphQLList(
                                GraphQLList(
                                    GraphQLList(
                                        GraphQLList(
                                            GraphQLList(
                                                GraphQLList(
                                                    GraphQLString))))))))))
        }))

    introspection = graphql(schema, introspection_query)

    with raises(Exception) as excinfo:
        build_client_schema(introspection.data)

    assert str(
        excinfo.value) == 'Decorated type deeper than introspection query.'
def test_fails_on_a_very_deep_non_null():
    schema = GraphQLSchema(query=GraphQLObjectType(
        name="Query",
        fields={
            "foo":
            GraphQLField(
                GraphQLList(
                    GraphQLList(
                        GraphQLList(
                            GraphQLList(
                                GraphQLList(
                                    GraphQLList(
                                        GraphQLList(
                                            GraphQLList(
                                                GraphQLNonNull(
                                                    GraphQLString))))))))))
        },
    ))

    introspection = graphql(schema, introspection_query)

    with raises(Exception) as excinfo:
        build_client_schema(introspection.data)

    assert str(
        excinfo.value) == "Decorated type deeper than introspection query."
def test_throws_when_given_empty_types():
    incomplete_introspection = {
        '__schema': {
            'queryType': {'name': 'QueryType'},
            'types': []
        }
    }

    with raises(Exception) as excinfo:
        build_client_schema(incomplete_introspection)

    assert str(excinfo.value) == 'Invalid or incomplete schema, unknown type: QueryType. Ensure that a full ' \
                                 'introspection query is used in order to build a client schema.'
Пример #4
0
def test_throws_when_given_empty_types():
    incomplete_introspection = {
        "__schema": {"queryType": {"name": "QueryType"}, "types": []}
    }

    with raises(Exception) as excinfo:
        build_client_schema(incomplete_introspection)

    assert (
        str(excinfo.value)
        == "Invalid or incomplete schema, unknown type: QueryType. Ensure that a full "
        "introspection query is used in order to build a client schema."
    )
def test_throws_when_given_empty_types():
    incomplete_introspection = {
        '__schema': {
            'queryType': {'name': 'QueryType'},
            'types': []
        }
    }

    with raises(Exception) as excinfo:
        build_client_schema(incomplete_introspection)

    assert str(excinfo.value) == 'Invalid or incomplete schema, unknown type: QueryType. Ensure that a full ' \
                                 'introspection query is used in order to build a client schema.'
def _test_schema(server_schema):
    initial_introspection = graphql(server_schema, introspection_query)
    client_schema = build_client_schema(initial_introspection.data)
    second_introspection = graphql(client_schema, introspection_query)
    assert contain_subset(initial_introspection.data, second_introspection.data)

    return client_schema
def _test_schema(server_schema):
    initial_introspection = graphql(server_schema, introspection_query)
    client_schema = build_client_schema(initial_introspection.data)
    second_introspection = graphql(client_schema, introspection_query)
    assert contain_subset(initial_introspection.data, second_introspection.data)

    return client_schema
Пример #8
0
def test_cannot_use_client_schema_for_general_execution():
    customScalar = GraphQLScalarType(name='CustomScalar',
                                     serialize=lambda: None)

    schema = GraphQLSchema(query=GraphQLObjectType(
        name='Query',
        fields={
            'foo':
            GraphQLField(GraphQLString,
                         args=OrderedDict([('custom1',
                                            GraphQLArgument(customScalar)),
                                           ('custom2',
                                            GraphQLArgument(customScalar))]))
        }))

    introspection = graphql(schema, introspection_query)
    client_schema = build_client_schema(introspection.data)

    class data:
        foo = 'bar'

    result = graphql(
        client_schema,
        'query NoNo($v: CustomScalar) { foo(custom1: 123, custom2: $v) }',
        data, {'v': 'baz'})

    assert result.data == {'foo': None}
    assert [format_error(e) for e in result.errors] == [{
        'locations': [{
            'column': 32,
            'line': 1
        }],
        'message':
        'Client Schema cannot be used for execution.'
    }]
Пример #9
0
def test_builds_a_schema_with_legacy_directives():
    old_introspection = {
        "__schema": {
            "queryType": {"name": "Simple"},
            "types": [
                {
                    "name": "Simple",
                    "kind": "OBJECT",
                    "fields": [
                        {"name": "simple", "args": [], "type": {"name": "Simple"}}
                    ],
                    "interfaces": [],
                }
            ],
            "directives": [
                {"name": "Old1", "args": [], "onField": True},
                {"name": "Old2", "args": [], "onFragment": True},
                {"name": "Old3", "args": [], "onOperation": True},
                {"name": "Old4", "args": [], "onField": True, "onFragment": True},
            ],
        }
    }

    new_introspection = {
        "__schema": {
            "directives": [
                {"name": "Old1", "args": [], "locations": ["FIELD"]},
                {
                    "name": "Old2",
                    "args": [],
                    "locations": [
                        "FRAGMENT_DEFINITION",
                        "FRAGMENT_SPREAD",
                        "INLINE_FRAGMENT",
                    ],
                },
                {
                    "name": "Old3",
                    "args": [],
                    "locations": ["QUERY", "MUTATION", "SUBSCRIPTION"],
                },
                {
                    "name": "Old4",
                    "args": [],
                    "locations": [
                        "FIELD",
                        "FRAGMENT_DEFINITION",
                        "FRAGMENT_SPREAD",
                        "INLINE_FRAGMENT",
                    ],
                },
            ]
        }
    }

    client_schema = build_client_schema(old_introspection)
    second_introspection = graphql(client_schema, introspection_query).data

    assert contain_subset(new_introspection, second_introspection)
Пример #10
0
def test_succeds_on_smaller_equals_than_7_deep_lists():
    schema = GraphQLSchema(query=GraphQLObjectType(
        name='Query',
        fields={
            'foo':
            GraphQLField(
                GraphQLNonNull(
                    GraphQLList(
                        GraphQLNonNull(
                            GraphQLList(
                                GraphQLNonNull(
                                    GraphQLList(GraphQLNonNull(
                                        GraphQLString))))))))
        }))

    introspection = graphql(schema, introspection_query)
    build_client_schema(introspection.data)
def test_fails_on_a_deep_non_null():
    schema = GraphQLSchema(
        query=GraphQLObjectType(
            name='Query',
            fields={
                'foo': GraphQLField(
                    GraphQLList(GraphQLList(GraphQLList(GraphQLNonNull(GraphQLString))))
                )
            }
        )
    )

    introspection = graphql(schema, introspection_query)

    with raises(Exception) as excinfo:
        build_client_schema(introspection.data)

    assert str(excinfo.value) == 'Decorated type deeper than introspection query.'
def test_succeds_on_smaller_equals_than_7_deep_lists():
    schema = GraphQLSchema(
        query=GraphQLObjectType(
            name='Query',
            fields={
                'foo': GraphQLField(
                    GraphQLNonNull(GraphQLList(
                        GraphQLNonNull(GraphQLList(GraphQLNonNull(
                            GraphQLList(GraphQLNonNull(GraphQLString))
                        ))
                    )))
                )
            }
        )
    )

    introspection = graphql(schema, introspection_query)
    build_client_schema(introspection.data)
Пример #13
0
def test_cannot_use_client_schema_for_general_execution():
    customScalar = GraphQLScalarType(name="CustomScalar",
                                     serialize=lambda: None)

    schema = GraphQLSchema(query=GraphQLObjectType(
        name="Query",
        fields={
            "foo":
            GraphQLField(
                GraphQLString,
                args=OrderedDict([
                    ("custom1", GraphQLArgument(customScalar)),
                    ("custom2", GraphQLArgument(customScalar)),
                ]),
            )
        },
    ))

    introspection = graphql(schema, introspection_query)
    client_schema = build_client_schema(introspection.data)

    class data:
        foo = "bar"

    result = graphql(
        client_schema,
        "query NoNo($v: CustomScalar) { foo(custom1: 123, custom2: $v) }",
        data,
        {"v": "baz"},
    )

    assert result.data == {"foo": None}
    assert [format_error(e) for e in result.errors] == [{
        "locations": [{
            "column": 32,
            "line": 1
        }],
        "message":
        "Client Schema cannot be used for execution.",
        "path": ["foo"],
    }]
def test_cannot_use_client_schema_for_general_execution():
    customScalar = GraphQLScalarType(
        name='CustomScalar',
        serialize=lambda: None
    )

    schema = GraphQLSchema(
        query=GraphQLObjectType(
            name='Query',
            fields={
                'foo': GraphQLField(
                    GraphQLString,
                    args=OrderedDict([
                        ('custom1', GraphQLArgument(customScalar)),
                        ('custom2', GraphQLArgument(customScalar))
                    ])
                )
            }
        )
    )

    introspection = graphql(schema, introspection_query)
    client_schema = build_client_schema(introspection.data)

    class data:
        foo = 'bar'

    result = graphql(
        client_schema,
        'query NoNo($v: CustomScalar) { foo(custom1: 123, custom2: $v) }',
        data,
        {'v': 'baz'}
    )

    assert result.data == {'foo': None}
    assert [format_error(e) for e in result.errors] == [
        {'locations': [{'column': 32, 'line': 1}], 'message': 'Client Schema cannot be used for execution.'}
    ]
def test_builds_a_schema_with_legacy_directives():
    old_introspection = {
        "__schema": {
            "queryType": {
                "name": "Simple"
            },
            "types": [{
                "name": "Simple",
                "kind": "OBJECT",
                "fields": [{
                    "name": "simple",
                    "args": [],
                    "type": {
                        "name": "Simple"
                    }
                }],
                "interfaces": []
            }],
            "directives": [{
                "name": "Old1",
                "args": [],
                "onField": True
            }, {
                "name": "Old2",
                "args": [],
                "onFragment": True
            }, {
                "name": "Old3",
                "args": [],
                "onOperation": True
            }, {
                "name": "Old4",
                "args": [],
                "onField": True,
                "onFragment": True
            }]
        }
    }

    new_introspection = {
        "__schema": {
            "directives": [{
                "name": "Old1",
                "args": [],
                "locations": ["FIELD"]
            }, {
                "name": "Old2",
                "args": [],
                "locations": ["FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"]
            }, {
                "name": "Old3",
                "args": [],
                "locations": ["QUERY", "MUTATION", "SUBSCRIPTION"]
            }, {
                "name": "Old4",
                "args": [],
                "locations": ["FIELD", "FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"]
            }]
        }
    }

    client_schema = build_client_schema(old_introspection)
    second_introspection = graphql(client_schema, introspection_query).data

    assert contain_subset(new_introspection, second_introspection)