-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked the version handling of Apollo Federation. (#6839)
- Loading branch information
1 parent
179234f
commit bb04265
Showing
38 changed files
with
578 additions
and
738 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...Chocolate/ApolloFederation/src/ApolloFederation/Extensions/FederationVersionExtensions.cs
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,81 @@ | ||
using System.Collections.Generic; | ||
using HotChocolate.Types.Descriptors; | ||
using HotChocolate.Types.Descriptors.Definitions; | ||
|
||
namespace HotChocolate.ApolloFederation; | ||
|
||
internal static class FederationVersionExtensions | ||
{ | ||
private static readonly Dictionary<Uri, FederationVersion> _uriToVersion = new() | ||
{ | ||
[new Uri(FederationVersionUrls.Federation20)] = FederationVersion.Federation20, | ||
[new Uri(FederationVersionUrls.Federation21)] = FederationVersion.Federation21, | ||
[new Uri(FederationVersionUrls.Federation22)] = FederationVersion.Federation22, | ||
[new Uri(FederationVersionUrls.Federation23)] = FederationVersion.Federation23, | ||
[new Uri(FederationVersionUrls.Federation24)] = FederationVersion.Federation24, | ||
[new Uri(FederationVersionUrls.Federation25)] = FederationVersion.Federation25, | ||
}; | ||
|
||
private static readonly Dictionary<FederationVersion, Uri> _versionToUri = new() | ||
{ | ||
[FederationVersion.Federation20] = new(FederationVersionUrls.Federation20), | ||
[FederationVersion.Federation21] = new(FederationVersionUrls.Federation21), | ||
[FederationVersion.Federation22] = new(FederationVersionUrls.Federation22), | ||
[FederationVersion.Federation23] = new(FederationVersionUrls.Federation23), | ||
[FederationVersion.Federation24] = new(FederationVersionUrls.Federation24), | ||
[FederationVersion.Federation25] = new(FederationVersionUrls.Federation25), | ||
}; | ||
|
||
public static FederationVersion GetFederationVersion<T>( | ||
this IDescriptor<T> descriptor) | ||
where T : DefinitionBase | ||
{ | ||
var contextData = descriptor.Extend().Context.ContextData; | ||
if (contextData.TryGetValue(FederationContextData.FederationVersion, out var value) && | ||
value is FederationVersion version and > FederationVersion.Unknown) | ||
{ | ||
return version; | ||
} | ||
|
||
// TODO : resources | ||
throw new InvalidOperationException("The configuration state is invalid."); | ||
} | ||
|
||
public static FederationVersion GetFederationVersion( | ||
this IDescriptorContext context) | ||
{ | ||
if (context.ContextData.TryGetValue(FederationContextData.FederationVersion, out var value) && | ||
value is FederationVersion version and > FederationVersion.Unknown) | ||
{ | ||
return version; | ||
} | ||
|
||
// TODO : resources | ||
throw new InvalidOperationException("The configuration state is invalid."); | ||
} | ||
|
||
public static Uri ToUrl(this FederationVersion version) | ||
{ | ||
if(_versionToUri.TryGetValue(version, out var url)) | ||
{ | ||
return url; | ||
} | ||
|
||
// TODO : resources | ||
throw new ArgumentException("The federation version is not supported.", nameof(version)); | ||
} | ||
|
||
public static FederationVersion ToVersion(this Uri url) | ||
{ | ||
if(_uriToVersion.TryGetValue(url, out var version)) | ||
{ | ||
return version; | ||
} | ||
|
||
// TODO : resources | ||
throw new ArgumentException("The federation url is not supported.", nameof(url)); | ||
} | ||
|
||
public static bool TryToVersion(this Uri url, out FederationVersion version) | ||
=> _uriToVersion.TryGetValue(url, out version); | ||
} |
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
35 changes: 0 additions & 35 deletions
35
src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationVersionExtensions.cs
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...hocolate/ApolloFederation/src/ApolloFederation/Types/Directives/AuthenticatedAttribute.cs
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
3 changes: 1 addition & 2 deletions
3
...hocolate/ApolloFederation/src/ApolloFederation/Types/Directives/AuthenticatedDirective.cs
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
2 changes: 1 addition & 1 deletion
2
src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/LinkDirective.cs
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
Oops, something went wrong.