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

Update Error Handling for createMember, createAdmin, createComment #2448

Open
palisadoes opened this issue Mar 29, 2024 · 21 comments
Open

Update Error Handling for createMember, createAdmin, createComment #2448

palisadoes opened this issue Mar 29, 2024 · 21 comments
Labels
bug Something isn't working no-issue-activity No issue activity

Comments

@palisadoes
Copy link
Contributor

Describe the bug

  1. This PR was recently merged to complete the implementation of our error handling methodology.
    1. Graphql error handling develop talawa-api#1746
    2. These mutations were affected createMember, createAdmin, createComment
    3. There may be others
  2. This may have an impact on the operation of the mobile app. Though these mutations are admin related and may not be relevant to the mobile app. We need verification of operations.

Expected behavior

  • The app maintains its existing functionality without errors

Actual behavior

  • Uncertain at this time.

Screenshots

  • N/A

Additional details

  • N/A

Potential internship candidates

@palisadoes palisadoes added the bug Something isn't working label Mar 29, 2024
@github-actions github-actions bot added the unapproved Unapproved, needs to be triaged label Mar 29, 2024
Copy link

github-actions bot commented Apr 9, 2024

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Apr 9, 2024
@TirthNisar193
Copy link

Do we see any issues after the changes/ are we known to bugs caused after implementation of talawa-api#1746. If so i am interested for working on this project and can start with this issue.

@github-actions github-actions bot removed the no-issue-activity No issue activity label Apr 19, 2024
@palisadoes palisadoes removed the unapproved Unapproved, needs to be triaged label Apr 22, 2024
Copy link

github-actions bot commented May 3, 2024

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label May 3, 2024
@dhanagopu
Copy link

@TirthNisar193 Are you working on this?

@github-actions github-actions bot removed the no-issue-activity No issue activity label May 5, 2024
Copy link

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label May 16, 2024
@Cioppolo14 Cioppolo14 removed the no-issue-activity No issue activity label May 16, 2024
@Cioppolo14
Copy link
Contributor

Unassigning due to no activity or open PR.

Copy link

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label May 27, 2024
@rohansen856
Copy link

I would like to work on this issue. Please assign me.

@github-actions github-actions bot removed the no-issue-activity No issue activity label Oct 17, 2024
Copy link

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Oct 27, 2024
@palisadoes
Copy link
Contributor Author

@rohansen856 This has been assigned to you

@github-actions github-actions bot removed the no-issue-activity No issue activity label Oct 28, 2024
@rohansen856
Copy link

@palisadoes I have confirmed the code changes of the following mutation: createAdmin.ts, createComment.ts and createMember.ts, have no apparent effect on the workings of the main mobile app.
for all these files, the primary change in error handling was returning defined error values instead of throwing them on server side. ex.:

  if (!currentUser) {
    return {
      organization: new Organization(),
      userErrors: [
        {
          __typename: "UserNotFoundError",
          message: requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE),
        },
      ],
    };
}

instead of:

  if (!currentUser) {
    throw new errors.NotFoundError(
      requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE),
      USER_NOT_FOUND_ERROR.CODE,
      USER_NOT_FOUND_ERROR.PARAM
    );
}

These errors do not affect the workings of this app as the createComment (in /lib/services/comment_service.dart), directly run graphql queries, not through these api routes. ex.:

  Future<void> createComments(String postId, String text) async {
    final String createCommentQuery = CommentQueries().createComment();

    try {
      await _dbFunctions.gqlAuthMutation(
        createCommentQuery,
        variables: {
          'postId': postId, //Add your variables here
          'text': text,
        },
      );

      _navigationService.showTalawaErrorSnackBar(
        "Comment sent",
        MessageType.info,
      );
    } on Exception catch (_) {
      _navigationService.showTalawaErrorSnackBar(
        "Something went wrong",
        MessageType.error,
      );
    }
  }

for the createMember part in organisations, same type of functionality happens. The queries defined in: lib/utils/queries.dart has all the direct graphql relations.

According to my review, The changes in the talawa-api should not affect these functionalities. Please correct me if i am wrong in any of my views. Thank you. And also very sorry for the late.

@palisadoes
Copy link
Contributor Author

@noman2002 What do you think?

@noman2002
Copy link
Member

@rohansen856 Aren't the graphql query going through backend ? I don't think its writing into the database directly. Please investigate into this. If its not going through backend route then we need to fix it.

@rohansen856
Copy link

Thanks for the reply @noman2002
I will look into it asap and inform you if either there is any fault in my judgement or there is any need for a fix. Thank you.

@rohansen856
Copy link

@noman2002 from what i understand for the createComments function for now, the involved functionalities are:
lib/utils/comment_queries.dart:

  /// * String: The query for creating a comment
  String createComment() {
    return """
     mutation createComment(\$postId: ID!, \$text: String!) { 
      createComment(postId: \$postId, 
        data:{
          text: \$text,
        }
      ){
        _id
      }
    }
  """;
  }

