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

Added '@' prefix when exporting directives in Apollo. #7812

Merged
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 @@ -294,7 +294,7 @@ private void RegisterExportedDirectives()
var typeReference = _typeInspector.GetTypeRef(exportedDirective);
if (_typeRegistry.TryGetType(typeReference, out var exportedDirectiveType))
{
composeDirectives.Add(new ComposeDirective(exportedDirectiveType.Type.Name));
composeDirectives.Add(new ComposeDirective($"@{exportedDirectiveType.Type.Name}"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace HotChocolate.ApolloFederation;
public class ComposeDirectiveTests
{
[Fact]
public async Task TestServiceTypeEmptyQueryTypePureCodeFirst()
public async Task ExportDirectiveUsingTypeCodeFirst()
{
// arrange
var schema = await new ServiceCollection()
Expand All @@ -32,6 +32,29 @@ public async Task TestServiceTypeEmptyQueryTypePureCodeFirst()
.MatchSnapshot();
}

[Fact]
public async Task ExportDirectiveUsingNameCodeFirst()
{
// arrange
var schema = await new ServiceCollection()
.AddGraphQL()
.AddApolloFederation()
.AddQueryType()
.AddType<Address>()
.ExportDirective("@custom")
.BuildSchemaAsync();

var entityType = schema.GetType<ObjectType>(FederationTypeNames.ServiceType_Name);
var sdlResolver = entityType.Fields[WellKnownFieldNames.Sdl].Resolver!;

// act
var value = await sdlResolver(TestHelper.CreateResolverContext(schema));

Utf8GraphQLParser
.Parse((string)value!)
.MatchSnapshot();
}

[Key("field")]
public class Address
{
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", "@tag", "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
@@ -0,0 +1,37 @@
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
}

type Address @key(fields: "field") {
field: String! @custom
}

type Query {
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}

"This type provides a field named sdl: String! which exposes the SDL of the service's schema. This SDL (schema definition language) is a printed version of the service's schema including the annotations of federation directives. This SDL does not include the additions of the federation spec."
type _Service {
sdl: String!
}

"Union of all types that key directive applied. This information is needed by the Apollo federation gateway."
union _Entity = Address

"Marks underlying custom directive to be included in the Supergraph schema."
directive @composeDirective(name: String!) repeatable on SCHEMA

directive @custom on FIELD_DEFINITION

"Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface."
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE

"Links definitions within the document to external schemas."
directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA

"Scalar representing a set of fields."
scalar FieldSet

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Loading