Git Product home page Git Product logo

graphql-typescript-apollo-starter's Introduction

Graphql typescript apollo starter

A starter template for developing a graphql server, can also be used as a mock server simulating a book rating site, similar to goodreads. It uses typescript and express, and it uses jest as a testing framework. It's configured with prisma playground, and subscriptions support.

This project follows the ideas, defined in the article from apollo regarding schema modularization Modularizing your GraphQL schema code

This project uses the wonderful nps script manager, you can read more about it here and download it with npm install -g nps

Since I'm sharding the entire project to chunks of typedefs with the gql tag, you can see the full schema in src/__typedefs/schema.graphql

Getting started

  • Run in development mode with hot reloading nps dev

  • Build nps build

  • Test nps test

  • Test and watch nps test.watch

  • Generate types and schemas nps generateDefs. do this after changes to the api to keep the types in sync.

Project structure:

   .graphqlconfig - configuration for the graphql cli tool
   package-scripts.js - this is where all the nps scripts are
   
   test/ 
   src/ - |
         | - index.ts
         | - mocks.ts: mock data, replace it with a database layer for most production apps
         | - __typedefs/ - containes type definitions and graphql schema
         | - graphql/ - |
                        | - enums/: different enums should go here
                        | - scalarTypes/: used for validation and mutating input/output
                        | - schemaShards/: your resolvers and typeDefs should go here
                        | - helpers/: includes helper functions for manipulating and merging schemas 
                        | - schema.ts: this file merges all the different graphql parts and export an executable schema

Api

The graphql api is self documented, you can access the documentations through the prisma playground after running the server, or by going through the typescript or full graphql schema in src/__typedefs.

Example usage

Let's see an example, you can run the development server using nps dev, and go to http://localhost:3000/graphql (or change port with the PORT environment variable) to use the playground. In the playground you can subscribe to the writerCreated subscription like this in one tab:

subscription{
  writerCreated{
    name
    id
    birthDay
    country
  }
}

And create new books like this on another:

mutation createWriter($input:WriterCreateInput!) {
  writerCreate(input:$input) {
    name
    id
  }
}

with this input.

{
  "input": {
    "name": "liron navon",
    "birthDay": "02/02/1994",
    "country": "IL"
  }
}

graphql-typescript-apollo-starter's People

Contributors

liron-navon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.