Skip to content
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

Included tag directive in Apollo Federation import list #7421

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public override void OnAfterCompleteName(
ITypeCompletionContext completionContext,
DefinitionBase definition)
{
if (definition is not ITypeDefinition and not DirectiveTypeDefinition)
if (_context.GetFederationVersion() == FederationVersion.Federation10
|| definition is not ITypeDefinition and not DirectiveTypeDefinition)
{
return;
}
Expand Down Expand Up @@ -161,16 +162,18 @@ public override void OnAfterCompleteName(
if (type.IsDefined(typeof(PackageAttribute)))
{
RegisterImport(type);
return;
}

if (type == typeof(DirectiveType<Tag>))
{
RegisterTagImport();
}

return;

void RegisterImport(MemberInfo element)
{
if (_context.GetFederationVersion() == FederationVersion.Federation10)
{
return;
}

var package = element.GetCustomAttribute<PackageAttribute>();

if (package is null)
Expand All @@ -193,6 +196,19 @@ void RegisterImport(MemberInfo element)
types.Add(completionContext.Type.Name);
}
}

void RegisterTagImport()
{
var packageUrl = FederationVersion.Federation20.ToUrl();

if (!_imports.TryGetValue(packageUrl, out var types))
{
types = [];
_imports[packageUrl] = types;
}

types.Add($"@{completionContext.Type.Name}");
}
}

public override void OnTypesCompletedName()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@tag", "@key", "@provides", "@external", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@tag", "@key", "@provides", "@external", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@external", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @composeDirective(name: "custom") @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@composeDirective" ]) @link(url: "https:\/\/specs.custom.dev\/custom\/v1.0", import: [ "@custom" ]) {
schema @composeDirective(name: "custom") @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet", "@composeDirective" ]) @link(url: "https:\/\/specs.custom.dev\/custom\/v1.0", import: [ "@custom" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@external", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@external", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@external", "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypePropertyDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypePropertyDirectives
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypeClassDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypeClassDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypePropertyDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypePropertyDirectives
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypeClassDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: QueryOfTestTypeClassDirective
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@override", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@override", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.7", import: [ "@key", "@override", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.7", import: [ "@key", "@override", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@policy" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet", "@policy" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@policy" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet", "@policy" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@policy", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@policy", "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@provides", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@provides", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@provides", "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@requires", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@requires", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@requires", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@requires", "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@requiresScopes" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet", "@requiresScopes" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet", "@requiresScopes" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet", "@requiresScopes" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@requiresScopes", "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@requiresScopes", "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task TestServiceTypeEmptyQueryTypePureCodeFirst()
.Parse((string)value!)
.MatchInlineSnapshot(
"""
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public async Task TestServiceTypeTypePureCodeFirst()
.Parse((string)value!)
.MatchInlineSnapshot(
"""
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.2", import: [ "@key", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.2", import: [ "@key", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@shareable", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@shareable", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@shareable", "FieldSet" ]) {
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.6", import: [ "@shareable", "@tag", "FieldSet" ]) {
query: Query
}

Expand Down
Loading