I recently needed to stand up a demo app that invoked an AWS AppSync GraphQL API. The existing endpoint (not available publicly) returned restaurant data for a given zip with the following schema.
The app I wanted to build was throwaway, and my goal was to make it happen effortlessly, during a single lunch break. I was told to try Redwood.js, AWS Amplify, Sanity.io, Next.js via prisma-examples, and some zero-code tools, including ReTool.
Redwood.js
Let’s start with Redwood.js …
Create an App
Add a Homepage
Add an Input Box for the Zip Code
When the form is submitted, state (including zip code) will change.
Add graphql-request
Add the GraphQL Query
Wire Up GraphQL Results
Not Taking Advantage of Redwood.js
So far I used Redwood.js similarly to how one would use Rails without models, views or controllers, just to host some Ruby code on a web page. Redwood has lots of features, including cells and side-loading. Seems like a missed opportunity! So I asked the Redwood.js community to help me leverage Redwood.js better. The answer is more generally described in the documentation under Server-Side API Integration.
Expose Restaurants Side-Loading
Add api/src/graphql/restaurants.sdl.js with the schema that our Redwood.js service will return.
Fetch Data from the AppSync API
Wire up calls to the AppSync endpoint in api/src/lib/db.js.
Add api/src/services/restaurants.js that loads restaurant data using the above endpoint.
Add a Restaurants Cell
The cell makes a query to the Redwood.js service to fetch restaurants.
Wire up the cell in the homepage.
Put it All Together
Create a .env file with APPSYNC_API_ENDPOINT_URL and APPSYNC_API_KEY and run the app with yarn redwood dev.