Pipeline Resolvers

cup ip

In the previous section, you use a Lambda function to access your existing DynamoDB table. In some cases you need to access multiple data sources based on the result of your queries. This is where pipeline resolvers are useful. Pipeline resolvers allow you to query multiple data sources in series.

1. Update your schema

Add the getResults2 query definition to your schema.

amplify/backend/api/graphqlrealtimerace/schema.graphql

type Query {
  getRaces: [Race]
  getResults(driverId: String!): [Result]
  getResults2(driverId: String!): [Result]
}

This query will use a pipeline resolver. The pipeline first calls the Lambda function you just created to retrieve results for a race. As a second step, it filters the results from the Lambda function, to remove any results where the status is not Finished. This will allow the app to only show specific results without having to do any filtering on the front-end

3. Create your AppSync resources

Add the resources below to the Resources in the template:

amplify/backend/api/graphqlrealtimerace/stacks/CustomResources.json

[ 🌟 ] CustomResources.json

Push your changes:

amplify push --yes

4. Update your app

Update src/pages/Account.tsx to fetch and display the race information. We are simply changing the app to use the new getResults2 query.

[ 🌟 ] src/pages/Account.tsx

In your app, you can now select a driver name from the drop down. When you select a driver, your app calls the AppSync getResults query which uses your Direct Lambda resolver. The Lambda function retrieves the data from your existing DynamoDB table.

app overview