This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
@contact
directive (#21)
Adds new `@contact` directive. ```graphql directive @contact( "Contact title of the subgraph owner" name: String! "URL where the subgraph's owner can be reached" url: String "Other relevant notes can be included here; supports markdown links" description: String ) on SCHEMA ``` Contact schema directive can be used to provide team contact information to your subgraph schema. This information is automatically parsed and displayed by Apollo Studio. See [Subgraph Contact Information](https://www.apollographql.com/docs/graphos/graphs/federated-graphs/#contact-info-for-subgraphs) for additional details.
- Loading branch information
1 parent
98205b0
commit 97674e7
Showing
11 changed files
with
281 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using HotChocolate.Types.Descriptors; | ||
using static ApolloGraphQL.HotChocolate.Federation.ThrowHelper; | ||
|
||
namespace ApolloGraphQL.HotChocolate.Federation; | ||
|
||
/// <summary> | ||
/// <code> | ||
/// directive @contact( | ||
/// "Contact title of the subgraph owner" | ||
/// name: String! | ||
/// "URL where the subgraph's owner can be reached" | ||
/// url: String | ||
/// "Other relevant notes can be included here; supports markdown links" | ||
/// description: String | ||
/// ) on SCHEMA | ||
/// </code> | ||
/// | ||
/// Contact schema directive can be used to provide team contact information to your subgraph schema. This information is automatically parsed and displayed by Apollo Studio. | ||
/// See <see href="https://www.apollographql.com/docs/graphos/graphs/federated-graphs/#contact-info-for-subgraphs">Subgraph Contact Information</see> for additional details. | ||
/// | ||
/// NOTE: Only available in Federation v2 | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// schema @contact(description : "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall).", name : "My Team Name", url : "https://myteam.slack.com/archives/teams-chat-room-url"){ | ||
/// query: Query | ||
/// } | ||
/// </code> | ||
/// </example> | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)] | ||
public sealed class ContactAttribute : SchemaTypeDescriptorAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes new instance of <see cref="ContactAttribute"/> | ||
/// </summary> | ||
/// <param name="name"> | ||
/// Contact title of the subgraph owner | ||
/// </param> | ||
/// <param name="url"> | ||
/// URL where the subgraph's owner can be reached | ||
/// </param> | ||
/// <param name="description"> | ||
/// Other relevant contact notes; supports markdown links | ||
/// </param> | ||
public ContactAttribute(string name, string? url = null, string? description = null) | ||
{ | ||
Name = name; | ||
Url = url; | ||
Description = description; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the contact title of the subgraph owner. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the url where the subgraph's owner can be reached. | ||
/// </summary> | ||
public string? Url { get; } | ||
|
||
/// <summary> | ||
/// Gets other relevant notes about subgraph contact information. Can include markdown links. | ||
/// </summary> | ||
public string? Description { get; } | ||
|
||
public override void OnConfigure(IDescriptorContext context, ISchemaTypeDescriptor descriptor, Type type) | ||
{ | ||
if (string.IsNullOrEmpty(Url)) | ||
{ | ||
throw Contact_Name_CannotBeEmpty(type); | ||
} | ||
descriptor.Contact(Name, Url, Description); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace ApolloGraphQL.HotChocolate.Federation.Two; | ||
|
||
public sealed class Contact | ||
{ | ||
/// <summary> | ||
/// Initializes new instance of <see cref="Contact"/> | ||
/// </summary> | ||
/// <param name="name"> | ||
/// Contact title of the subgraph owner | ||
/// </param> | ||
/// <param name="url"> | ||
/// URL where the subgraph's owner can be reached | ||
/// </param> | ||
/// <param name="description"> | ||
/// Other relevant notes can be included here; supports markdown links | ||
/// </param> | ||
public Contact(string name, string? url, string? description) | ||
{ | ||
Name = name; | ||
Url = url; | ||
Description = description; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the contact title of the subgraph owner. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the url where the subgraph's owner can be reached. | ||
/// </summary> | ||
public string? Url { get; } | ||
|
||
/// <summary> | ||
/// Gets other relevant notes about subgraph contact information. Can include markdown links. | ||
/// </summary> | ||
public string? Description { get; } | ||
} |
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,38 @@ | ||
using ApolloGraphQL.HotChocolate.Federation.Constants; | ||
using ApolloGraphQL.HotChocolate.Federation.Properties; | ||
|
||
namespace ApolloGraphQL.HotChocolate.Federation.Two; | ||
|
||
/// <summary> | ||
/// <code> | ||
/// directive @contact( | ||
/// "Contact title of the subgraph owner" | ||
/// name: String! | ||
/// "URL where the subgraph's owner can be reached" | ||
/// url: String | ||
/// "Other relevant notes can be included here; supports markdown links" | ||
/// description: String | ||
/// ) on SCHEMA | ||
/// </code> | ||
/// | ||
/// Contact schema directive can be used to provide team contact information to your subgraph schema. This information is automatically parsed and displayed by Apollo Studio. | ||
/// See <see href="https://www.apollographql.com/docs/graphos/graphs/federated-graphs/#contact-info-for-subgraphs">Subgraph Contact Information</see> for additional details. | ||
/// | ||
/// NOTE: Only available in Federation v2 | ||
/// | ||
/// <example> | ||
/// <code> | ||
/// schema @contact(description : "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall).", name : "My Team Name", url : "https://myteam.slack.com/archives/teams-chat-room-url"){ | ||
/// query: Query | ||
/// } | ||
/// </code> | ||
/// </example> | ||
/// </summary> | ||
public sealed class ContactDirectiveType : DirectiveType<Contact> | ||
{ | ||
protected override void Configure(IDirectiveTypeDescriptor<Contact> descriptor) | ||
=> descriptor | ||
.Name(WellKnownTypeNames.ContactDirective) | ||
.Description(FederationResources.Contact_Description) | ||
.Location(DirectiveLocation.Schema); | ||
} |