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

feat(apollo-engine-reportoing): sendVariableValues and sendHeaders. #2931

Merged
merged 12 commits into from Jun 27, 2019

Conversation

helenwh
Copy link
Contributor

@helenwh helenwh commented Jun 26, 2019

Reopening: #2847
After the revert: #2930

(Copied from PR #2847)
Addressing the issues in: https://apollographql.atlassian.net/browse/BE-93
And a followup to this PR: #2472

  • Adding a new EngineReportingOptions parameter, sendVariableValues, that accepts custom functions for modifying private or sensitive variable values in addition to the booleans/arrays previously supported by the privateVariables option. Defaults to blocklisting all values.

  • DEPRECATING privateVariables

  • Adding a new parameter, sendHeaders, which defaults to a blocklist as well, but otherwise preserves properties of privateHeaders

  • DEPRECATING privateHeaders

Docs preview: https://deploy-preview-2937--apollo-server-docs.netlify.com/docs/apollo-server/api/apollo-server/#enginereportingoptions

[Question/Discussion] I am thinking about including a VariableModificationType in the messaging for a later PR, but it might be unnecessary; I would need to make changes in the UI for it to be used, and I'm not sure if users care/want to know how their variables are being modified?

@helenwh helenwh requested review from glasser and zionts June 26, 2019 22:32
Copy link
Contributor

@zionts zionts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as the previous one was good to go, but we just wanted to wait on feedback from partners before merging and releasing :)

Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a number of nits, a couple documentation formatting things, and just one thing in particular that could be problematic down the line we don't change it now with regards to using object literals. I do think most of the TODO items should/could be quelled?

That said, let's get this into 2.7.0 alpha today!

docs/source/api/apollo-server.md Outdated Show resolved Hide resolved
docs/source/api/apollo-server.md Outdated Show resolved Hide resolved
docs/source/api/apollo-server.md Outdated Show resolved Hide resolved
docs/source/api/apollo-server.md Outdated Show resolved Hide resolved
docs/source/api/apollo-server.md Outdated Show resolved Hide resolved
packages/apollo-engine-reporting/src/agent.ts Outdated Show resolved Hide resolved
packages/apollo-engine-reporting/src/extension.ts Outdated Show resolved Hide resolved
// This probably means that the value contains a circular reference,
// causing `JSON.stringify()` to throw a TypeError:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Issue_with_JSON.stringify()_when_serializing_circular_references
details.variablesJson![name] = JSON.stringify(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be defensive and make sure that it does! (and maybe just use the standardized error message?)

if (e.name === 'TypeError' && e.message === 'Converting circular structure to JSON') {
  details.variablesJson![name] = JSON.stringify(e.message);
} else {
  // Re-throw when it doesn't meet our expectation so we don't
  // inadvertently swallow anything as a "cycle error" when its not.
  throw e;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good way to check against the standardized error message? It looks like it differs per browser:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value

packages/apollo-engine-reporting/src/extension.ts Outdated Show resolved Hide resolved
packages/apollo-engine-reporting/src/extension.ts Outdated Show resolved Hide resolved
@abernix abernix added this to the Release 2.7.0 milestone Jun 27, 2019
@helenwh helenwh force-pushed the EnforcingPrivateVariables branch 4 times, most recently from 90ef77c to 20ac4db Compare June 27, 2019 18:09
@abernix abernix changed the base branch from master to release-2.7.0 June 27, 2019 19:48
@abernix abernix changed the base branch from release-2.7.0 to master June 27, 2019 20:14
Helen Ho and others added 9 commits June 27, 2019 23:24
…kVariableValues), but this is still TBD

- use the same helper for both the deprecated privateVariable option and the new option, since the logic is (basically) the same
- added helper (and tests) to enforce that originalVariables.keys == modifiedVariables.keys
- updated documentation
…omparisons, constant declarations), more test cases

Co-Authored-By: Jesse Rosenberger <git@jro.cc>
@abernix abernix changed the base branch from master to release-2.7.0 June 27, 2019 20:32
Node.js only raises this particular error when cycles are detected.

While I first thought it was more defensive to catch the exact error we
anticipated, I'm slightly reconsidering whether this is defensive enough and
if we should, in fact, change this back to catching any error, particularly
since this runs async and might go undetected or cause a whole string of
a user's errors to not pass any variables.

