Skip to content

huy97/appsync_local

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS AppSync GraphQL API Locally Mocking

Introduction

  • This project using GraphQL Yoga or Apollo Server to running AWS AppSync GraphQL API locally\
  • Your project lambdas resolver must be following format {typeName}/{fieldName}/index.(t|j)s
  • Lambda folder structure must be following:
├── lambdas
│   ├── Query
│   │   └── test
│   │       └── index.ts
└── server.ts

Installation

npm install --save-dev appsync-dev-server

or

yarn add --dev appsync-dev-server

Usage

// Apollo Server
import path from "path";
import { createApolloServer } from "appsync-dev-server";

const lambdaFolder = path.resolve(__dirname, "lambdas");
const graphqlFolder = path.resolve(__dirname, "graphql");

createApolloServer({
  port: 4000,
  graphqlDir: graphqlFolder,
  lambdaDir: lambdaFolder,
});

or

// GraphQL Yoga Server
import path from "path";
import { createYogaServer } from "appsync-dev-server";

const lambdaFolder = path.resolve(__dirname, "lambdas");
const graphqlFolder = path.resolve(__dirname, "graphql");

createYogaServer({
  port: 4000,
  graphqlDir: graphqlFolder,
  lambdaDir: lambdaFolder,
});

Option props

interface ICreateServerProps {
  port?: number; // default 4000
  path?: string; // default /graphql
  graphqlDir: string; // graphql schema file folder, required if you don't use typeDefs
  lambdaDir: string; // lambda resolver file folder, required if you don't use resolvers
  resolvers?: any; // custom resolvers
  typeDefs?: any; // custom typeDefs
}

Run with watch mode

tsc-watch --onSuccess \"ts-node --project ./dist/tsconfig.json -r tsconfig-paths/register ./dist/server.js\"

Path alias

If you want to use path alias, you can use tsconfig-paths to resolve it

npm install tsconfig-paths

then run server with ts-node and tsconfig-paths/register

ts-node --project examples/tsconfig.json -r tsconfig-paths/register examples/server.ts

Directives supported

  • @aws_api_key
  • @aws_cognito_user_pools
  • @aws_subscribe

Environment variables

You can use environment variables in your lambda resolver by .env file

USER_POOL_ID=
USER_POOL_CLIENT_ID=
...

Example

Issues

  • Project can't compatible with more than project structure, you can clone this project and modify it to fit your project structure
  • If you have any issues, please create new issue and describe your problem

Thank for using

About

Appsync Locally by Apollo Server or GraphQL Yoga

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •