Required property not signified as required in typeRef schema is not a bug

I should not have spent so much time on this issue if I would have thought more about it first. This is not a bug report but hopefully a help to anyone who comes across this.

In my schema I have a edge to another type such as a Post’s edge to its author.

type User {
  id: ID
  name: String!
  isActive: Boolean!
}
type Post {
  id: ID
  title: String!
  author: User!
}

Seeing that I have a really long schema and not this small example I rely heavily on Schema Explorer in the API Explorer on Slash to help me remember what fields are required when writing mutations in my app.

I wrote a mutation for a new Post:

mutation {
  addPost(input: [{
    title: "New Post Title"
    author: {
      name: "New User"
    }
  }]) {
    numUids
  }
}

This would appear to work correctly because the author edge has the type UserRef with the predicates:

id: ID
name: String
isActive: Boolean

But it actually would error out with something similar to

couldn’t rewrite mutation addPost because failed to rewrite mutation payload because the type User requires a vale for field isActive, but no value present.

I spent way too long trying to find the problem because the field was not required on the UserRef, not fully reading the error specifically stated the User type.

This is actually correct, because the UserRef type is used for referencing an existing or adding a new User on the same edge. When referencing an existing user, I do not care about adding all of the required fields, I just need the id. But when adding a new User, I should’ve gone back to the User type to see what fields are required.


A way around this:

When generating the GraphQL schema I can define a description of a type by adding a quoted string above the type declaration. This description is added to the type only and is not propagated to the *Ref that is generated for the type. Would it be possible to add a description that the Ref type should only be used for reference and that it does not display required fields if adding a new item. Maybe worded like:

The UserRef type is used as a reference to link an existing User and add a new User. A new User may have required fields which is not shown by this UserRef type.

That may be a little wordy, but just an idea to save some time for future people like myself who has an occasional doofus moment.