Thoughts, @glasser?
I thought it made sense to catch only cycles, but I've changed my mind.  I
think there could be just arbitrary errors in a `toString` or `toJSON`
implementation which we'd still want to guard, particularly because these
errors are shipped async.

Ref: 4b2f9d3
Ref: #2931 (comment)
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for working on this!

This is a wonderful PR with excellent test coverage and documentation: A huge improvement over the previous privateVariables implementation.

Note that I rescinded on one of my suggestions in #2931 (comment) and reverted it back to how you had it. See 4b2f9d3 and 6c9aa8f for the follow-ups and thoughts that led to that.

@abernix abernix changed the title Reopening PR #2847: Adding sendVariableValues and sendHeaders parameters and specifications to engine feat(apollo-engine-reportoing): sendVariableValues and sendHeaders. Jun 27, 2019
@abernix abernix merged commit 166b6d9 into release-2.7.0 Jun 27, 2019
@abernix abernix deleted the EnforcingPrivateVariables branch June 27, 2019 20:59
@abernix
Copy link
Member

abernix commented Jun 27, 2019

Successfully published:
 - apollo-engine-reporting@1.4.0-alpha.1
 - apollo-server-azure-functions@2.7.0-alpha.1
 - apollo-server-cloud-functions@2.7.0-alpha.1
 - apollo-server-cloudflare@2.7.0-alpha.1
 - apollo-server-core@2.7.0-alpha.1
 - apollo-server-express@2.7.0-alpha.1
 - apollo-server-fastify@2.7.0-alpha.1
 - apollo-server-hapi@2.7.0-alpha.1
 - apollo-server-koa@2.7.0-alpha.1
 - apollo-server-lambda@2.7.0-alpha.1
 - apollo-server-micro@2.7.0-alpha.1
 - apollo-server-testing@2.7.0-alpha.1
 - apollo-server@2.7.0-alpha.1

helenwh pushed a commit that referenced this pull request Jul 17, 2019
…Option (#3049)

* fix error handling bug in `sendVariableValues` EngineReportingOption

* fixing docs to describe error more precisely

Co-Authored-By: Jesse Rosenberger <git@jro.cc>

* updating changelog w/ info on error fix, adding a line to the 2.7.0 notes on the `sendHeaders` option that was missed in PR #2931
abernix added a commit that referenced this pull request Apr 14, 2020
This APQ flag reporting was almost surely changed incorrectly in #2931 and
not caught during review, causing this APQ boolean to not be properly set
when the request was, in fact, an APQ request, unless `sendHeaders` was
enabled - which it is _not_ by default after the change that released it.

Ref: https://github.com/apollographql/apollo-server/pull/2931/files#diff-24ae042112f9dcc18543ac851c4d8f7cR97-R102
abernix added a commit that referenced this pull request Apr 14, 2020
This APQ flag reporting was almost surely changed incorrectly in #2931 and
not caught during review, causing this APQ boolean to not be properly set
when the request was, in fact, an APQ request, unless `sendHeaders` was
enabled - which it is _not_ by default after the change that released it.

Ref: https://github.com/apollographql/apollo-server/pull/2931/files#diff-24ae042112f9dcc18543ac851c4d8f7cR97-R102
abernix added a commit that referenced this pull request Apr 15, 2020
This APQ flag reporting was almost surely changed incorrectly in #2931 and
not caught during review, causing this APQ boolean to not be properly set
when the request was, in fact, an APQ request, unless `sendHeaders` was
enabled - which it is _not_ by default after the change that released it.

Ref: https://github.com/apollographql/apollo-server/pull/2931/files#diff-24ae042112f9dcc18543ac851c4d8f7cR97-R102
abernix added a commit that referenced this pull request Apr 16, 2020
* fix: report APQ hit/registration when `sendHeaders` is disabled.

This APQ flag reporting was almost surely changed incorrectly in #2931 and
not caught during review, causing this APQ boolean to not be properly set
when the request was, in fact, an APQ request, unless `sendHeaders` was
enabled - which it is _not_ by default after the change that released it.

Ref: https://github.com/apollographql/apollo-server/pull/2931/files#diff-24ae042112f9dcc18543ac851c4d8f7cR97-R102

* Add CHANGELOG.md for #3986.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants