GraphQL allows creation of a document that has an invalid relation

Sorry to bother you. There is probably a very simple answer for this.

I have two collections:

type Observer @collection(name: "observers") {
    fullName: String
    ownedObservatories: [Observatory!]! @relation(name: "observatory_owner")
}

type Observatory @collection(name: "observatories") {
    description: ObservatoryDescription!
    owner: Observer! @relation(name: "observatory_owner")
}

Curiously Fauna allows me to create an ‘Observatory’ that points to a non-existent ‘Observer’:

mutation {
    createObservatory(data: {
        description: {
            observatoryName: "foo"
        }
        owner: { connect: "31415927" }
    }){ _id }
}

But when I go to query it:

query {
    findObservatoryByID(id: "279295350291825161") {
        description {
            observatoryName
        }
        owner {
            _id
        }
    }
}

I get this error:

{
  "data": {
    "findObservatoryByID": null
  },
  "errors": [
    {
      "message": "Cannot return null for non-nullable type (line 8, column 5):\n    owner {\n    ^",
      "path": [
        "findObservatoryByID",
        "owner"
      ],
      "locations": [
        {
          "line": 8,
          "column": 5
        }
      ]
    }
  ]
}

Everything works fine if I give the ‘createObservatory’ mutation a valid ‘Observer’ as the owner.

Is there a syntax that will cause the mutation to fail if the relation is invalid?

Again, my apologies if this behavior is discussed in the docs.

1 Like

Hi @oopfan,

we already ticket this known issue and we are working for fixing it.

Luigi