GraphQL UsersPermissionsUsers required fields shouldn't be required

System Information
  • Strapi Version: 4.3.9
  • Operating System: Node Alpine Docker
  • Database: MariaDB
  • Node Version: 16
  • NPM Version: 7.20.5
  • Yarn Version:

I am using GraphQL as my primary API method, which means that it’s convenient to make use of GraphQL codegen to generate types for my frontend. I noticed that there is very likely a bug in the GraphQL schema that’s causing some issues. The email and username fields of UsersPermissionsUser type are type String!. This doesn’t make sense because this type describes a response, which isn’t required to have any fields at all. The only time anything should be typed as required(!) is inside of GraphQL inputs, no?

It seems perhaps there is some confusion in the schema.json attributes.[fieldname].required attribute, which is used to determine whether the field is required during CREATION of an item, not whether it’s required in the API response.

This causes a headache because I’m frequently passing objects that match the general shape of a UsersPersmissionsUserEntity into React function component props, except they might be missing an email field. Typescript throws a warning because the generated type from the GraphQL endpoint makes it seem as though every User object will come back with a username and email field 100% of the time, though on the frontend I rarely need to provide an email field to any component.

The same is true for any EntityResponseCollection as well where it says data and meta are required, even though I make requests frequently that don’t request meta: