This repository contains the code for the Questbook API endpoint (https://api.questbook.app) built using the Serverless framework. There are two types of endpoints:
/zapier/v1/:chain/:event
- Designed specifically for the Questbook Zapier App./mappings/:event
- Used to map email IDs to in-app wallet addresses.
- Clone the repository.
- Run
yarn
to install all the packages. - Run
sls offline
and wait for the TypeScript to compile. - The API is ready to be tested.
- Make sure you have the AWS Credentials set
- Run
sls deploy
chain
: Can take up values 5 (Goerli), 42220 (Celo), 137 (Polygon), or 10 (Optimism). It specifies which subgraph to query. Any other value would return an error.event
: Can take the following values:ProposalSubmitted
: Queries the subgraph to list proposals submitted in the last 24 hours.ProposalUpdated
: Queries the subgraph to list proposals updated in the last 24 hours.PayoutStatus
: Queries the subgraph to list fund transfers initiated or updated in the last 24 hours.ReviewerSubmittedReview
: Queries the subgraph to list reviews submitted in the last 24 hours.
event
: Can be eithercheck
orcreate
.check
: Confirms if there exists a mapping from an in-app wallet address to any email address.create
: Inserts a new mapping into the database if a mapping does not exist.
- Under
src/graphql
, create a new.graphql
file describing the query to be executed upon calling the endpoint. - Run
yarn generate
. Thesrc/generated/graphql.ts
file should be modified to contain the types for the above query. - Add the relevant type string for the new
event
insrc/types/index.ts
. - Inside
functions/zapier
, create a new.ts
file with the name of the event. - Check the formatting of the data received in the request body inside the
.ts
file, and call the functionwork
defined insrc/utils/work.ts
. - Modify two files:
- In
src/utils/fetchData.ts
, add the case for the newly introduced event in theswitch-case
block and specify theApollo.DocumentNode
to be called for the new event. Import theApollo.DocumentNode
fromsrc/generated/graphql.ts
. It should be the same one generated in step 2. - In
src/utils/dataFormat.ts
, modify theswitch-case
block in a similar fashion to specify the formatting function to be applied to the data returned by the query specified in the above step.
- In
- You are good to go.
Tip: If you receive a response like {'error': {}}
upon querying an endpoint, check the formatting function. You might be trying to access non-existent items in the query.
TABLE_NAME=<Name of the AWS Dynamo DB Table that stores the mappings>
INFURA_ID=<ID of the Infura App. Needed when decoding the transaction while creating a new mapping>