joarwilk / gql2flow

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

Generate correct types for queries and mutations #43

Closed ragelo closed 6 years ago

ragelo commented 6 years ago

Hi! Will be nice to see such updates! What do you think?

Schema example

type Thing {
  name: String!
}

input ThingsFilter {
  nameStartFrom: String
}

type Query {
  things(count: Number!, filter: ThingsFilter): [Thing!]
}

input ChangeProjectTitleInput {
  name: !String
}
type Thing {
  thing: Thing!
}

type Mutation {
  addThing(input: AddThingInput!): AddThingPayload
}

Current output:

...
declare type Query = {
  things: ?Array<Thing>;
}

declare type AddThingInput = {
  name: string;
}

declare type AddThingPayload = {
  thing: Thing;
}

declare type Mutation = {
  addThing: ?AddThingPayload;
}

Expected output:

...
declare type ViewerSubjectsArgs = {
  count: number;
  filter: ?ThingsFilter;
}
declare type Query = {
  things<ViewerSubjectsArgs>(): ?Array<Thing> | Promise<?Array<Thing>>;
}

declare type AddThingInput = {
  name: string;
}

declare type MutationAddThingArgs = {
  input: AddThingInput;
}

declare type AddThingPayload = {
  thing: Thing;
}

declare type Mutation = {
  addThing<MutationAddThingArgs>(): ?AddThingPayload | Promise<?AddThingPayload>;
}
joarwilk commented 6 years ago

This repo is not maintained, sorry