Skip to content

Conversation

@philschatz
Copy link
Owner

@philschatz philschatz commented Apr 9, 2018

In order to switch to TypeScript, GraphQL responses should also be strongly typed.

This uses GitHub's GraphQL Schema combined with a GraphQL Query to produce a TypeScript definition of the response.

See ./data/README.md for instructions on updating the Schema.

Run node ./data/build-from-query.js to generate the TypeScript definition files.

Example

Given the following GraphQL Query:

query getCardAndColumnAutomationCards($url: URI!) {
  resource(url: $url) {
    ... on Issue {
      projectCards(first: 10) {
        nodes {
          id
          url
          column {
            name
            id
          }
        }
      }
    }
  }
}

It generates a TypeScript definition like the following:

export interface GetCardAndColumnAutomationCardsInput {
  url: any;
}

export interface SelectionOnColumn {
  name: string;
  id: string;
}

export interface SelectionOnNodes {
  id: string;
  url: any;
  column: SelectionOnColumn | null;
}

export interface SelectionOnProjectCards {
  nodes: Array<SelectionOnNodes | null> | null;
}

export interface IFragmentSpreadOnIssue {
  projectCards: SelectionOnProjectCards;
}

export interface GetCardAndColumnAutomationCards {
  resource: Partial<IFragmentSpreadOnIssue> | null;
}

TODO

  • create TypeScript definitions for GraphQL responses based on the Schema
  • convert the JavaScript files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants