-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't install the usage reporting plugin by default in subgraphs (#7184)
The usage reporting plugin is designed for monolithic graphs and Gateways, not for subgraphs. You will get strange results in GraphOS/Studio if you send usage reports from a subgraph to Studio. This PR changes the defaults so that subgraphs do not automatically install the usage reporting plugin even if API key and graph ref are provided; in this case, a warning is logged. You still can explicitly install ApolloServerPluginUsageReporting in subgraphs, though a warning will be logged. Fixes #7121. Also, update terminology around subgraphs. Various log messages and internal symbol names and comments referred to "federated service" rather than the newer and clearer "subgraph". Co-authored-by: Danielle Man <man.danielleh@gmail.com> Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
- Loading branch information
1 parent
46af825
commit b1548c1
Showing
10 changed files
with
123 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/server': minor | ||
--- | ||
|
||
Don't automatically install the usage reporting plugin in servers that appear to be hosting a federated subgraph (based on the existence of a field `_Service.sdl: String`). This is generally a misconfiguration. If an API key and graph ref are provided to the subgraph, log a warning and do not enable the usage reporting plugin. If the usage reporting plugin is explicitly installed in a subgraph, log a warning but keep it enabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { GraphQLSchema, isObjectType, isScalarType } from 'graphql'; | ||
|
||
// Returns true if it appears that the schema was appears to be of a subgraph | ||
// (eg, returned from @apollo/subgraph's buildSubgraphSchema). This strategy | ||
// avoids depending explicitly on @apollo/subgraph or relying on something that | ||
// might not survive transformations like monkey-patching a boolean field onto | ||
// the schema. | ||
// | ||
// This is used for two things: | ||
// 1) Determining whether traces should be added to responses if requested with | ||
// an HTTP header. If you want to include these traces even for non-subgraphs | ||
// (when requested via header, eg for Apollo Explorer's trace view) you can | ||
// use ApolloServerPluginInlineTrace explicitly; if you want to never include | ||
// these traces even for subgraphs you can use | ||
// ApolloServerPluginInlineTraceDisabled. | ||
// 2) Determining whether schema-reporting should be allowed; subgraphs cannot | ||
// report schemas, and we accordingly throw if it's attempted. | ||
export function schemaIsSubgraph(schema: GraphQLSchema): boolean { | ||
const serviceType = schema.getType('_Service'); | ||
if (!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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters