- Notifications
You must be signed in to change notification settings - Fork3
GraphQL server. JavaScript runtime for stucco - GraphQL backend
License
graphql-editor/stucco-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 onStucco 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" } } }}
typeTodoOperations{getCreditCardNumber(id:String!):StringshowMeTehMoney:Int}typeQuery{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.argumentsreturn{response:input.source.creditCards[id]}}
schema.graphql
typeQuery{hello:String}schema{query:Query}
stucco.json
{"resolvers":{"Query.hello":{"resolve":{"name":"lib/hello" } } }}
lib/hello.js
exportfunctionhandler(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 needstucco.json
,schema.graphql
, file with resolvers in the root folder and inside root folder. To fetch your schema from URL you can use tool likegraphql-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