ariadne-codegen icon indicating copy to clipboard operation
ariadne-codegen copied to clipboard

Mixin not stripped from Fragments (take 2)

Open dhay opened this issue 1 year ago • 5 comments

I'm still seeing issues when adding a @mixin to a fragment. I saw https://github.com/mirumee/ariadne-codegen/issues/176, but the issue persists. In my case, I'm trying to add the mixin to the fragment itself, not a field within the fragment.

sample-schema.graphql

type Item {
    id: ID
}

type Mutation {
    change_item(id: ID!): Item
}

sample-queries.graphql

fragment Item on Item @mixin(from: "sample_mixin", import: "ItemMixin") {
    id
}
mutation my_mutation($id: ID!) {
    change_item(id: $id) {
        ...Item
    }
}

sample_mixin.py

class ItemMixin:
    pass

sample.toml

[tool.ariadne-codegen]
schema_path = "sample-schema.graphql"
queries_path = "sample-queries.graphql"

Running ariadne-codegen --config sample.toml results in a client.py that looks like this:

class Client(AsyncBaseClient):
    async def my_mutation(self, id: str, **kwargs: Any) -> MyMutation:
        query = gql(
            """
            mutation my_mutation($id: ID!) {
              change_item(id: $id) {
                ...Item
              }
            }

            fragment Item on Item @mixin(from: "sample_mixin", import: "ItemMixin") {
              id
            }
            """
        )
        variables: Dict[str, object] = {"id": id}
        response = await self.execute(
            query=query, operation_name="my_mutation", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return MyMutation.model_validate(data)
$ pip list | grep ariadne
ariadne-codegen           0.13.0

dhay avatar Jun 04 '24 22:06 dhay

I confirm this doesn't work currently. Seems like the PR in the other issue addresses only the part when the mixin is defined in a field, not on the entire fragment.

jukiewiczm avatar Jun 28 '24 15:06 jukiewiczm

@dhay I've just rechecked today and got surprised as besides obviously wrong GraphQL code, my queries are still working with the unstripped mixin directive, I have no idea why. Does it fail for you?

jukiewiczm avatar Sep 19 '24 14:09 jukiewiczm

It’s definitely still an issue. In fact I just ran into it again in another project I was recently working on. Maybe it depends on which server implantation is in play? We’re using the Node.js federation server. Perhaps it’s more strict about GraphQL syntax than other servers?

dhay avatar Sep 19 '24 19:09 dhay

It’s definitely still an issue. In fact I just ran into it again in another project I was recently working on. Maybe it depends on which server implantation is in play? We’re using the Node.js federation server. Perhaps it’s more strict about GraphQL syntax than other servers?

Probably. I'm using Hasura and it's quite surprisingly letting this one go

jukiewiczm avatar Sep 19 '24 20:09 jukiewiczm

Same issue here

datenzar avatar Apr 24 '25 09:04 datenzar