this function that generates a GraphQL mutation string for creating a comment on a post,
which is used here:
lib/services/comment_service.dart

  Future<void> createComments(String postId, String text) async {
    final String createCommentQuery = CommentQueries().createComment();

    try {
      await _dbFunctions.gqlAuthMutation(
        createCommentQuery,
        variables: {
          'postId': postId, //Add your variables here
          'text': text,
        },
      );

      _navigationService.showTalawaErrorSnackBar(
        "Comment sent",
        MessageType.info,
      );
    } on Exception catch (_) {
      _navigationService.showTalawaErrorSnackBar(
        "Something went wrong",
        MessageType.error,
      );
    }
  }

here, the gqlAuthMutation function comes from:
lib/services/database_mutation_functions.dart

  Future<QueryResult<Object?>> gqlAuthMutation(
    String mutation, {
    Map<String, dynamic>? variables,
  }) async {
    final MutationOptions options = MutationOptions(
      document: gql(mutation),
      variables: variables ?? <String, dynamic>{},
    );
    final response = await cacheService.executeOrCacheOperation(
      operation: mutation,
      variables: variables,
      operationType: CachedOperationType.gqlAuthMutation,
      whenOnline: () async {
        final QueryResult result = await clientAuth.mutate(options);
        print(result);
        // If there is an error or exception in [result]
        if (result.hasException) {
          GraphqlExceptionResolver.encounteredExceptionOrError(
            result.exception!,
          );
        } else if (result.data != null && result.isConcrete) {
          return result;
        }
        return noData;
      },
    );
    return response;
  }

finally,
Yes, the gqlAuthMutation function directly queries the GraphQL service when the app is online or caches the request for offline scenario. So, there should be no clash with the changes made for error handling of the createComments function
Thank you.

@palisadoes
Copy link
Contributor Author

During the week of November 11, 2024 we will start a code freeze on the develop branches in Talawa, Talawa Admin and Talawa-API.

We have completed a project to convert the Talawa-API backend to use PostgreSQL. Work will then begin with us merging code in the develop branches to a new develop-postrgres branch in each repository.

Planning activities for this will be managed in our #talawa-projects slack channel. A GitHub project will be created to track specially labeled issues. We completed a similar exercise last year using a similar methodology.

Starting November 12, California time no new PRs will be accepted against the develop branch. They must be applied to the develop-postrgres branch.

There are some GSoC project features that will need to be merged into develop. These will be the only exceptions.

This activity and the post GSoC 2024 start date was announced in our #general Slack channel last month as a pinned post.

@noman2002
Copy link
Member

@noman2002 from what i understand for the createComments function for now, the involved functionalities are: lib/utils/comment_queries.dart:

  /// * String: The query for creating a comment
  String createComment() {
    return """
     mutation createComment(\$postId: ID!, \$text: String!) { 
      createComment(postId: \$postId, 
        data:{
          text: \$text,
        }
      ){
        _id
      }
    }
  """;
  }

this function that generates a GraphQL mutation string for creating a comment on a post, which is used here: lib/services/comment_service.dart

  Future<void> createComments(String postId, String text) async {
    final String createCommentQuery = CommentQueries().createComment();

    try {
      await _dbFunctions.gqlAuthMutation(
        createCommentQuery,
        variables: {
          'postId': postId, //Add your variables here
          'text': text,
        },
      );

      _navigationService.showTalawaErrorSnackBar(
        "Comment sent",
        MessageType.info,
      );
    } on Exception catch (_) {
      _navigationService.showTalawaErrorSnackBar(
        "Something went wrong",
        MessageType.error,
      );
    }
  }

here, the gqlAuthMutation function comes from: lib/services/database_mutation_functions.dart

  Future<QueryResult<Object?>> gqlAuthMutation(
    String mutation, {
    Map<String, dynamic>? variables,
  }) async {
    final MutationOptions options = MutationOptions(
      document: gql(mutation),
      variables: variables ?? <String, dynamic>{},
    );
    final response = await cacheService.executeOrCacheOperation(
      operation: mutation,
      variables: variables,
      operationType: CachedOperationType.gqlAuthMutation,
      whenOnline: () async {
        final QueryResult result = await clientAuth.mutate(options);
        print(result);
        // If there is an error or exception in [result]
        if (result.hasException) {
          GraphqlExceptionResolver.encounteredExceptionOrError(
            result.exception!,
          );
        } else if (result.data != null && result.isConcrete) {
          return result;
        }
        return noData;
      },
    );
    return response;
  }

finally, Yes, the gqlAuthMutation function directly queries the GraphQL service when the app is online or caches the request for offline scenario. So, there should be no clash with the changes made for error handling of the createComments function Thank you.

You can proceed with your approach.

Copy link

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Dec 11, 2024
@Cioppolo14
Copy link
Contributor

@rohansen856 Are you working on this?

@palisadoes
Copy link
Contributor Author

unassigning. Inactivity

@github-actions github-actions bot removed the no-issue-activity No issue activity label Dec 12, 2024
Copy link

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working no-issue-activity No issue activity
Projects
None yet
Development

No branches or pull requests

6 participants