Skip to content

relationships aren't marked as required #251

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

Closed
glentakahashi opened this issue Oct 25, 2019 · 3 comments
Closed

relationships aren't marked as required #251

glentakahashi opened this issue Oct 25, 2019 · 3 comments

Comments

@glentakahashi
Copy link

glentakahashi commented Oct 25, 2019

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
}
@adrianschneider94
Copy link

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.

@erikwrede
Copy link
Member

erikwrede commented Feb 15, 2023

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.

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants