awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
921 stars 266 forks source link

TypeError: Cannot read properties of null (reading 'match') #743

Closed Adeeltahir1995 closed 1 year ago

Adeeltahir1995 commented 1 year ago

Note: If your issue/feature-request/question is regarding the AWS AppSync service, please log it in the official AWS AppSync forum

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

When I create AWSAppSyncClient instance using AUTH_TYPE as AWS_IAM it supposed to automatically use appsync as service name as it is defined a constant Reference

But instead it throws an error TypeError: Cannot read properties of null (reading 'match') at line while signing the request.

This is happening because I have a custom domain on top of the appsync generated domain. Since the code is trying to parse the url to infer the service type before it actually sign it, the use of custom domain raises the exception. Whereas for the actual appsync domain url it works fine.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

For version 4.1.9:

  1. Create a client instance for auth type AUTH_TYPE.AWS_IAM
  2. Provide a custom domain instead of the actual appsync domain name in the url parameter
  3. Run the code

It should throw error with following error stack:

Error:
TypeError: Cannot read properties of null (reading 'match')
    at parse_service_info (/Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/signer/signer.js:98:24)
    at Function.sign (/Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/signer/signer.js:220:36)
    at /Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/auth-link.js:155:47
    at step (/Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/auth-link.js:57:23)
    at Object.next (/Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/auth-link.js:38:53)
    at fulfilled (/Users/mac/Documents/kfc-lambda-restaurant-status-monitoring/node_modules/aws-appsync-auth-link/lib/auth-link.js:29:58)
error Command failed with exit code 1.

What is the expected behavior?

The package should by default use appsync as service name and should not use the url parameter to infer the service.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?

Not sure about previous versions

manueliglesias commented 1 year ago

Hi @Adeeltahir1995

For front-end web and mobile development, we recommend using the Amplify clients which are optimized to connect to the AppSync backend. We have docs with instructions on how to connect to an AppSync API behind a custom domain.

Adeeltahir1995 commented 1 year ago

Hello @manueliglesias
Thank you for the comment. I am using this package inside a backend lambda. I can not use amplify since that is built for frontend.