0.10.19 • Published 4 months ago

stucco-js v0.10.19

Weekly downloads
63
License
MIT
Repository
-
Last release
4 months ago

image

Javascript runtime for Stucco

Build

About

Stucco-js is JavaScript/TypeScript runtime for Stucco. It can be used as a local development environment or as a base library for implementing FaaS runtime.

Configuration file

Stucco-js relies on Stucco library written in GoLang. Configuration file format is in JSON.

Resolvers

{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}

Custom Scalars

{
    "scalars":{
        "CUSTOM_SCALAR_NAME":{
            "parse":{
                "name": "PATH_TO_RESOLVER"
            },
            "serialize":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}

Handler

You can also return Promise from handler

Default export

module.exports = (input) => {
    return  "Hello world"
}

Handler export

module.exports.handler = (input) => {
    return "Hello world"
}

Named export

module.exports.someName = (input) => {
    return "Hello world"
}
{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER.someName"
            }
        }
    }
}

Passing arguments to another resolver

Resolver "Query.todoOperations"

type TodoOperations{
    getCreditCardNumber(id: String!): String
    showMeTehMoney: Int
}

type Query{
    todoOps: TodoOperations
}
{
    "resolvers":{
        "Query.todoOps":{
            "resolve":{
                "name": "lib/todoOps"
            }
        },
        "TopoOps.getCreditCardNumber":{
            "resolve":{
                "name": "lib/getCreditCardNumber"
            }
        }
    }
}

lib/todoOps.js

module.exports = (input) => {
    return {
        response:{
            creditCards:{
                dupa: "1234-1234-1234-1234",
                ddd: "1222-3332-3323-1233"
            }
        }
    }
}

lib/getCreditCardNumber.js

module.exports = (input) => {
    const { id } = input.arguments
    return {
        response: input.source.creditCards[id]
    }
}

Example

Basic

schema.graphql

type Query{
    hello: String
}
schema{
    query: Query
}

stucco.json

{
    "resolvers":{
        "Query.hello":{
            "resolve":{
                "name": "lib/hello"
            }
        }
    }
}

lib/hello.js

export function handler(input){
    return "Hello world"
}

Test query

{
    hello
}
{
    "hello": "Hello world"
}

This JSON defines resolver

Using TypeScript

So if you have your TypeScript files in src folder you should transpile them to the lib folder and stucco can run it from there.

Local development

To start local development you need stucco.json, schema.graphql, file with resolvers in the root folder and inside root folder. To fetch your schema from URL you can use tool like graphql-zeus

Add this script to your package json to test your backend

{
    "scripts":{
        "start": "stucco"
    }
}

Or run with npx

npx stucco
0.10.19

4 months ago

0.10.18

1 year ago

0.10.16

1 year ago

0.10.17

1 year ago

0.10.10

2 years ago

0.10.11

2 years ago

0.10.12

2 years ago

0.10.9

2 years ago

0.10.7

2 years ago

0.10.8

2 years ago

0.10.3

2 years ago

0.10.4

2 years ago

0.10.5

2 years ago

0.10.6

2 years ago

0.9.17

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.10.0

2 years ago

0.9.16

2 years ago

0.9.15

2 years ago

0.9.11

2 years ago

0.9.8

2 years ago

0.9.9

2 years ago

0.9.10

2 years ago

0.9.7

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.6.7

3 years ago

0.6.6

3 years ago

0.6.5

3 years ago

0.6.3

3 years ago

0.5.4

3 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago