Skip to content

Add docstring to generated code based on schema description#362

Merged
DamianCzajkowski merged 8 commits intomirumee:mainfrom
PaleNeutron:codegen_docstring
Sep 30, 2025
Merged

Add docstring to generated code based on schema description#362
DamianCzajkowski merged 8 commits intomirumee:mainfrom
PaleNeutron:codegen_docstring

Conversation

@PaleNeutron
Copy link
Contributor

@PaleNeutron PaleNeutron commented Mar 13, 2025

Implement #361

Now generated method and class will have docstring based on schema field and type description

output example

class Query:
    @classmethod
    def book_id(cls, para: bookIdParas) -> bookIdFields:
        """get book id from my database"""
        arguments: Dict[str, Dict[str, Any]] = {
            "para": {"type": "bookIdParas!", "value": para}
        }
        cleared_arguments = {
            key: value for key, value in arguments.items() if value["value"] is not None
        }
        return bookIdFields(field_name="bookId", arguments=cleared_arguments)

class bookIdFields(GraphQLField):
    """my book id"""

    book_id: "bookIdGraphQLField" = bookIdGraphQLField("book_id")

    def fields(self, *subfields: bookIdGraphQLField) -> "bookIdFields":
        """Subfields should come from the bookIdFields class"""
        self._subfields.extend(subfields)
        return self

    def alias(self, alias: str) -> "bookIdFields":
        self._alias = alias
        return self

@jrsquared
Copy link

I was looking for this feature! Any chance this can get merged?

@DamianCzajkowski DamianCzajkowski linked an issue Sep 29, 2025 that may be closed by this pull request
@DamianCzajkowski
Copy link
Collaborator

Hi @PaleNeutron, looks good!
I noticed there are some conflicts with the main branch at the moment. Could you resolve those conflicts and also add some unit tests to your pull request?

@PaleNeutron
Copy link
Contributor Author

@DamianCzajkowski , finished.

@DamianCzajkowski DamianCzajkowski merged commit 9773a57 into mirumee:main Sep 30, 2025
5 checks passed
@jrsquared
Copy link

🙌 any idea when this will get cut into a release? very excited for this in my projects.

@DamianCzajkowski
Copy link
Collaborator

@jrsquared, I'm planning to do a release at the beginning of next week.

@jrsquared
Copy link

awesome, thank you!

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

Successfully merging this pull request may close these issues.

Add docstring to generated field

3 participants