strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
4.01k stars 533 forks source link

schema-codegen should generate mutation methods #3249

Open c0dezer019 opened 11 months ago

c0dezer019 commented 11 months ago

Feature Request Type

Description

What it does

schema-codegen currently generates the following from the schema:

import strawberry

@strawberry.type
class Member:
    username: str

@strawberry.type
class Query:
    member: Member | None

@strawberry.type
class Mutation:
    create_user: Member

schema = strawberry.Schema(query=Query, mutation=Mutation)

Here's the schema for reference:

schema {
    query: Query
    mutation: Mutation
}

type Member {
    username: String!
}

type Query {
    member: Member
}

type Mutation {
    createMember(name: String!): Member!
}

What it should do

Instead, it should generate the following for our mutations:

@strawberry.type
class Mutation:
    @strawberry.mutation
    def create_member(self, name: str) -> Member:
        return Member(name=name)

Upvote & Fund

Fund with Polar

patrick91 commented 11 months ago

One note on this, we'll probably generate an empty method instead of what you wrote, as it won't be easy to generate something that's actually valid (and useful)

@strawberry.type
class Mutation:
    @strawberry.mutation
    def create_member(self, name: str) -> Member:
        ...