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
yarnto install all the packages. - Run
sls offlineand 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 eithercheckorcreate.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.graphqlfile describing the query to be executed upon calling the endpoint. - Run
yarn generate. Thesrc/generated/graphql.tsfile should be modified to contain the types for the above query. - Add the relevant type string for the new
eventinsrc/types/index.ts. - Inside
functions/zapier, create a new.tsfile with the name of the event. - Check the formatting of the data received in the request body inside the
.tsfile, and call the functionworkdefined insrc/utils/work.ts. - Modify two files:
- In
src/utils/fetchData.ts, add the case for the newly introduced event in theswitch-caseblock and specify theApollo.DocumentNodeto be called for the new event. Import theApollo.DocumentNodefromsrc/generated/graphql.ts. It should be the same one generated in step 2. - In
src/utils/dataFormat.ts, modify theswitch-caseblock 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>