graphene-sqlalchemy icon indicating copy to clipboard operation
graphene-sqlalchemy copied to clipboard

relationships aren't marked as required

Open glentakahashi opened this issue 6 years ago • 1 comments

given this code:

class Parent(db.Model):
    __tablename__ = "parent"
    id = db.Column(Integer, primary_key=True)

    children = db.relationship("Child", back_populates="parent")

class Child(db.Model):
    __tablename__ = "child"
    id = db.Column(Integer, primary_key=True)

    parent_id = db.Column(Integer, ForeignKey("parent.id"), nullable=False)
    parent = db.relationship("Parent", back_populates="children")

I would expect this to be generated:

type Parent {
  id: ID!
  children: [Child!]!
}
type Child {
  id: ID!
  parent: Parent!
}

However this is what gets generated:

type Parent {
  id: ID!
  children: [Child]
}
type Child {
  id: ID!
  parent: Parent
}

glentakahashi avatar Oct 25 '19 20:10 glentakahashi

This is a important feature because it simplifies writing the frontend code. I use the graphql code generator with typescript and all I have to consider every time when I use a relationship, if a value could be null or not.

adrianschneider94 avatar May 31 '20 21:05 adrianschneider94

resolved in #367 for :nrelationships. As argued in the PR review, we cannot reliably determine the nullability or non-nullability for :1-relationships just based on the SQLAlchemy model. Client controlled nullability (GQL Spec RFC) will resolve this in the future. For now, you can customize the field type of :1relationship fields using the ORMField.

erikwrede avatar Feb 15 '23 10:02 erikwrede

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.

github-actions[bot] avatar Aug 15 '23 00:08 github-actions[bot]