Skip to content

Commit

Permalink
Revert "Inline usage reporting protobuf into main package (#6515)"
Browse files Browse the repository at this point in the history
This reverts commit 0b58585.

This leaves the fix of adding cors and body-parser to server's deps and
leaves the removal of a TODO(AS4) about this.

The build process for this package is completely different from a normal
TS package, so keeping it together seems best. This seems like it'll
make setting up ESM builds easier.
  • Loading branch information
glasser committed Jun 14, 2022
1 parent 0c1a6ce commit 15e9e85
Show file tree
Hide file tree
Showing 31 changed files with 3,516 additions and 1,072 deletions.
1 change: 1 addition & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"buildCommand": "compile",
"installCommand": "install-with-npm-8.5",
"packages": [
"packages/usage-reporting-protobuf",
"packages/server"
],
"sandboxes": ["apollo-server-typescript-3opde","apollo-server"],
Expand Down
4,405 changes: 3,397 additions & 1,008 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
"codegen": "graphql-codegen",
"prettier-check": "prettier --check .",
"prettier-fix": "prettier --write .",
"spell-check": "cspell lint '**' --no-progress || (echo 'Add any real words to cspell-dict.txt.'; exit 1)",
"protobuf-generate": "rm -rf packages/server/usageReportingProtobuf/generated && mkdir packages/server/usageReportingProtobuf/generated && npm run protobuf-pbjs && npm run protobuf-pbts",
"protobuf-pbjs": "apollo-pbjs --target static-module --out packages/server/usageReportingProtobuf/generated/protobuf.js --wrap commonjs --force-number --no-from-object packages/server/usageReportingProtobuf/reports.proto",
"protobuf-pbts": "apollo-pbts -o packages/server/usageReportingProtobuf/generated/protobuf.d.ts packages/server/usageReportingProtobuf/generated/protobuf.js",
"protobuf-update": "curl -sSfo packages/server/usageReportingProtobuf/reports.proto https://usage-reporting.api.apollographql.com/proto/reports.proto"
"spell-check": "cspell lint '**' --no-progress || (echo 'Add any real words to cspell-dict.txt.'; exit 1)"
},
"workspaces": [
"packages/*"
Expand Down
1 change: 0 additions & 1 deletion packages/server/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ src/**/__tests__/**
dist/**/__tests__/**
!package.json
!README.md
!usageReportingProtobuf/**/*
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"node": ">=12.0"
},
"dependencies": {
"@apollo/protobufjs": "1.2.2",
"@apollo/usage-reporting-protobuf": "^3.3.0",
"@apollo/utils.createhash": "^1.1.0",
"@apollo/utils.fetcher": "^1.0.0",
"@apollo/utils.isnodelike": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express from 'express';
import bodyParser from 'body-parser';
import loglevel from 'loglevel';

import { Report, Trace } from '../../../usageReportingProtobuf';
import { Report, Trace } from '@apollo/usage-reporting-protobuf';

import {
GraphQLSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ITrace,
ITracesAndStats,
ContextualizedStats,
} from '../../../../usageReportingProtobuf';
} from '@apollo/usage-reporting-protobuf';
import { pluginsEnabledForSchemaResolvers } from '../../../utils/schemaInstrumentation';
import nock from 'nock';
import sumBy from 'lodash.sumby';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trace } from '../../../../usageReportingProtobuf';
import { Trace } from '@apollo/usage-reporting-protobuf';
import { dateToProtoTimestamp } from '../../../plugin/traceTreeBuilder';
import {
OurContextualizedStats,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeTraceDetails } from '../../../plugin/usageReporting/traceDetails';
import { Trace } from '../../../../usageReportingProtobuf';
import { Trace } from '@apollo/usage-reporting-protobuf';
import { GraphQLError } from 'graphql';

const variables: Record<string, any> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/externalTypes/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Trace } from '../../usageReportingProtobuf';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import type { Logger } from '@apollo/utils.logger';
import type {
DocumentNode,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/inlineTrace/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trace } from '../../../usageReportingProtobuf';
import { Trace } from '@apollo/usage-reporting-protobuf';
import { TraceTreeBuilder } from '../traceTreeBuilder';
import type { ApolloServerPluginUsageReportingOptions } from '../usageReporting/options';
import type { InternalApolloServerPlugin } from '../../internalPlugin';
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/traceTreeBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This class is a helper for ApolloServerPluginUsageReporting and
// ApolloServerPluginInlineTrace.
import { GraphQLError, GraphQLResolveInfo, ResponsePath } from 'graphql';
import { Trace, google } from '../../usageReportingProtobuf';
import { Trace, google } from '@apollo/usage-reporting-protobuf';
import type { Logger } from '@apollo/utils.logger';

function internalError(message: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LRUCache from 'lru-cache';
import type { Trace } from '../../../usageReportingProtobuf';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import { iterateOverTrace } from './iterateOverTrace';
import { DurationHistogram } from './durationHistogram';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Trace } from '../../../usageReportingProtobuf';
import type { Trace } from '@apollo/usage-reporting-protobuf';

