Open mikestaub opened 6 years ago
I see now this was previously discussed: https://github.com/joarwilk/gql2flow/issues/12
This makes sense to me but the issue still applies to input types. For example this graphql definition:
input CreateUserInput {
name: String!
role: String
}
Will generate this FlowType:
declare type CreateUserInput = {
name: string;
role?: ?string;
}
Which is too lax. It should be:
declare type CreateUserInput = {
name: string;
role?: string;
}
My proposed solution: https://github.com/mikestaub/gql2flow/commit/159facd60ac6559490bc38a8e0742ec7e131ae4e
FlowType allows 3 cases of optional fields and nullable types as explained here: https://stackoverflow.com/questions/37165601/flowtype-how-to-annotate-union-with-optional-fields/37174244#37174244
When a user marks a GraphQL field as NonNull, the current code assumes the 3rd case, which is incorrect. It should assume the 2nd as the GraphQL spec does not allow the 3rd case. https://github.com/joarwilk/gql2flow/blob/master/util/interface.js#L104