Skip to content

Commit 3d5716c

Browse files
danielreynolds1michaelstaib
authored andcommitted
Added '@' prefix when exporting directives in Apollo. (#7812)
1 parent a570145 commit 3d5716c

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationTypeInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private void RegisterExportedDirectives()
294294
var typeReference = _typeInspector.GetTypeRef(exportedDirective);
295295
if (_typeRegistry.TryGetType(typeReference, out var exportedDirectiveType))
296296
{
297-
composeDirectives.Add(new ComposeDirective(exportedDirectiveType.Type.Name));
297+
composeDirectives.Add(new ComposeDirective($"@{exportedDirectiveType.Type.Name}"));
298298
}
299299
}
300300

src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/Directives/ComposeDirectiveTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace HotChocolate.ApolloFederation;
1111
public class ComposeDirectiveTests
1212
{
1313
[Fact]
14-
public async Task TestServiceTypeEmptyQueryTypePureCodeFirst()
14+
public async Task ExportDirectiveUsingTypeCodeFirst()
1515
{
1616
// arrange
1717
var schema = await new ServiceCollection()
@@ -33,6 +33,29 @@ public async Task TestServiceTypeEmptyQueryTypePureCodeFirst()
3333
.MatchSnapshot();
3434
}
3535

36+
[Fact]
37+
public async Task ExportDirectiveUsingNameCodeFirst()
38+
{
39+
// arrange
40+
var schema = await new ServiceCollection()
41+
.AddGraphQL()
42+
.AddApolloFederation()
43+
.AddQueryType()
44+
.AddType<Address>()
45+
.ExportDirective("@custom")
46+
.BuildSchemaAsync();
47+
48+
var entityType = schema.GetType<ObjectType>(FederationTypeNames.ServiceType_Name);
49+
var sdlResolver = entityType.Fields[WellKnownFieldNames.Sdl].Resolver!;
50+
51+
// act
52+
var value = await sdlResolver(TestHelper.CreateResolverContext(schema));
53+
54+
Utf8GraphQLParser
55+
.Parse((string)value!)
56+
.MatchSnapshot();
57+
}
58+
3659
[Key("field")]
3760
public class Address
3861
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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" ]) {
1+
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" ]) {
22
query: Query
33
}
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
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" ]) {
2+
query: Query
3+
}
4+
5+
type Address @key(fields: "field") {
6+
field: String! @custom
7+
}
8+
9+
type Query {
10+
_service: _Service!
11+
_entities(representations: [_Any!]!): [_Entity]!
12+
}
13+
14+
"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."
15+
type _Service {
16+
sdl: String!
17+
}
18+
19+
"Union of all types that key directive applied. This information is needed by the Apollo federation gateway."
20+
union _Entity = Address
21+
22+
"Marks underlying custom directive to be included in the Supergraph schema."
23+
directive @composeDirective(name: String!) repeatable on SCHEMA
24+
25+
directive @custom on FIELD_DEFINITION
26+
27+
"Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface."
28+
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
29+
30+
"Links definitions within the document to external schemas."
31+
directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA
32+
33+
"Scalar representing a set of fields."
34+
scalar FieldSet
35+
36+
"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."
37+
scalar _Any

0 commit comments

Comments
 (0)