Comments (2)
Well, I'd be happy to hear any additional advice (especially how I may improve this), but I did make some progress. Using my generated models, I was able to dig a bit into the code and figure out how to send random queries and map that to my models. Here's the result, maybe it will help someone!
Query Function:
Future<Customer?> getCustomer() async {
try {
const document = '''
query GetCustomer(\$customerId: ID!) {
getCustomer(customerId: \$customerId) {
id
email
status
}
}
''';
const variables = {"customerId": "abcdefg"};
final call = await Amplify.API
.query(
request: GraphQLRequest<dynamic>(
document: document,
variables: variables,
))
.response;
final responseRaw = call.data;
print(responseRaw);
final customerDynamic = jsonDecode(responseRaw)['getCustomer'];
print(customerDynamic);
final customer = Customer.fromJson(customerDynamic);
return customer;
} on ApiException catch (e) {
safePrint('Query failed: $e');
return null;
}
}
Result (in console):
{"getCustomer":{"id":"abcdefg,"email":"[email protected]","status":"ACTIVE"}}
{id: abcdefg, email: [email protected], status: ACTIVE}
Customer {id=abcdefg, [email protected], status=ACTIVE, createdAt=null, updatedAt=null, queryResultsCustomerResultsId=null}
Next up.. figure out how to do subscriptions π
from amplify-flutter.
Subscriptions!
StreamSubscription<GraphQLResponse<String>>? subscription;
void subscribe() {
const document = '''
subscription SubscribeToRealtimeEvent(\$channel: String!) {
subscribeToRealtimeEvent(channel: \$channel) {
channel
data
date
}
}
''';
const variables = {"channel": "123456"};
final subscriptionRequest = GraphQLRequest<String>(document: document, variables: variables);
final Stream<GraphQLResponse<String>> operation = Amplify.API.subscribe(
subscriptionRequest,
onEstablished: () => safePrint('Subscription established'),
);
subscription = operation.listen(
(event) {
safePrint('Subscription event data received: ${event.data}');
},
onError: (Object e) => safePrint('Error in subscription stream: $e'),
);
}
Output:
Subscription event data received:
{"subscribeToRealtimeEvent":{"channel":"123456","data":"{\"action\":\"ACT_ON_RESPONSE_RECEIVED\",\"params\":{\"itemId\":\"000000001\"}}","date":"2024-03-21T18:45:30.343Z"}}
I tried mapping these to the RealtimeEvent
model, but I got this error message so I just moved it to String
, easy enough to handle:
Error: ApiOperationException {
"message": "Decoding of the response type provided is currently unsupported",
"recoverySuggestion": "Please provide a Model Type or type 'String'"
}
from amplify-flutter.
Related Issues (20)
- PushNotificationException "Error occurred awaiting for device token." HOT 5
- Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast HOT 7
- Error: AuthorizationException (OAuth authorization error (invalid_client)) on signInWithWebUI
- Pinpoint push notification campaign events are not being recorded. HOT 3
- Unable to start subscription after internet interruption HOT 4
- Changing model prevents syncing HOT 7
- Blank notification after upgrading the flutter to v3.22.2 HOT 14
- Memory leak when configuring amplify HOT 10
- Datastore update auth groups Unauthorized error HOT 13
- InstructionsResolver is not a Class HOT 4
- Compile issues after upgrading to 2.2.0 HOT 10
- Conflict handler not called for conflicts created while offline HOT 6
- Receive "ERROR | WebSocketBloc | Shutting down with exception: NetworkException" after upgrading from Amplify Flutter 1.6 to 2.3 HOT 33
- Notifications from Pinpoint campaigns with the "local time" option are not sent. HOT 4
- With msix pakcage install to windows 10, 11, When sign in cognito, Got an error "request failed due to a network error" HOT 10
- Amplify Codegen for Flutter generating invalid `ModelProvider.dart` HOT 5
- Replace tuple with record types HOT 3
- Amplify Fails to Configure - WorkerBeeExceptionImpl HOT 11
- Π‘rash after completing a workmanager task HOT 2
- Support latest version of json_annotation HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amplify-flutter.