gj-service-appsync

1.0.60 • Public • Published

gj-service-appsync

Installation

In order to add this package to your service, run the following command:

npm i gj-service-appsync

Usage

// deploy.js
const appsync = require('gj-service-appsync')
appsync.deploy(__dirname)
// config.js
module.exports = {
    name: 'MY NEW API',
    region: 'us-east-2'
}
// src/schema.graphql
type Hello {
    hello: String
    id: String
    name: String
}

type Product {
    id: String
    name: String
}

type Extra {
    id: String
    product: String
}

type Coffee {
    id: String
    name: String
}

type Query {
    getHello: Hello
    something: Product
    product: Extra
    getProduct(id: String): Coffee
}

input CreateProductInput {
    id: String
    name: String
}

input RemoveProductInput {
    id: String
}

type Mutation {
    createProduct(input: CreateProductInput): Coffee
    removeProduct(input: RemoveProductInput): Coffee
}
// src/index.js
const resolvers = require('./resolvers')

module.exports.handler = async (event) => {
    try {
        const x = await resolvers
        [event.info.parentTypeName]
        [event.info.fieldName]
            (event)

        return x
    } catch (e) {
        throw new Error(e)
    }
}
// src/resolvers.js
module.exports = {
    Query: {
        getHello: async () => {
            return {
                hello: 'hello',
                id: '1234',
                name: 'NAMEE448'
            }
        },

        something: async () => {
            return {
                id: '1234',
                name: 'Dark Coffee 1'
            }
        },

        product: async () => {
            return {
                id: '1234',
                product: 'Light Coffee'
            }
        },

        getProduct: {
            type: 'db',
            action: 'GET',
            table: 'int-test-appsyncdb'
        }
    },

    Mutation: {
        createProduct: {
            type: 'db',
            action: 'CREATE',
            table: 'int-test-appsyncdb'
        },

        removeProduct: {
            type: 'db',
            action: 'REMOVE',
            table: 'int-test-appsyncdb'
        },
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i gj-service-appsync

Weekly Downloads

40

Version

1.0.60

License

ISC

Unpacked Size

53.3 kB

Total Files

26

Last publish

Collaborators

  • garysjennings