New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't install the usage reporting plugin by default in subgraphs #7184
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6ebca53
Update terminology around subgraphs
glasser 7e2cbc3
Don't install the usage reporting plugin by default in subgraphs
glasser 4428081
Apply suggestions from code review
glasser 6bd943d
Update packages/server/src/plugin/usageReporting/options.ts
glasser File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tip on making this warning go away would probably be helpful here (recommend disabling usage reporting with the plugin?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it would be "remove the explicit installation" but that would affect more than the warning. I think we would want some sort of
ApolloServerPluginUsageReporting({ yesIKnowThisIsASubgraphAndThisIsWeirdDontWarnMe: true })
but maybe only do this if we really hear there are users who need this?