Skip to content

johnrazeur/generator-graphql-typescript

Repository files navigation

generator-graphql-typescript NPM version Build Status Coverage percentage

Create a Graphql API in typescript with type-graphql and Typeorm

Installation

First, install Yeoman and generator-rest-express-typescript using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-graphql-typescript

Then generate your new project:

yo graphql-typescript myapp

Getting Started

  • Run npm start to preview and watch for changes
  • Run npm run build to create the production version
  • Run npm run test to lauch jest test

Queries

Login

query login(
    input: $input
  ) {
    ... on LoginType {
      __typename
      token
    }
    ... on UserError {
      __typename
      message
    }
  }
}

Get projects

You need to put the token you get from the login query to perform this query. Prefix the authorization header with bearer.

{
  "Authorization": "bearer thetoken"
}
query {
  projects { 
    name,
    owner { email }
  }
} 

Mutations

Register

mutation {
  register(
    input: $input
  ) {
    ... on User {
      __typename
      username
      email
    }
    ... on UserError {
      __typename
      message
    }
  }
}

Add project

You need to put the token you get from the login query to perform this query. Prefix the authorization header with bearer.

{
  "Authorization": "bearer thetoken"
}
mutation {
  createProject(
    input: $input
  ) {
    __typename
    ... on Project {
      name
    }
    ... on UserError {
      message
    }
  }
}

TODO 🚧

  • Add subcommand to create a new resolver

Contribute

See the contributing docs.

License

MIT © Clément Lafont