Skip to content

Commit

Permalink
checkpoint towards including traces in federated service responses
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Jun 26, 2019
1 parent 47764ad commit 13bcd5c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ValidationContext,
FieldDefinitionNode,
DocumentNode,
isObjectType,
isScalarType,
} from 'graphql';
import { GraphQLExtension } from 'graphql-extensions';
import {
Expand Down Expand Up @@ -362,6 +364,11 @@ export class ApolloServerBase {
);
// Let's keep this extension second so it wraps everything, except error formatting
this.extensions.push(() => this.engineReportingAgent!.newExtension());
} else if (engine !== false && this.schemaIsFederated()) {
// We haven't configured this app to use Engine directly. But it looks like
// we are a federated service backend, so we should be capable of including
// our trace in a response extension if we are asked to by the gateway.
// FIXME actually write the extension
}

if (extensions) {
Expand Down Expand Up @@ -504,6 +511,31 @@ export class ApolloServerBase {
return false;
}

// Returns true if it appears that the schema was returned from
// @apollo/federation's buildFederatedSchema. This strategy avoids depending
// explicitly on @apollo/federation or relying on something that might not
// survive transformations like monkey-patching a boolean field onto the
// schema.
//
// The only thing this is used for is determining whether traces should be
// added to responses if requested with an HTTP header; if there's a false
// positive, that feature can be disabled by specifying `engine: false`.
private schemaIsFederated(): boolean {
const serviceType = this.schema.getType('_Service');
if (!(serviceType && isObjectType(serviceType))) {
return false;
}
const sdlField = serviceType.getFields().sdl;
if (!sdlField) {
return false;
}
const sdlFieldType = sdlField.type;
if (!isScalarType(sdlFieldType)) {
return false;
}
return sdlFieldType.name == 'String';
}

private ensurePluginInstantiation(plugins?: PluginDefinition[]): void {
if (!plugins || !plugins.length) {
return;
Expand Down

0 comments on commit 13bcd5c

Please sign in to comment.