Skip to content

rachel-church/sample-graphql-ts-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Boilerplate GraphQL server with TypeScript


Features

  • Static type generation: TypeScript types for GraphQL queries & mutations are generated in a build step
  • Tooling: Out-of-the-box support for GraphQL Playground

Getting started

  1. Ensure that yarn is installed by running yarn --version.
  2. Install dependencies by running yarn
  3. Run yarn start to start the GraphQL server on http://localhost:4000. Going to this address opens the GraphQL Playground.

Type Generation

This project uses GraphQL Codegen to generate TS from the schema.graphql file.

Running yarn or yarn gen will re-generate the schema.d.ts file. You will need to do this if you make any edits to schema.graphql.

Sample GraphQL queries:

query AllEmployees {
  employees {
    id
    firstName
    age
  }
}

query AllEmployeesWithManagerInfo {
  employees {
    id
    firstName
    age
    manager {
      id,
      firstName,
      manager {
        id
        firstName
      }
    }
  }
}

query EmployeesUnder30 {
  employees(where: { age: { lessThanOrEqualTo: 30 } }) {
    id
    firstName
    lastName
    age
  }
}

mutation CreateMe {
  createEmployee(fields: { firstName: "Rachel", lastName: "Church", age: 25 }) {
    id,
    age,
    firstName
  }
}

mutation updateEmployee {
  updateEmployee(id: "3c7fae36", fields: { age: 26 }) {
    age
    id
  }
}

mutation updateEmployeeFromVariable($employeeId: String!) {
  updateEmployee(id: $employeeId, fields: { lastName: "Fletcher" }) {
    age
    id
  }
}

fragment comparisonFields on Employee {
  firstName,
  age,
  manager {
    firstName,
    age
  }
}

query MultipleQueries {
  greysondsad: employee(id: "FNFmsvQpIs") {
    ...comparisonFields
  }
  johan: employee(id: "XXYCahs8wX") {
    ...comparisonFields
  }
}

About

A sample employee graphql server using Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published