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

Introduce usage reporting signature and its components #92

Merged
merged 19 commits into from
May 19, 2022

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented May 13, 2022

Introduce a new @apollo/utils.usagereporting package which exports common bits of usage reporting code shared between apollo-server and router-bridge.

Consequently, this also introduces/updates a few other related packages:
@apollo/utils.removealiases
@apollo/utils.stripsensitiveliterals

These transforms are used by usagereporting in order to derive the operation signature.

For testing purposes, I've also introduced a snapshot serializer for printing GraphQL AST nodes.
@apollo/utils.jest-graphql-ast-serializer

This PR addresses @glasser 's comment apollographql/federation#1841 (comment)
Related: apollographql/federation#1841
cc @o0Ignition0o

TODO:

@changeset-bot
Copy link

changeset-bot bot commented May 13, 2022

🦋 Changeset detected

Latest commit: c068530

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@apollo/utils.jest-graphql-ast-serializer Major
@apollo/utils.removealiases Major
@apollo/utils.stripsensitiveliterals Minor
@apollo/utils.usagereporting Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 13, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

otherwise looks good though I know that @o0Ignition0o said he did make some changes in the router code? so let's make sure whatever changes those are get integrated.

packages/hideLiterals/src/index.ts Outdated Show resolved Hide resolved
packages/removeAliases/src/index.ts Outdated Show resolved Hide resolved
@glasser
Copy link
Member

glasser commented May 17, 2022

Consider switching to stripIgnoredCharacters now. This affects tests (spacing, commas). @glasser maybe you can help me understand the downstream impact w.r.t. Studio that this would have.

I spoke with @timbotnik and @zionts about this. We should still plan on pairing this with other changes that affect the signature, of which they have one (not stripping the contents of lists and objects) planned for the next few months hopefully. So no need to do this today.

@o0Ignition0o
Copy link

This looks great! 🎉

I tried to depend on it to see if the router bridge tests still pass, and I m hitting this error:

npm i https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.createhash https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.dropunuseddefinitions https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.fetcher https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.hideliterals https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.isnodelike https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.logger https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.operationregistrysignature https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.printwithreducedwhitespace https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.removealiases https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.sortast https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.stripsensitiveliterals https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.usagereportingsignature
npm ERR! code E404
npm ERR! 404 Not Found - GET https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.operationregistrysignature
npm ERR! 404 
npm ERR! 404  'https://pkg.csb.dev/apollographql/apollo-utils/commit/b100d75d/@apollo/utils.operationregistrysignature' is not in this registry.
npm ERR! 404 This package name is not valid, because 
npm ERR! 404  1. name can only contain URL-friendly characters
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ignition/.npm/_logs/2022-05-17T10_14_22_476Z-debug-0.log

Happy to pair with you so we can try to wire the bridge against this changeset, if the router-bridge tests pass, we should be good!

@trevor-scheer trevor-scheer force-pushed the trevor/usage-reporting-signature branch from 5512715 to ee46e01 Compare May 18, 2022 20:56
packages/jest/package.json Outdated Show resolved Hide resolved
Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

looking good otherwise. also still unclear what the changes @o0Ignition0o made when importing into router are — did you two go over that?

packages/jest/src/astSerializer.ts Outdated Show resolved Hide resolved
}
`),
),
).toMatchInlineSnapshot(`
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you need to install the serializer here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's never a requirement, but good catch (using it here now)

Copy link
Member

Choose a reason for hiding this comment

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

ah you were using print before

packages/stripSensitiveLiterals/src/index.ts Outdated Show resolved Hide resolved
packages/usageReporting/README.md Outdated Show resolved Hide resolved
@trevor-scheer
Copy link
Member Author

@glasser I did go over with @o0Ignition0o, we actually tested out the code in runtime. The changes necessary in router-bridge were actually at the top level function which called the two important additions here (usageReportingSignature and calculateReferencedFieldsByType, so these bits were still identical between AS and router-bridge.

@trevor-scheer trevor-scheer marked this pull request as ready for review May 18, 2022 23:31
@glasser
Copy link
Member

glasser commented May 19, 2022

Before merging perhaps check that the codesandbox packages can work directly in router and apollo-server? But if that requires a follow-up patch that's fine too.

@trevor-scheer
Copy link
Member Author

@o0Ignition0o can we update apollographql/federation-rs#120 with the latest build from codesandbox?

Notably: there's only one package now, so you can uninstall the existing ones and run
npm install https://pkg.csb.dev/apollographql/apollo-utils/commit/c0685309/@apollo/utils.usagereporting

The package name is changed as well, so you'll need to update the imports to be from "@apollo/utils.usagereporting".

@o0Ignition0o
Copy link

@trevor-scheer I just did, it looks super neat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants