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

Generate single class for common types and shorten class name #1860

Open
rahul-gj opened this issue Feb 20, 2024 · 1 comment
Open

Generate single class for common types and shorten class name #1860

rahul-gj opened this issue Feb 20, 2024 · 1 comment

Comments

@rahul-gj
Copy link

Is your feature request related to a problem? Please describe.
Currently we generate individual classes even for same type in schema.

for below example:

schema.graphql

type Query {
  studentQuery(ids: [ID!]!): [Student]
}

type Person {
  id: ID!
  name: String!
}

type Student {
  id: ID!
  name: String!
  father: Person!
  mother: Person!
  friends: [Person!]
}

query.graphql

query Enrolments($ids: [ID!]!) {
  studentQuery(ids: $ids) {
    id
    name
    father {
      id
      name
    }
    mother {
      id
      name
    }
    friends {
      id
      name
    }
  }
}

and pyproject.toml

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

we generate following enrolments.py in graphql_client folder

...
class EnrolmentsStudentQuery(BaseModel):
    id: str
    name: str
    father: "EnrolmentsStudentQueryFather"
    mother: "EnrolmentsStudentQueryMother"
    friends: Optional[List["EnrolmentsStudentQueryFriends"]]


class EnrolmentsStudentQueryFather(BaseModel):
    id: str
    name: str


class EnrolmentsStudentQueryMother(BaseModel):
    id: str
    name: str


class EnrolmentsStudentQueryFriends(BaseModel):
    id: str
    name: str

Describe the solution you'd like
I would like to have an option to remove duplicate classes based on same type with same fields
for example would like to generate following enrolments.py in graphql_client folder for above inputs

class EnrolmentsStudentQuery(BaseModel):
    id: str
    name: str
    father: "Person"
    mother: "Person"
    friends: Optional[List["Person"]]


class Person(BaseModel):
    id: str
    name: str

Describe alternatives you've considered
Need to modify generated classes as no alternative. Planning to use inheritance to override such common fields with manually generated classes.

Additional context
N/A

@sir-sigurd
Copy link

@rahul-gj
it looks like you are using https://github.com/mirumee/ariadne-codegen, why did you create an issue here?

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