mirror of
https://github.com/vale981/apollo-server
synced 2025-03-05 17:51:40 -05:00
Merge pull request #1960 from apollographql/adam/18/11/client-info-default-to-headers
AER/Default to headers for client identity
This commit is contained in:
commit
e40a2e90c4
1 changed files with 30 additions and 4 deletions
|
@ -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
|
||||
|
@ -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: {
|
||||
|
|
Loading…
Add table
Reference in a new issue