How can I use a custom type in graphql query in graphql_flutter?

Viewed 186

I am using graphql_flutter in a flutter app. Below is my query code:

await this.gqClient.query(QueryOptions(documentNode: gql('''
query posts(\$size: Int, \$lastEvaluatedKey: LastEvaluatedKey){
          posts(size: \$size, lastEvaluatedKey: \$lastEvaluatedKey) {
            posts {
              id
            }
            lastEvaluatedKey {
              id
              timestamp
            }
          }
        }
      '''),
       variables: {'size': this.pageSize, 'lastEvaluatedKey': this._lastEvaluatedKey}))

I got this error when executing above code:

OperationException (GraphQL Errors:
        Validation error of type UnknownType: Unknown type LastEvaluatedKey: Undefined location)

It seems that LastEvaluatedKey is not recognised. I have declared a dart class LastEvaluatedKey as below but it doesn't seem to help. Where should I put the LastEvaluatedKey definition in the client side?

class LastEvaluatedKey {
  final String id;
  final String timestamp;

  LastEvaluatedKey({this.id, this.timestamp});

  Map<String, dynamic> toJson() {
    try {
      return {
        'id': this.id,
        'timestamp': this.timestamp,
      };
    } catch (err) {
      return null;
    }
  }
}
0 Answers
Related