/**
* Iterates over the entire trace, calling `f` on each Trace.Node found. It
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/usageReporting/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
BaseContext,
} from '../../externalTypes';
import type { Logger } from '@apollo/utils.logger';
import type { Trace } from '../../../usageReportingProtobuf';
import type { Trace } from '@apollo/usage-reporting-protobuf';
import type { Fetcher } from '@apollo/utils.fetcher';

export interface ApolloServerPluginUsageReportingOptions<
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/usageReporting/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Report, ReportHeader, Trace } from '../../../usageReportingProtobuf';
import { Report, ReportHeader, Trace } from '@apollo/usage-reporting-protobuf';
import type { Fetcher, FetcherResponse } from '@apollo/utils.fetcher';
import {
usageReportingSignature,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/usageReporting/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ITypeStat,
ReportHeader,
Trace,
} from '../../../usageReportingProtobuf';
} from '@apollo/usage-reporting-protobuf';
import type { ReferencedFieldsByType } from '@apollo/utils.usagereporting';
import { DurationHistogram } from './durationHistogram';
import { iterateOverTrace, ResponseNamePath } from './iterateOverTrace';
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/usageReporting/traceDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trace } from '../../../usageReportingProtobuf';
import { Trace } from '@apollo/usage-reporting-protobuf';
import type { VariableValueOptions } from './options';

// Creates trace details from request variables, given a specification for modifying
Expand Down
41 changes: 0 additions & 41 deletions packages/server/usageReportingProtobuf/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions packages/server/usageReportingProtobuf/index.d.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/usage-reporting-protobuf/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Note that this npmignore file differs from the others because this package
# puts its generated files in "generated" and checks them in to git rather than
# unversioned in "dist".

*
!src/**/*
src/**/__tests__/**
!generated/**/*
generated/**/__tests__/**
!package.json
!README.md
39 changes: 39 additions & 0 deletions packages/usage-reporting-protobuf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# `apollo-reporting-protobuf`

> **Note:** The Apollo usage reporting API is subject to change. We strongly
> encourage developers to contact Apollo support at `support@apollographql.com`
> to discuss their use case prior to building their own reporting agent using
> this module.
This module provides JavaScript/TypeScript
[Protocol buffer](https://developers.google.com/protocol-buffers/) definitions
for the Apollo usage reporting API. These definitions are generated for
consumption from the `reports.proto` file which is defined internally within
Apollo.

## Development

> **Note:** Due to a dependency on Unix tools (e.g. `bash`, `grep`, etc.), the
> development of this module requires a Unix system. There is no reason why
> this can't be avoided, the time just hasn't been taken to make those changes.
> We'd happily accept a PR which makes the appropriate changes!
Currently, this package generates a majority of its code with
`@apollo/protobufjs` (a fork of
[`protobufjs`](https://www.npmjs.com/package/protobufjs) that we maintain
specifically for this package) based on the `reports.proto` file. The output is
generated with the `generate` npm script.

The root of the repository provides some `devDependencies` necessary to build
these definitions and the `prepare` npm script is invoked programmatically via
the monorepo tooling (e.g. Lerna) thanks to _this_ module's `postinstall`
script. Therefore, when making changes to this module, run scripts via `npx
lerna run SCRIPTNAME` in the **root** of this monorepo in order to update the
definitions in _this_ module.

To update `reports.proto` to the current version recognized by the Studio usage
reporting ingress, run `lerna run update-proto`. To then regenerate the JS and
TS files, run `npx lerna run generate`. We check in the generated code and only
regenerate it manually, partially to make builds faster (no need to run pbjs on
every `npm install`) and partially so that we don't have to make sure that
`pbjs` runs on every Node version that we support.
2 changes: 2 additions & 0 deletions packages/usage-reporting-protobuf/generated/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as protobuf from './protobuf';
export = protobuf;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const protobuf = require('./generated/protobuf');
const protobuf = require('./protobuf');
const protobufJS = require('@apollo/protobufjs/minimal');

// Remove Long support. Our uint64s tend to be small (less
Expand Down
36 changes: 36 additions & 0 deletions packages/usage-reporting-protobuf/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@apollo/usage-reporting-protobuf",
"version": "3.3.1",
"description": "Protobuf format for Apollo usage reporting",
"main": "generated/index.js",
"types": "generated/index.d.ts",
"scripts": {
"generate": "rm -rf generated && mkdir generated && npm run pbjs && npm run pbts && cp src/index.* generated",
"pbjs": "apollo-pbjs --target static-module --out generated/protobuf.js --wrap commonjs --force-number --no-from-object src/reports.proto",
"pbts": "apollo-pbts -o generated/protobuf.d.ts generated/protobuf.js",
"update-proto": "curl -sSfo src/reports.proto https://usage-reporting.api.apollographql.com/proto/reports.proto"
},
"repository": {
"type": "git",
"url": "https://github.com/apollographql/apollo-server",
"directory": "packages/usage-reporting-protobuf"
},
"keywords": [
"GraphQL",
"Apollo",
"Server",
"Javascript"
],
"author": "Apollo <packages@apollographql.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollographql/apollo-server/issues"
},
"homepage": "https://github.com/apollographql/apollo-server#readme",
"dependencies": {
"@apollo/protobufjs": "1.2.2"
},
"volta": {
"extends": "../../package.json"
}
}
2 changes: 2 additions & 0 deletions packages/usage-reporting-protobuf/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as protobuf from './protobuf';
export = protobuf;
12 changes: 12 additions & 0 deletions packages/usage-reporting-protobuf/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const protobuf = require('./protobuf');
const protobufJS = require('@apollo/protobufjs/minimal');

// Remove Long support. Our uint64s tend to be small (less
// than 104 days).
// XXX Just remove this in our fork? We already deleted
// the generation of Long in protobuf.d.ts in the fork.
// https://github.com/protobufjs/protobuf.js/issues/1253
protobufJS.util.Long = undefined;
protobufJS.configure();

module.exports = protobuf;

0 comments on commit 15e9e85

Please sign in to comment.