You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with Flutter and using the following libraries:
graphql
graphql_flutter
graphql_codegen
flutter-freezed
I've successfully set up schema generation using flutter-freezed following this guide. When I run build_runner, it generates queries and mutations that can be used as hooks.
However, I'm facing an issue where the queries and mutations are not synchronized with the models generated by the schema.
Here’s an example of my setup:
GraphQL Query:
queryFetchChallenges($filters: [[FilterInput!]!]) {
challenges(filters: $filters) {
data {
...ChallengeFragmentuserChallenges {
idenrolledAtcompletedAtchallenge {
id
}
}
}
}
}
Generated Hook
final fetchChallengesQuery =useQuery$FetchChallenges(
Options$Query$FetchChallenges(
fetchPolicy:FetchPolicy.networkOnly,
),
);
final challenges = fetchChallengesQuery.result.parsedData?.challenges?.data;
and the Model is
classQuery$FetchChallenges$challenges$dataimplementsFragment$ChallengeFragment {
// Fields and methods...
}
I want to convert the list of Query$FetchChallenges$challenges$data into a list of Challenge instances. I tried doing this with the following code:
final response = fetchChallengesQuery.result.parsedData?.challenges?.data;
final challenges = response?.map((queryChallenge) =>Challenge.fromJson(queryChallenge.toJson())).toList();
However, I’m encountering issues with enum compatibility and other type mismatches.
How can I synchronize the Query$FetchChallenges$challenges$data with the freezed Challenge model? Specifically, how can I properly convert or map the generated query types to the Freezed models, given that there are issues with enum values and other type mismatches?
OR is there anything I can do in my build runner that can properly map the queries to the freezed models?
Any help or suggestions would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working with Flutter and using the following libraries:
graphql
graphql_flutter
graphql_codegen
flutter-freezed
I've successfully set up schema generation using
flutter-freezed
following this guide. When I runbuild_runner
, it generates queries and mutations that can be used as hooks.However, I'm facing an issue where the queries and mutations are not synchronized with the models generated by the schema.
Here’s an example of my setup:
GraphQL Query:
Generated Hook
and the Model is
Generated freezed model
Problem
I want to convert the list of Query$FetchChallenges$challenges$data into a list of Challenge instances. I tried doing this with the following code:
However, I’m encountering issues with enum compatibility and other type mismatches.
How can I synchronize the
Query$FetchChallenges$challenges$data
with the freezedChallenge
model? Specifically, how can I properly convert or map the generated query types to the Freezed models, given that there are issues with enum values and other type mismatches?OR is there anything I can do in my build runner that can properly map the queries to the freezed models?
Any help or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions