Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type annotation generated for fragment decoder #44

Open
entropic77 opened this issue Dec 22, 2023 · 0 comments
Open

Wrong type annotation generated for fragment decoder #44

entropic77 opened this issue Dec 22, 2023 · 0 comments

Comments

@entropic77
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant