Skip to content

Commit 9c6989c

Browse files
authored
Support type extensions with unreachable types policy rule (#7978)
1 parent c46b2f2 commit 9c6989c

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

.changeset/famous-paws-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Add schema linting support for type extensions

packages/services/policy/__tests__/policy.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ describe('policy checks', () => {
210210
);
211211
});
212212

213+
it('should support type extensions', async () => {
214+
const result = await schemaPolicyApiRouter
215+
.createCaller({ req: { log: console } as any })
216+
.checkPolicy({
217+
source: `type Query extend type Query { foo: Foo } type Foo { id: ID! }`,
218+
schema: `type Query extend type Query { foo: Foo } type Foo { id: ID! }`,
219+
target: '1',
220+
policy: {
221+
'no-unreachable-types': [2],
222+
},
223+
});
224+
expect(result).toHaveLength(0);
225+
});
226+
213227
/** To ensure existing policies dont break during upgrades */
214228
it.each(policies)('should support existing policies', async policy => {
215229
await expect(

patches/@graphql-eslint__eslint-plugin@3.20.1.patch

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,40 @@ index d952cee1e10976459e7c5836b86ba6540c45fdb6..d314997bfd26477c7d823cad397eb5d6
120120
return {
121121
[ruleId]: {
122122
meta: {
123+
diff --git a/esm/rules/no-unreachable-types.js b/esm/rules/no-unreachable-types.js
124+
index 17e9394c80ebb2257ec6145421fafa227872d0ca..f39ad76d7948ccc4e35f6b7d4adb26dee9e4a71b 100644
125+
--- a/esm/rules/no-unreachable-types.js
126+
+++ b/esm/rules/no-unreachable-types.js
127+
@@ -51,8 +51,15 @@ function getReachableTypes(schema) {
128+
for (const { astNode } of [...objects, ...interfaces]) {
129+
visit(astNode, visitor);
130+
}
131+
- } else if (type == null ? void 0 : type.astNode) {
132+
- visit(type.astNode, visitor);
133+
+ } else {
134+
+ if (type == null ? void 0 : type.astNode) {
135+
+ visit(type.astNode, visitor);
136+
+ }
137+
+ if (type == null ? void 0 : type.extensionASTNodes) {
138+
+ for (const ext of type.extensionASTNodes) {
139+
+ visit(ext, visitor);
140+
+ }
141+
+ }
142+
}
143+
};
144+
const visitor = {
145+
@@ -74,6 +81,11 @@ function getReachableTypes(schema) {
146+
if (type == null ? void 0 : type.astNode) {
147+
visit(type.astNode, visitor);
148+
}
149+
+ if (type == null ? void 0 : type.extensionASTNodes) {
150+
+ for (const ext of type.extensionASTNodes) {
151+
+ visit(ext, visitor);
152+
+ }
153+
+ }
154+
}
155+
for (const node of schema.getDirectives()) {
156+
if (node.locations.some((location) => RequestDirectiveLocations.has(location))) {
123157
diff --git a/esm/rules/relay-edge-types.js b/esm/rules/relay-edge-types.js
124158
index 7a7eb179786103d9d72a4a84fb4bf811d11a4286..6fb12a5f56b71f56c9a14018d0494e9c7584f935 100644
125159
--- a/esm/rules/relay-edge-types.js

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)