Improve GraphQL Schema for required fields

Required relations and fields should be represented in the schema with an exclamation mark at the end.

This would make it a lot easier to use automated code generation for TypeScript and Flow users.

hey @denis.augsburger thank you very much for your request!

Can you please provide an example of something that behaves as you are suggesting?

I couldn’t find a product that already implements this functionality.

In this video a contentful developer explaines at around the 10th minute: “Third design decision: Content Type Validations are re-used to derive links between types”.
My suggestion is to bring it a little bit further and re-use the Content Type Validations to define required/mandatory fields in the schema.

As an example: I define a blogPost with a required title and a required connection to an Author. I would expect the following SDL:

type BlogPost {
title: String!
author: Author!
}

As a result, the TypeScript Definitions can be correctly derived from the schema. Compare also with object types and fields

Thank you very much for the details, we’ll look into it!

Are you still looking into it? We are running into the exact same issue as denis.augsburger. If we cant trust the graphql schema, its quite hard derive types from schema that are trustable.

This seems to be a “duplicate” of this newer, more upvoted feature request: Make required fields non-nullable in GraphQL schema. Could the votes be combined? :slightly_smiling_face:

thank you @ristomatti! I’m going to close this, and while votes cannot be moved, we are manually going over the request every now and then, we’ll consider this :slight_smile:

1 Like

Hey everyone, we finally made it! :tada: :tada: :tada:

We just shipped a new X-Exclude-Invalid header that you can add to change the GraphQL types of required fields:

Please let us know what you think!

1 Like