Skip to content

Wrong type annotation generated for fragment decoder #44

Description

@entropic77

This is a query for the Magento API, used to get a shopping cart with products:

fragment SimpleProduct on SimpleProduct {
    sku
}

fragment VirtualProduct on VirtualProduct {
    sku
}

fragment DownloadableProduct on DownloadableProduct {
    sku
}

fragment ConfigurableProduct on ConfigurableProduct {
    sku
}

fragment BundleProduct on BundleProduct {
    sku
}

fragment GroupedProduct on GroupedProduct {
    sku
}

fragment CartItem on CartItemInterface {
    __typename
    ...on SimpleCartItem {
        product {
            ...Product
        }
    }
    ...on VirtualCartItem {
        product {
            ...Product
        }
    }
    ...on DownloadableCartItem {
        product {
            ...Product
        }
    }
    ...on ConfigurableCartItem {
        product {
            ...Product
        }
    }
    ...on BundleCartItem {
        product {
            ...Product
        }
    }
}

fragment Product on ProductInterface {
    __typename
    ... on SimpleProduct {
        ...SimpleProduct
    }
    ... on VirtualProduct {
        ...VirtualProduct
    }
    ... on DownloadableProduct {
        ...DownloadableProduct
    }
    ... on ConfigurableProduct {
        ...ConfigurableProduct
    }
    ... on BundleProduct {
        ...BundleProduct
    }
    ... on GroupedProduct {
        ...GroupedProduct
    }
}

query getCart($cartId: String!) {
    cart(cart_id: $cartId) {
        items {
            ...CartItem
        }
    }
}

It will generate the file Fragments/Product.elm containing the following decoder:

decoder : Int -> Json.Decode.Decoder (b -> b) -> Json.Decode.Decoder b

Compiling this will fail with:

The argument is:

    Json.Decode.Decoder (b1 -> b1)

But (|>) is piping it to a function that expects:

    Json.Decode.Decoder (Product_Specifics -> b)

Changing it to this will make it compile and work:

decoder : Int -> Json.Decode.Decoder (Product_Specifics -> b) -> Json.Decode.Decoder b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions