Skip to content

Commit 67cf306

Browse files
[Analyzer] Fix Source Generator Connection type collision (#9734)
1 parent cb3fd63 commit 67cf306

5 files changed

Lines changed: 272 additions & 1 deletion

File tree

src/HotChocolate/Core/src/Types/Types/Descriptors/TypeReferences/FactoryTypeReference.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,8 @@ public override bool Equals(TypeReference? other)
131131
}
132132

133133
public override int GetHashCode()
134-
=> HashCode.Combine(base.GetHashCode(), TypeStructure, TypeDefinition);
134+
=> HashCode.Combine(
135+
base.GetHashCode(),
136+
SyntaxComparer.BySyntax.GetHashCode(TypeStructure),
137+
TypeDefinition);
135138
}

src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/IntegrationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ public async Task Schema_Snapshot()
1818
.MatchSnapshotAsync();
1919
}
2020

21+
[Fact]
22+
public async Task Schema_Snapshot_Without_ConnectionName_Inference()
23+
{
24+
await new ServiceCollection()
25+
.AddGraphQLServer(disableDefaultSecurity: true)
26+
.AddIntegrationTestTypes()
27+
.AddGlobalObjectIdentification()
28+
.ModifyPagingOptions(o => o.InferConnectionNameFromField = false)
29+
.BuildSchemaAsync()
30+
.MatchSnapshotAsync();
31+
}
32+
2133
[Fact]
2234
public async Task Subscription_With_Subscribe_With_Delivers_Message_From_Stream()
2335
{

src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/Product.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public static IsSelectedNode GetIsSelectedTest([IsSelected("name")] bool isSelec
6060
public static Product GetProduct()
6161
=> new Book { Id = "1", Title = "GraphQL in Action" };
6262

63+
[UsePaging]
64+
public static IEnumerable<Book> GetBooks() => [];
65+
66+
[UsePaging]
67+
public static IEnumerable<Book> GetFavoriteBooks() => [];
68+
6369
[UsePaging]
6470
public static IEnumerable<int> GetInts(PagingArguments pagingArguments)
6571
{

src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/__snapshots__/IntegrationTests.Schema_Snapshot.snap

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,40 @@ type Query {
1313
The only product.
1414
"""
1515
product: Product!
16+
books(
17+
"Returns the first _n_ elements from the list."
18+
first: Int
19+
"Returns the elements in the list that come after the specified cursor."
20+
after: String
21+
"Returns the last _n_ elements from the list."
22+
last: Int
23+
"Returns the elements in the list that come before the specified cursor."
24+
before: String
25+
): BooksConnection
26+
@listSize(
27+
assumedSize: 50
28+
slicingArguments: ["first", "last"]
29+
slicingArgumentDefaultValue: 10
30+
sizedFields: ["edges", "nodes"]
31+
requireOneSlicingArgument: false
32+
)
33+
favoriteBooks(
34+
"Returns the first _n_ elements from the list."
35+
first: Int
36+
"Returns the elements in the list that come after the specified cursor."
37+
after: String
38+
"Returns the last _n_ elements from the list."
39+
last: Int
40+
"Returns the elements in the list that come before the specified cursor."
41+
before: String
42+
): FavoriteBooksConnection
43+
@listSize(
44+
assumedSize: 50
45+
slicingArguments: ["first", "last"]
46+
slicingArgumentDefaultValue: 10
47+
sizedFields: ["edges", "nodes"]
48+
requireOneSlicingArgument: false
49+
)
1650
ints(
1751
"Returns the first _n_ elements from the list."
1852
first: Int
@@ -72,6 +106,42 @@ type Book implements Product {
72106
kind: String!
73107
}
74108

109+
"A connection to a list of items."
110+
type BooksConnection {
111+
"Information to aid in pagination."
112+
pageInfo: PageInfo!
113+
"A list of edges."
114+
edges: [BooksEdge!]
115+
"A flattened list of the nodes."
116+
nodes: [Book!]
117+
}
118+
119+
"An edge in a connection."
120+
type BooksEdge {
121+
"A cursor for use in pagination."
122+
cursor: String!
123+
"The item at the end of the edge."
124+
node: Book!
125+
}
126+
127+
"A connection to a list of items."
128+
type FavoriteBooksConnection {
129+
"Information to aid in pagination."
130+
pageInfo: PageInfo!
131+
"A list of edges."
132+
edges: [FavoriteBooksEdge!]
133+
"A flattened list of the nodes."
134+
nodes: [Book!]
135+
}
136+
137+
"An edge in a connection."
138+
type FavoriteBooksEdge {
139+
"A cursor for use in pagination."
140+
cursor: String!
141+
"The item at the end of the edge."
142+
node: Book!
143+
}
144+
75145
"A connection to a list of items."
76146
type IntsConnection {
77147
"Information to aid in pagination."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
schema {
2+
query: Query
3+
subscription: Subscription
4+
}
5+
6+
type Query {
7+
"Fetches an object given its ID."
8+
node("ID of the object." id: ID!): Node
9+
"Lookup nodes by a list of IDs."
10+
nodes("The list of node IDs." ids: [ID!]!): [Node]!
11+
isSelectedTest: IsSelectedNode!
12+
"""
13+
Gets the product.
14+
15+
16+
**Returns:**
17+
The only product.
18+
"""
19+
product: Product!
20+
books(
21+
"Returns the first _n_ elements from the list."
22+
first: Int
23+
"Returns the elements in the list that come after the specified cursor."
24+
after: String
25+
"Returns the last _n_ elements from the list."
26+
last: Int
27+
"Returns the elements in the list that come before the specified cursor."
28+
before: String
29+
): BookConnection
30+
favoriteBooks(
31+
"Returns the first _n_ elements from the list."
32+
first: Int
33+
"Returns the elements in the list that come after the specified cursor."
34+
after: String
35+
"Returns the last _n_ elements from the list."
36+
last: Int
37+
"Returns the elements in the list that come before the specified cursor."
38+
before: String
39+
): BookConnection
40+
ints(
41+
"Returns the first _n_ elements from the list."
42+
first: Int
43+
"Returns the elements in the list that come after the specified cursor."
44+
after: String
45+
"Returns the last _n_ elements from the list."
46+
last: Int
47+
"Returns the elements in the list that come before the specified cursor."
48+
before: String
49+
): IntConnection
50+
products(
51+
"Returns the elements in the list that come after the specified cursor."
52+
after: Version2
53+
"Returns the first _n_ elements from the list."
54+
first: Int
55+
"Returns the last _n_ elements from the list."
56+
last: Int
57+
"Returns the elements in the list that come before the specified cursor."
58+
before: String
59+
): ProductConnection
60+
argumentWithExplicitType(arg: Version2): String!
61+
nullableArgumentWithExplicitType(arg: Version2): String!
62+
nullableArrayArgumentRef(items: [String!]): String!
63+
arrayArgumentRef(items: [String!]!): String!
64+
arrayNullableElementArgumentRef(items: [String]!): String!
65+
nullableArrayNullableElementArgumentRef(items: [String]): String!
66+
nullableListArgumentRef(items: [String!]): String!
67+
listArgumentRef(items: [String!]!): String!
68+
listNullableElementArgumentRef(items: [String]!): String!
69+
nullableListNullableElementArgumentRef(items: [String]): String!
70+
issue8057Entity(id: ID!): Issue8057Entity
71+
}
72+
73+
type Subscription {
74+
onProductAdded(categoryId: Int!): Int!
75+
onProductPriceChanged(productId: Int!): Int!
76+
}
77+
78+
type Book implements Product {
79+
title: String!
80+
id: String!
81+
kind: String!
82+
}
83+
84+
"A connection to a list of items."
85+
type BookConnection {
86+
"Information to aid in pagination."
87+
pageInfo: PageInfo!
88+
"A list of edges."
89+
edges: [BookEdge!]
90+
"A flattened list of the nodes."
91+
nodes: [Book!]
92+
}
93+
94+
"An edge in a connection."
95+
type BookEdge {
96+
"A cursor for use in pagination."
97+
cursor: String!
98+
"The item at the end of the edge."
99+
node: Book!
100+
}
101+
102+
"A connection to a list of items."
103+
type IntConnection {
104+
"Information to aid in pagination."
105+
pageInfo: PageInfo!
106+
"A list of edges."
107+
edges: [IntEdge!]
108+
"A flattened list of the nodes."
109+
nodes: [Int!]
110+
}
111+
112+
"An edge in a connection."
113+
type IntEdge {
114+
"A cursor for use in pagination."
115+
cursor: String!
116+
"The item at the end of the edge."
117+
node: Int!
118+
}
119+
120+
type IsSelectedNode implements Node {
121+
id: ID!
122+
name: String!
123+
description: String!
124+
wasNameSelected: Boolean!
125+
}
126+
127+
type Issue8057Entity implements Node {
128+
id: ID!
129+
}
130+
131+
"Information about pagination in a connection."
132+
type PageInfo {
133+
"Indicates whether more edges exist following the set defined by the clients arguments."
134+
hasNextPage: Boolean!
135+
"Indicates whether more edges exist prior the set defined by the clients arguments."
136+
hasPreviousPage: Boolean!
137+
"When paginating backwards, the cursor to continue."
138+
startCursor: String
139+
"When paginating forwards, the cursor to continue."
140+
endCursor: String
141+
}
142+
143+
"A connection to a list of items."
144+
type ProductConnection {
145+
"Information to aid in pagination."
146+
pageInfo: PageInfo!
147+
"A list of edges."
148+
edges: [ProductEdge!]
149+
"A flattened list of the nodes."
150+
nodes: [Product!]
151+
}
152+
153+
"An edge in a connection."
154+
type ProductEdge {
155+
"A cursor for use in pagination."
156+
cursor: String!
157+
"The item at the end of the edge."
158+
node: Product!
159+
}
160+
161+
type Television implements Product {
162+
argumentWithExplicitType(arg: Version!): String!
163+
nullableArgumentWithExplicitType(arg: Version): String!
164+
id: String!
165+
kind: String!
166+
}
167+
168+
"The node interface is implemented by entities that have a global unique identifier."
169+
interface Node {
170+
id: ID!
171+
}
172+
173+
interface Product {
174+
kind: String!
175+
id: String!
176+
}
177+
178+
scalar Version
179+
180+
scalar Version2

0 commit comments

Comments
 (0)