Skip to content

Commit

Permalink
aer/Default to headers for client identity in
Browse files Browse the repository at this point in the history
lolwut

Revert "lolwut"

This reverts commit 03a2e10.
  • Loading branch information
Adam Zionts committed Nov 14, 2018
1 parent 34cb3ea commit 81d9f47
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/apollo-engine-reporting/src/extension.ts
Expand Up @@ -19,6 +19,10 @@ import { EngineReportingOptions, GenerateClientInfo } from './agent';
import { defaultSignature } from './signature';
import { GraphQLRequestContext } from 'apollo-server-core/dist/requestPipelineAPI';

const clientNameHeaderKey = 'apollographql-client-name';
const clientReferenceIdHeaderKey = 'apollographql-client-reference-id';
const clientVersionHeaderKey = 'apollographql-client-version';

// EngineReportingExtension is the per-request GraphQLExtension which creates a
// trace (in protobuf Trace format) for a single request. When the request is
// done, it passes the Trace back to its associated EngineReportingAgent via the
Expand Down Expand Up @@ -55,10 +59,32 @@ export class EngineReportingExtension<TContext = any>
this.nodes.set(responsePathAsString(undefined), root);
this.generateClientInfo =
options.generateClientInfo ||
// Default to using the clientInfo field of the request's extensions, when
// the ClientInfo fields are undefined, we send the empty string
(({ request }) =>
(request.extensions && request.extensions.clientInfo) || {});
// Default to using the `apollo-client-x` header fields if present.
// If none are present, fallback on the `clientInfo` query extension
// for backwards compatibility.
// The default value if neither header values nor query extension is
// set is the empty String for all fields (as per protobuf defaults)
(({ request }) => {
if (
request.http &&
request.http.headers &&
(request.http.headers.get(clientNameHeaderKey) ||
request.http.headers.get(clientVersionHeaderKey) ||
request.http.headers.get(clientReferenceIdHeaderKey))
) {
return {
clientName: request.http.headers.get(clientNameHeaderKey),
clientVersion: request.http.headers.get(clientVersionHeaderKey),
clientReferenceId: request.http.headers.get(
clientReferenceIdHeaderKey,
),
};
} else if (request.extensions && request.extensions.clientInfo) {
return request.extensions.clientInfo;
} else {
return {};
}
});
}

public requestDidStart(o: {
Expand Down

0 comments on commit 81d9f47

Please sign in to comment.