Amplify-cli: How to Implement a Pipeline Resolver

Created on 22 Jan 2020  路  4Comments  路  Source: aws-amplify/amplify-cli

Which Category is your question related to?
Graphql Transform

Amplify CLI Version
4.11.0

What AWS Services are you utilizing?
AppSync, Dynamodb

Provide additional details e.g. code snippets
I have a query in my app that requires I believe requires a custom pipeline resolver and I am not sure how to implement it. My schema looks like:

type Student @model {
  id: ID
  name: String
  classes: [StudentClass] @connection(keyName: "byStudent", fields: ["id"])
  exams: [StudentExam] @connection(keyName: "byStudent", fields: ["id"])
}

type StudentExam
  @model
  @key(name: "byExam", fields: ["examID"])
  @key(name: "byStudent", fields: ["studentID"]) {
  id: ID!
  studentID: ID
  student: [Student] @connection(fields: ["studentID"])
  examID: ID
  exam: [Exam] @connection(fields: ["examID"])
}

type Exam @model @key(name: "byClass", fields: ["byClass"]) {
  id: ID
  classID: ID
  class: [Class] @connection(fields: ["classID"])
  students: [StudentExam] @connection(keyName: "byExam", fields: ["id"])
  avgScore: Float
}

type StudentClass
  @model
  @key(name: "byStudent", fields: ["studentID"])
  @key(name: "byClass", fields: ["classID"]) {
  studentID: ID
  classID: ID
  student: [Student] @connection(fields: ["studentID"])
  class: [Class] @connection(fields: ["classID"])
}

type Class @model {
  id: ID
  name: String
  students: [StudentClass] @connection(keyName: "byClass", fields: ["id"])
  exams: [Exam] @connection(keyName: "byClass", fields: ["id"])
}

Given a student, I need to be able to query for the list of Exams in the Student's Classes, that the Student is not signed up for. A StudentExam record denotes that a Student is signed up for an Exam in a Class. My solution to this would be to

  1. Find the Student's Classes _C_
  2. Find the Exams _E_ for the Students Classes
  3. Filter _E_ such that the given Student is not in _e_.users, for all _e_ where _e_ is in _E_

The docs would seem to recommend writing a custom resolver that targets a dynamodb table generated @model. But the steps outlined above will need to target multiple tables, and so would require a pipeline of resolvers. How can I do that?

graphql-transformer question

Most helpful comment

Hello @karrettgelley currently the CLI does not support pipeline resolvers, though this is something we are working on an update for.
Follow this RFC for those updates: https://github.com/aws-amplify/amplify-cli/issues/1055
A few possible implementations are discussed on that thread.

If I understand your question correctly

  1. Based on a Student S you want to query all the classes S is in.
  2. Out of those classes C you want to query for exams E that S is not in?

All 4 comments

I asked the same question a few days ago here:
https://github.com/aws-amplify/amplify-cli/issues/3192

It would be nice to have that in the documentation.

Hello @karrettgelley currently the CLI does not support pipeline resolvers, though this is something we are working on an update for.
Follow this RFC for those updates: https://github.com/aws-amplify/amplify-cli/issues/1055
A few possible implementations are discussed on that thread.

If I understand your question correctly

  1. Based on a Student S you want to query all the classes S is in.
  2. Out of those classes C you want to query for exams E that S is not in?

Closing this issue - If you have any specific questions related to implementing a custom pipeline resolver solution in your project I recommend looking at the thread linked above.

@SwaySway Sorry for the late response. But your assumption is correct. For now, I will try to workaround the problem by rearchitecting the schema. In the future it will be nice to have pipeline resolvers, but I have come up with another solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ffxsam picture ffxsam  路  3Comments

kstro21 picture kstro21  路  3Comments

jeanpaulcozzatti picture jeanpaulcozzatti  路  3Comments

mwarger picture mwarger  路  3Comments

amlcodes picture amlcodes  路  3Comments