Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

GraphQL server. JavaScript runtime for stucco - GraphQL backend

License

NotificationsYou must be signed in to change notification settings

graphql-editor/stucco-js

Repository files navigation

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 onStucco 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"

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]}}

Example

Basic

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

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 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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp