joarwilk / gql2flow

Convert a GraphQL Schema to a flow definition
97 stars 24 forks source link

GraphQL SDL and FlowType descrepencies #41

Open mikestaub opened 6 years ago

mikestaub commented 6 years ago

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

mikestaub commented 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;
}
mikestaub commented 6 years ago

My proposed solution: https://github.com/mikestaub/gql2flow/commit/159facd60ac6559490bc38a8e0742ec7e131ae4e