graphql-editor/stucco-js

Repository files navigation

image

Build

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.

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

{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}
{
    "scalars":{
        "CUSTOM_SCALAR_NAME":{
            "parse":{
                "name": "PATH_TO_RESOLVER"
            },
            "serialize":{
                "name": "PATH_TO_RESOLVER"
            }
        }
    }
}

You can also return Promise from handler

module.exports = (input) => {
    return  "Hello world"
}
module.exports.handler = (input) => {
    return "Hello world"
}
module.exports.someName = (input) => {
    return "Hello world"
}
{
    "resolvers":{
        "RESOLVER_TYPE.RESOLVER_FIELD":{
            "resolve":{
                "name": "PATH_TO_RESOLVER.someName"
            }
        }
    }
}
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]
    }
}

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

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.

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

About

GraphQL server. JavaScript runtime for stucco - GraphQL backend

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •