This is part of a demo of how to build an 8Base powered application using Nuxt as a frontend. This repo covers the 8Base custom functions that live on the 8Base servers.
Please see the corresponding frontend codebase here.
Basically these are LAMBDA functions that run on AWS.
There are 4 types of Custom Functions. SEE https://docs.8base.com/docs/8base-console/custom-functions/
- Resolvers: For extending your GraphQL API with new "endpoints"
- Webhooks: You can run a custom function via a URL
- Triggers: For functions requiring event-based execution (like before or after a query/mutation)
- Tasks: For invocable and scheduled (cron) functions
sudo npm install -g 8base-cli
.npm install graphql --save
npm install graphql-tag --save
SEE https://docs.8base.com/docs/development-tools/cli/
8base login
8base init server -e
cd server
8base generate resolver likePost -s=js
8base generate -h
for all options. You want TypeScript?
- Install
graphql
andgraphql-tag
into package - Create
/server/src/resolvers/likePost/schema.graphql
- Use
8base invoke-local likePost -m request
to see how function runs.- Note that
console.log()
works event.data
parameter contains all the GQL variables.
- Note that
8base deploy
- Notice how API Explorer in 8Base dashboard has changed now.
The way 8Base knows what functions match what hooks/events, is the 8base.yml
file.
- Mock run a function
8base invoke-local likePost -m request
request
is the mock data filename, so/mocks/request.json
.
8base invoke likePost -m request
to run it with production code.
SEE https://app.8base.com/logic/likePost/configuration
8Base logs for a custom function ran through the API. Good for debugging.
SEE https://app.8base.com/settings/environment-variables
And then in code: process.env.{varKey}
8base export -h
8base import -h
I included some examples of resolvers to wrap some Auth0 functions for you.