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

Mixin not stripped from Fragments (take 2) #297

Open
dhay opened this issue Jun 4, 2024 · 4 comments
Open

Mixin not stripped from Fragments (take 2) #297

dhay opened this issue Jun 4, 2024 · 4 comments

Comments

@dhay
Copy link

dhay commented Jun 4, 2024

I'm still seeing issues when adding a @mixin to a fragment. I saw #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
@jukiewiczm
Copy link

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
Copy link

@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?

@dhay
Copy link
Author

dhay commented Sep 19, 2024

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?

@jukiewiczm
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants