joarwilk / gql2flow

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

Optional fields on Input types are only set as maybe and not optional #33

Closed META-DREAMER closed 7 years ago

META-DREAMER commented 7 years ago

Lets say there's an input type:

input UpdateProfileInput {
  id: ID!
  name: string
  email: string
}

The generated type is:

declare type UpdateProfileInput = {
  id: string;
  name: ?string;
  email: ?string;
}

Which requires that both name and email be provided. This input object would falsely give an error:

const input = {
  id: '123',
  name: 'John Doe',
}

To get rid of the error right now you have to do:

const input = {
  id: '123',
  name: 'John Doe',
  email: undefined
}

The generated type should be:

declare type UpdateProfileInput = {
  id: string;
  name?: ?string;
  email?: ?string;
}
META-DREAMER commented 7 years ago

@joarwilk Could we get this released on NPM ?