Ejemplo n.º 1
0
def test_federated_schema_query_service_provide_federation_directives():
    type_defs = """
        type Query {
            rootField: String
        }

        type Review @key(fields: "id") {
            id: ID!
            body: String
            author: User @provides(fields: "email")
            product: Product @provides(fields: "upc")
        }

        type User @key(fields: "email") @extends {
            email: String @external
            reviews: [Review]
        }

        type Product @key(fields: "upc") @extends {
            upc: String @external
            reviews: [Review]
        }
    """

    schema = make_federated_schema(type_defs)

    result = graphql_sync(
        schema,
        """
            query GetServiceDetails {
                _service {
                    sdl
                }
            }
        """,
    )

    assert result.errors is None
    assert sic(result.data["_service"]["sdl"]) == sic("""
            type Query {
                rootField: String
            }

            type Review @key(fields: "id") {
                id: ID!
                body: String
                author: User @provides(fields: "email")
                product: Product @provides(fields: "upc")
            }

            type User @key(fields: "email") @extends {
                email: String @external
                reviews: [Review]
            }

            type Product @key(fields: "upc") @extends {
                upc: String @external
                reviews: [Review]
            }
        """)
Ejemplo n.º 2
0
def test_federated_schema_mark_interface_with_multiple_keys():
    type_defs = """
        type Query

        interface Product @key(fields: "upc sku") {
            upc: String!
            sku: String!
            name: String
            price: Int
        }
    """

    product = FederatedInterfaceType("Product")
    schema = make_federated_schema(type_defs, product)

    assert sic(print_interface(schema.get_type("Product"))) == sic("""
            interface Product {
                upc: String!
                sku: String!
                name: String
                price: Int
            }
        """)

    assert schema.get_type("_Entity") is None
Ejemplo n.º 3
0
def test_federated_schema_mark_type_with_multiple_keys():
    type_defs = """
        type Query

        type Product @key(fields: "upc sku") {
            upc: String!
            sku: String!
            name: String
            price: Int
        }
    """

    product = FederatedObjectType("Product")
    schema = make_federated_schema(type_defs, product)

    assert sic(print_object(schema.get_type("Product"))) == sic("""
        type Product {
            upc: String!
            sku: String!
            name: String
            price: Int
        }
    """)

    assert sic(print_union(schema.get_type("_Entity"))) == sic("""
            union _Entity = Product
        """)
Ejemplo n.º 4
0
def test_purge_directives_retain_federation_directives():
    type_defs = """
        type Query {
            rootField: String
        }

        type Review @key(fields: "id") {
            id: ID!
            body: String
            author: User @provides(fields: "email")
            product: Product @provides(fields: "upc")
        }

        type User @key(fields: "email") @extends {
            email: String @external
            reviews: [Review]
        }

        type Product @key(fields: "upc") @extends {
            upc: String @external
            reviews: [Review]
        }
    """

    assert sic(purge_schema_directives(type_defs)) == sic(type_defs)
Ejemplo n.º 5
0
def test_federated_schema_mark_type_with_key_split_type_defs():
    query_type_defs = """
        type Query
    """

    product_type_defs = """
        type Product @key(fields: "upc") {
            upc: String!
            name: String
            price: Int
        }
    """

    product = FederatedObjectType("Product")
    schema = make_federated_schema(
        [query_type_defs, product_type_defs],
        product,
    )

    assert sic(print_object(schema.get_type("Product"))) == sic("""
            type Product {
                upc: String!
                name: String
                price: Int
            }
        """)

    assert sic(print_union(schema.get_type("_Entity"))) == sic("""
            union _Entity = Product
        """)
Ejemplo n.º 6
0
def test_federated_schema_not_mark_type_with_no_keys():
    type_defs = """
        type Query

        type Product {
            upc: String!
            name: String
            price: Int
        }
    """

    product = FederatedObjectType("Product")
    schema = make_federated_schema(type_defs, product)

    assert sic(print_object(schema.get_type("Product"))) == sic(
        """
            type Product {
                upc: String!
                name: String
                price: Int
            }
        """
    )

    assert schema.get_type("_Entity") is None
Ejemplo n.º 7
0
def test_purge_directives_retain_builtin_directives():
    type_defs = """
        type Query {
            rootField: String
        }

        type Product {
            upc: ID!
            name: String
            label: String @deprecated(reason: "Use name instead")
        }
    """

    assert sic(purge_schema_directives(type_defs)) == sic(type_defs)
