apollo-server-integrations / apollo-server-integration-aws-lambda

An integration to use AWS Lambda as a hosting service with Apollo Server
MIT License
46 stars 9 forks source link

GET requests fail due to uri encoding #120

Closed michaelCaleyWhaley closed 1 year ago

michaelCaleyWhaley commented 1 year ago

Recently setup a lambda behind an ALB and attempted to make GET requests resulting in error message 'The variables search parameter contains invalid JSON.'

Example query params

queryStringParameters: {
          operationName: 'product',
          query: example query',
          variables:
'%7B%22productId%22%3A%22756817%22%2C%22countryCode%22%3A%22GB%22%2C%22currencyCode%22%3A%22GBP%22%7D',
        }

decoding the value via decodeURIComponent solved the issue.

parseQueryParams(event) {
      const params = new URLSearchParams();
      for (const [key, value] of Object.entries((event.queryStringParameters as Record<string, string>) ?? {})) {
        params.append(key, decodeURIComponent(value) ?? '');
      }
      for (const [key, value] of Object.entries(
        (event.multiValueQueryStringParameters as Record<string, string> | undefined) ?? {},
      )) {
        for (const v of value ?? []) {
          params.append(key, v);
        }
      }
      return params.toString();
    }
BlenderDude commented 1 year ago

Thanks for reporting this, seems to be an oversight in testing. I'll get a fix implemented and pushed here in the next day or so!

BlenderDude commented 1 year ago

Fixed in #122