-
-
Notifications
You must be signed in to change notification settings - Fork 53
fix: update visitor logic in topologicalSortAST
to fix Issue #528
#958
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,34 @@ describe('topologicalSortAST', () => { | |
expect(sortedSchema).toBe(expectedSortedSchema); | ||
}); | ||
|
||
it('should place interface definitions before types that depend on them', () => { | ||
const schema = /* GraphQL */ ` | ||
type A { | ||
id: ID! | ||
node: Node | ||
} | ||
|
||
interface Node { | ||
id: ID! | ||
} | ||
`; | ||
|
||
const sortedSchema = getSortedSchema(schema); | ||
|
||
const expectedSortedSchema = dedent/* GraphQL */` | ||
interface Node { | ||
id: ID! | ||
} | ||
|
||
type A { | ||
id: ID! | ||
node: Node | ||
} | ||
`; | ||
|
||
expect(sortedSchema).toBe(expectedSortedSchema); | ||
}); | ||
|
||
it('should correctly handle schema with circular dependencies', () => { | ||
const schema = /* GraphQL */ ` | ||
input A { | ||
|
@@ -235,13 +263,13 @@ describe('topologicalSortAST', () => { | |
const sortedSchema = getSortedSchema(schema); | ||
|
||
const expectedSortedSchema = dedent/* GraphQL */` | ||
input A { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do I need to change this test case? I expect this test case to pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The relevant code change is in the The reason for the change is that, in order to ensure that every node is visited, we need to iterate over all nodes in the graph. In the presence of cycles, some nodes may not be considered sinks (i.e., they have no outgoing edges), and therefore would be skipped in a traditional topological sort. This is precisely what was happening in this test case with the old implementation — it's why The new
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your explanation! |
||
a: A | ||
} | ||
|
||
input B { | ||
b: B | ||
} | ||
|
||
input A { | ||
a: A | ||
} | ||
`; | ||
|
||
expect(sortedSchema).toBe(expectedSortedSchema); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new case, so please add a test to confirm that the interface is also sorted