https://github.com/tomyitav/graphql-server-typed
Using typescript and gql-code-gen for easy graphql setup
https://github.com/tomyitav/graphql-server-typed
apollo-server dependency-injection graphql mvc-architecture nodejs typescript
Last synced: 3 months ago
JSON representation
Using typescript and gql-code-gen for easy graphql setup
- Host: GitHub
- URL: https://github.com/tomyitav/graphql-server-typed
- Owner: tomyitav
- License: mit
- Created: 2017-11-01T20:36:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T14:48:44.000Z (about 1 year ago)
- Last Synced: 2024-04-15T01:11:03.856Z (about 1 year ago)
- Topics: apollo-server, dependency-injection, graphql, mvc-architecture, nodejs, typescript
- Language: TypeScript
- Homepage: https://medium.com/@tomyitav/graphql-server-for-enterprise-development-675d2ff2d0ed
- Size: 961 KB
- Stars: 34
- Watchers: 5
- Forks: 4
- Open Issues: 49
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-server-typed
[](./LICENSE)
[](https://github.com/prettier/prettier)
[![renovate-app badge][renovate-badge]][renovate-app][renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
[renovate-app]: https://renovateapp.com/Boilerplate project for [create-graphql-app](https://github.com/tomyitav/create-graphql-app) cli.
Create a fully configured, production ready graphql server, using
+ typescript
+ [graphql-code-generator](https://github.com/dotansimha/graphql-code-generator)
+ graphql-subscriptions
+ merge-graphql-schemas
+ Dependency injection with `injection-js`This project demonstrates how to generate typescript types from graphql schema, using Graphql code generetor library.
## Installation
Clone the repository and run `npm install`
```
git clone https://github.com/tomyitav/graphql-server-typed.git
npm install
```## Build and start server instance
#### Build command
Running the command
```
npm run build
```Or on windows machine, run
```
npm run build:win
```will generate typescript types, and transpile code to *dist* folder
#### How to start server instance after building
```
npm start
```## Run server directly with ts-node
```
npm start:dev
```#### Watch for code changes
```
npm run start:watch
```This will monitor your changes and will automatically restart the server.
The server will run on port 8080.
You can change this by editing the config file.## Code Formatting
We use Prettier and Tslint to format and enforce standards on our code.
Both will run on the project automatically before each commit.Prettier rewrites code according to the .prettierrc.json configuration file.
If you want to activate prettier manually (on all .ts files inside src folder) without committing, run:```
npm run prettier
```Tslint will check rules found in the tslint.json configuration file.
If you want to check tslint manually (on all .ts files inside src folder) without committing, run:```
npm run tslint
```## Type generation using gql codegen
```
npm run generate
```This will automatically generate types in types.d.ts file!
generate command is executed in every build## Project structure
We use the function `makeExecutableSchema()` from graphql-tools to to combine our
types and resolvers. Instead of passing one large string for our schema, we
split our types and resolvers to multiple files, located in graphql directory in
types and resolvers directories. This way, we avoid schema complexity by using
merge-graphql-schemas:```js
import * as path from "path";
import {makeExecutableSchema} from "graphql-tools";
import {fileLoader, mergeTypes, mergeResolvers} from "merge-graphql-schemas";
import {GraphQLSchema} from "graphql";const typesArray = fileLoader(path.join(__dirname, '../types'), { recursive: true });
const resolversArray = fileLoader(path.join(__dirname, '../resolvers'));
const allTypes = mergeTypes(typesArray);
const allResolvers = mergeResolvers(resolversArray);
let schema: GraphQLSchema;
schema= makeExecutableSchema({
typeDefs: allTypes,
resolvers: allResolvers
});export default schema;
```So as your project grows - you can extend the schema by adding new type in types
directory, and adding matching resolver file in resolvers directory. The schema
is updated automatically.## Deploy server to production :rocket:
First, make sure you have [now-cli](https://zeit.co/now) installed.
Then, execute the following command:```
npm run deploy
```That's it! The server will be deployed on *now*
## Run server as AWS lambda
See the following [project](https://github.com/tomyitav/apollo-typed-lambda) for setting up aws lambda integration
## Connect to the server from client app
See the following [example](https://github.com/tomyitav/apollo-angular-client-starter) on how to connect to the server using apollo-angular.