Ejemplo n.º 8
0
def test_purge_directives_remove_custom_directives():
    type_defs = """
        directive @custom on FIELD

        type Query {
            rootField: String @custom
        }
    """

    assert sic(purge_schema_directives(type_defs)) == sic("""
            type Query {
                rootField: String
            }
        """)
Ejemplo n.º 9
0
def test_federated_schema_augment_root_query_with_no_keys():
    type_defs = """
        type Query {
            rootField: String
        }
    """

    schema = make_federated_schema(type_defs)

    assert sic(print_object(schema.get_type("Query"))) == sic("""
            type Query {
                rootField: String
                _service: _Service!
            }
        """)
Ejemplo n.º 10
0
def test_purge_directives_remove_custom_directives_with_single_line_description(
):
    type_defs = """
        "Any Description"
        directive @custom on FIELD
        
        type Query {
            rootField: String @custom
        }
    """

    assert sic(purge_schema_directives(type_defs)) == sic("""
            type Query {
                rootField: String
            }
        """)
Ejemplo n.º 11
0
def test_purge_directives_remove_custom_directives_with_block_string_description(
):
    type_defs = '''
        """
        Any Description
        """
        directive @custom on FIELD
        
        type Query {
            rootField: String @custom
        }
    '''

    assert sic(purge_schema_directives(type_defs)) == sic("""
            type Query {
                rootField: String
            }
        """)
Ejemplo n.º 12
0
def test_federated_schema_type_with_multiple_keys():
    type_defs = """
        type Query
        type Product @key(fields: "upc") @key(fields: "sku") {
            upc: String!
            sku: String!
            price: String
        }
    """
    product = FederatedObjectType("Product")
    schema = make_federated_schema(type_defs)

    assert sic(print_object(schema.get_type("Product"))) == sic("""
            type Product {
                upc: String!
                sku: String!
                price: String
            }
        """)
Ejemplo n.º 13
0
def test_federated_schema_augment_root_query_with_interface_key():
    type_defs = """
        type Query {
            rootField: String
        }

        interface Product @key(fields: "upc") {
            upc: ID!
        }
    """

    schema = make_federated_schema(type_defs)

    assert sic(print_object(schema.get_type("Query"))) == sic("""
            type Query {
                rootField: String
                _service: _Service!
            }
        """)
Ejemplo n.º 14
0
def test_federated_schema_query_service_with_multiple_keys():
    type_defs = """
        type Query {
            rootField: String
        }

        type Product @key(fields: "upc sku") {
            upc: String!
            sku: String!
            name: String
            price: Int
        }
    """

    schema = make_federated_schema(type_defs)

    result = graphql_sync(
        schema,
        """
            query GetServiceDetails {
                _service {
                    sdl
                }
            }
        """,
    )

    assert result.errors is None
    assert sic(result.data["_service"]["sdl"]) == sic(
        """
            type Query {
                rootField: String
            }

            type Product @key(fields: "upc sku") {
                upc: String!
                sku: String!
                name: String
                price: Int
            }
        """
    )
Ejemplo n.º 15
0
def test_federated_schema_augment_root_query_with_type_key():
    type_defs = """
        type Query {
            rootField: String
        }

        type Product @key(fields: "upc") {
            upc: ID!
        }
    """

    schema = make_federated_schema(type_defs)

    assert sic(print_object(schema.get_type("Query"))) == sic("""
            type Query {
                rootField: String
                _service: _Service!
                _entities(representations: [_Any!]!): [_Entity]!
            }
        """)
Ejemplo n.º 16
0
def test_federated_schema_query_service_ignore_custom_directives():
    type_defs = """
        directive @custom on FIELD

        type Query {
            rootField: String
        }

        type User @key(fields: "email") @extends {
            email: String @external
        }
    """

    schema = make_federated_schema(type_defs)

    result = graphql_sync(
        schema,
        """
            query GetServiceDetails {
                _service {
                    sdl
                }
            }
        """,
    )

    assert result.errors is None
    assert sic(result.data["_service"]["sdl"]) == sic(
        """
            type Query {
                rootField: String
            }

            type User @key(fields: "email") @extends {
                email: String @external
            }
        """
    )
Ejemplo n.º 17
0
def test_federated_schema_without_query_is_valid():
    type_defs = """
    type Product @key(fields: "upc") {
        upc: String!
        name: String
        price: Int
        weight: Int
    }
    """

    schema = make_federated_schema(type_defs)
    result = graphql_sync(
        schema,
        """
            query GetServiceDetails {
                _service {
                    sdl
                }
            }
        """,
    )

    assert result.errors is None
    assert sic(result.data["_service"]["sdl"]) == sic(type_defs)