0
Here’s the relevant schema definitions:
type Course implements GrApp {
id: ID!
term_id: ID!
term_name: String
type: String!
name: String!
data: AWSJSON
course_info: AWSJSON
}
interface GrApp {
id: ID!
type: String!
name: String!
data: AWSJSON
}
input TableGrAppFilterInput {
id: TableIDFilterInput
type: TableStringFilterInput
name: TableStringFilterInput
}
input TableIDFilterInput {
ne: ID
eq: ID
le: ID
lt: ID
ge: ID
gt: ID
contains: ID
notContains: ID
between: [ID]
beginsWith: ID
}
input TableIntFilterInput {
ne: Int
eq: Int
le: Int
lt: Int
ge: Int
gt: Int
contains: Int
notContains: Int
between: [Int]
}
input TableStringFilterInput {
ne: String
eq: String
le: String
lt: String
ge: String
gt: String
contains: String
notContains: String
between: [String]
beginsWith: String
}
type Term implements GrApp {
id: ID!
type: String!
name: String!
data: AWSJSON
courses: [Course]
}
type Query {
allTerm(filter: TableGrAppFilterInput, limit: Int, nextToken: String): TermConnection
}
An explanation of my schema: I have an interface/base of GrApp, and then Course and Term implementing it. This is because I have one DynamoDB database representing all my data (it’s just easier this way) and I have both a primary key (id) and a sort key (type) that differentiates between these two types.
However, I’m having trouble with the allTerm
query. This is my resolver:
import { util } from '@aws-appsync/utils';
export function request(ctx) {
const type="term";
const { limit = 20, nextToken } = ctx.arguments;
const index = 'type-index';
const query = JSON.parse(
util.transform.toDynamoDBConditionExpression({ type: { eq: type } })
);
return { operation: 'Query', index, query, limit, nextToken };
}
export function response(ctx) {
const { items: posts = [], nextToken } = ctx.result;
return { posts, nextToken };
}
With this query:
query listGrApps {
allTerm {
items {
id
name
}
}
}
Gives me this:
{
"data": {
"allTerm": {
"items": null
}
}
}
I got the above resolver code from https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-resolvers-js.html#configure-query (the allPostsByAuthor resolver part)
I’m not too sure why this is not working.