Hi everybody, i am trying to use the graphql endpoint so i am using the ferry client for that in my flutter app so according to the documentation i seted up the httpLink the following way and pass it to my ferry client
Env.endpoint
defaultHeaders: <String, String>{
"X-Appwrite-Project": Env.appwriteProjectId
}
);
but i am getting this error TypeError (type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>?' in type cast)
and this error comes from the package gql_http_link/src/link.dart
where their is a function called Map<String, dynamic>? _defaultHttpResponseDecoder(
http.Response httpResponse) =>
json.decode(
utf8.decode(
httpResponse.bodyBytes,
),
) as Map<String, dynamic>?;
i assume this can be the cause but how do i make it work in my app. I tested the query in Insomia it works but somehow with setting it up in flutter not working.
Have anybody experience on that. I would be very happy for anykind of help.
and what's being returned? what's the output of json.decode()
?
ok i somehow was not able to debug the package code to see whats in json.decode() is so i added a customHttpResponseDecoder in HttpLink like this static final Link _httpLink = HttpLink(
FlavorConfig.instance.variables["apiUrl"],
defaultHeaders: <String, String>{
"X-Appwrite-Project": Env.appwriteProjectId
},
httpResponseDecoder: _customHttpResponseDecoder,
);
and the content of _customHttpResponseDecoder is ``` static Map<String, dynamic>? _customHttpResponseDecoder(http.Response httpResponse) {
try {
final decodedBody = json.decode(utf8.decode(httpResponse.bodyBytes));
if (decodedBody is Map<String, dynamic>?) {
// Handle the case where the response is a Map
return decodedBody;
} else if (decodedBody is List<dynamic>) {
// Handle the case where the response is a List
// You may need to process the list elements individually
if (decodedBody.isEmpty) {
return {};
}
return {'data': decodedBody.first};
}
} catch (error) {
print('Error decoding response: $error');
}
return null; // Return null in case of decoding errors
}``` and the responce looks like this
interesting...were you able to make the same GraphQL some other way? maybe with the Appwrite SDK?
or manually
yes i do in insomia its working
what was the response in insomnia?
i get normal data from my collection
would you please share the request and response using insomnia? And can you see what the request looks like in Flutter?
and have you tried using the Appwrite SDK to make the GraphQL call?
The SDKs support GraphQL?!
i dont know eaither but no i didnt try it
ok i checked the request seems to be included everything same as insomia
after a little investigation i found out that when i set the request type to get in insomia i get this error and the same error i get in my flutter app when i use post but not getting this error in insomia when i set the request to post in insomia and i dont get the other null type error anymore after setting the content type to defaultHeaders: <String, String>{
"X-Appwrite-Project": Env.appwriteProjectId,
"Content-Type":"application/x-www-form-urlencoded"
},
this.
so i dont know what is happening.
yah exactly i alread looked into it and didnt found anything more then in the screenshots their is also the same stuff.
Can you share?
yes of course here the request part
but is the query part looking normal?
i mean i cannot see the query string fully.
Shouldn't there be more to the query?
It might be getting cut off?
yes i think so as well. If i send the query like this i would definately get an error.
Recommended threads
- Seed db
hello there... is this correct way to seed appwrite
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...