-
-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I pass a customised parameter in query? #642
Comments
Hi, the solution is to create a toJson method in your LastEvaluatedKey class and return the fields of LastEvaluatedKey in the form of Map<String, dynamic> |
I have updated my class as below. But it is still not working. I still get the error
The query code is inside When I debug above code, I can see the method |
You currently have to call If you're going to have a lot of input types that require serialization, you can us variables: json.encode(
variables,
toEncodable: (dynamic object) => object.toJson(),
) |
Thanks for your feedback. But adding
I updated the code above but still get the same error:
|
@zhaoyi0113 ohhh wait I think this error is that the graphql server doesn't recognize the type |
I can send query from different client so I don't think it is an issue on the server side. However, I can make it work by extracting the query parameters from LastEvlauatedKey instance like below code:
as you can see, it takes primitive types of parameters and set them in |
@zhaoyi0113 hmm, I'm fairly sure there must have been some difference. The error is a GraphQL validation error: query posts(\$size: Int, \$lastEvaluatedKey: LastEvaluatedKey){ If you want to investigate it further, come to the
|
Where should I define input LastEvaluatedKey {
id: String
timestamp: Int
}
|
@zhaoyi0113 in graphql, inputs are defined in the schema. So, I would look at your schema and see what the method signature of |
I would say the schema is on the server side. So I don't need to define that in client side. type Mutation {
sendPost(post: PostInput): Post
savePostPhotos(id: ID!, paths: [String]): ID
}
type PaginationKey {
id: String!
timestamp: Long
}
input PaginationKeyInput {
id: String!
timestamp: Long
}
type Post {
userId: String!
message: String
id: ID!
timestamp: Long!
userInfo: UserInfo
photoPaths: [String]
pstatus: Int
}
input PostInput {
userId: String!
message: String
}
type PostReqResponse {
posts: [Post]
lastEvaluatedKey: PaginationKey
}
type Query {
presignedURL(id: ID!, count: Int!): [String]
posts(size: Int, lastEvaluatedKey: PaginationKeyInput): PostReqResponse
post(id: ID!): Post
}
type UserInfo {
id: ID
username: String
firstName: String
lastName: String
name: String
email: String
picture: String
}
schema {
query: Query
mutation: Mutation
} |
@zhaoyi0113 so, instead of await this.gqClient.query(QueryOptions(documentNode: gql('''
query posts(\$size: Int, \$lastEvaluatedKey: PaginationKeyInput){
posts(size: \$size, lastEvaluatedKey: \$lastEvaluatedKey) {
posts {
id,
message,
photoPaths,
userInfo {
username,
picture
}
}
lastEvaluatedKey {
id
timestamp
}
}
}
'''), variables: {
'size': this.pageSize,
'lastEvaluatedKey': this._lastEvaluatedKey.toJson(),
})); |
awesome, it fixes the issue. Thanks for checking my bug. |
I am using
graphql_flutter
in a flutter app. Below is my query code:I got this error when executing above code:
It seems that
LastEvaluatedKey
is not recognised. I have declared a dart classLastEvaluatedKey
as below but it doesn't seem to help. Where should I put theLastEvaluatedKey
definition in the client side?The text was updated successfully, but these errors were encountered: