Skip to content
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

GraphQL response error on fetching user by id #4109

Closed
mtalhastar opened this issue Nov 11, 2023 · 18 comments
Closed

GraphQL response error on fetching user by id #4109

mtalhastar opened this issue Nov 11, 2023 · 18 comments
Assignees
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced GraphQL API Issues related to the API (GraphQL) Category

Comments

@mtalhastar
Copy link

When i call this function from flutter app passing correct user id stored in my dynamo db as parameter , it shows me following error.

CLI v 12.7.1

Error:
error

here is the code snippet:
snippets

@Jordan-Nelson Jordan-Nelson added GraphQL API Issues related to the API (GraphQL) Category pending-triage This issue is in the backlog of issues to triage labels Nov 11, 2023
@Tructivity
Copy link

@haverchuck @ykethan Can you guys help, please? We are stuck in this error!

@Equartey
Copy link
Contributor

Hi @mtalhastar,

Sorry you ran into this error. If your use case is to simply fetch a single model by ID we offer a discrete API for this. Here is an example of how to construct that request given an ID as a string.

  Future<userType?> queryItem(String id) async {
    try {
      final id = userTypeModelIdentifier(id: '123');
      final request = ModelQueries.get(
        userType.classType,
        id,
      );
      final response = await Amplify.API.query(request: request).response;

      if (response.data == null) {
        safePrint(response.errors);
      }

      return response.data;
    } on ApiException catch (e) {
      safePrint(e);
    }
  }

The example you provided using a query predicate is typically used when fetching one or more models based on a non-id field. However, I would expect your example to work as written. If your use case requires query predicates, in order to troubleshoot the issue further, can you please provide your schema.graphql file?

@Equartey Equartey added pending-response Issue is pending response from the issue requestor and removed pending-triage This issue is in the backlog of issues to triage labels Nov 13, 2023
@mtalhastar
Copy link
Author

On this i receive error below:
image

GraphQL file:
grahql.txt

@Equartey
Copy link
Contributor

Hi @mtalhastar,

Models should follow title casing such as UserType.

This subtile difference is making the underlying generated functions unable to find required properties and methods.

You will need to update your model names and redeploy your backend for the Model helper functions to work.

It's unclear to me at the moment if this is a bug or by design. I'm going to leaving this issue open so we can track the investigation internally.

@Equartey Equartey removed the pending-response Issue is pending response from the issue requestor label Nov 14, 2023
@mtalhastar
Copy link
Author

mtalhastar commented Nov 14, 2023

Cant just changing model titles in schema.graphql file work? instead of changing names in GraphQl models in amplify backend?

@Tructivity
Copy link

@dnys1 I've seen you that you are a contributor to AWS Amplify in Flutter and I'm facing a problem for days here so can you please help?

@Equartey
Copy link
Contributor

Hi @mtalhastar,

Cant just changing model titles in schema.graphql file work? instead of changing names in GraphQl models in amplify backend?

Apologies, I could have been more clear. You will update the model names in your schema.graphql, this file determines the graphql backend. After updating this file please rebuild your models with amplify codegen models and then push the changes to your amplify backend with amplify push.

@Tructivity
Copy link

Tructivity commented Nov 15, 2023

@Equartey Why I can't directly connect my Flutter app to the already developed Amplify backend without any changes to it?

If I made these changes, then the web application won't work again so I need more extra work from the web developer to fix them.

@Tructivity
Copy link

@Equartey Can u provide an answer for my question please? I need it

@Equartey
Copy link
Contributor

Hi @Tructivity,

I've confirmed this is a bug and have opened a PR to address it. However, this likely won't get released until next week.

In the meantime, the only workaround I can provide is renaming your models. Although, I realize this conflicts with wanting to preserve your backend. I will notify you here once the fix is publicly available.

@Tructivity
Copy link

@Equartey thanks for replying, so in the next week, I will be able to connect my Flutter app with the existing backend (DynamoDB) using GraphQL without any changes to it?

@Equartey
Copy link
Contributor

@Tructivity assuming there are no other issues with your setup, once this fix is released it should work.

@Tructivity
Copy link

@Equartey Thanks a lot for helping me! We will leave this issue open until the release of the update and we then confirm that it is working properly.

@Equartey Equartey self-assigned this Nov 16, 2023
@Equartey Equartey added the pending-release Issues that have been addressed in main but have not been released label Nov 16, 2023
@Equartey
Copy link
Contributor

Hey @Tructivity

We're still working on releasing a fix.

However, in the meantime please consume the branch directly by adding this override to your pubspec.yaml

dependency_overrides:
  amplify_api_dart:
    git:
      url: https://github.com/aws-amplify/amplify-flutter.git
      ref: 0b3672b09849290394b7a775beaccf1ec6379dbf
      path: packages/api/amplify_api_dart

Please let me know if you have issues setting this up.

I will continue to provide updates as I have them. Thanks!

@Tructivity
Copy link

@Equartey Thanks a lot but I can wait for a while before you release the update since we are busy with another issue! Can u please tell me when u will release the update?

@Equartey
Copy link
Contributor

@Tructivity I will notify you when it's been released. I currently do not have an ETA.

@Tructivity
Copy link

@Equartey 13 days I've been waiting to be fixed, hope will be fixed very soon 😞

@Equartey
Copy link
Contributor

Equartey commented Dec 6, 2023

@Tructivity Sorry for the delay, the fix has been released in amplify_api 1.6.2

I'm going to close this issue as resolved now. Please update your dependency and reach out if you have any additional issues.

@Equartey Equartey closed this as completed Dec 6, 2023
@Equartey Equartey added bug Something is not working; the issue has reproducible steps and has been reproduced and removed pending-release Issues that have been addressed in main but have not been released labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced GraphQL API Issues related to the API (GraphQL) Category
Projects
None yet
Development

No branches or pull requests

4 participants