Skip to content

Commit

Permalink
add test for known-fragment-names rule with import nested fragments…
Browse files Browse the repository at this point in the history
… + update `graphql-tools/import` package (#665)

* add failing test false positive case for `known-fragment-names` rule

* chore: update deps
  • Loading branch information
Dimitri POSTOLOV committed Nov 12, 2021
1 parent 70136fd commit 1914d6a
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 327 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-dolphins-brush.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

fix false positive case in `known-fragment-names` when import nested fragment
2 changes: 1 addition & 1 deletion examples/basic/package.json
Expand Up @@ -13,6 +13,6 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.4.1",
"eslint": "8.1.0"
"eslint": "8.2.0"
}
}
2 changes: 1 addition & 1 deletion examples/code-file/package.json
Expand Up @@ -13,6 +13,6 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.4.1",
"eslint": "8.1.0"
"eslint": "8.2.0"
}
}
4 changes: 2 additions & 2 deletions examples/graphql-config-code-file/package.json
Expand Up @@ -10,10 +10,10 @@
},
"dependencies": {
"graphql": "16.0.1",
"graphql-tag": "^2.12.5"
"graphql-tag": "2.12.6"
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.4.1",
"eslint": "8.1.0"
"eslint": "8.2.0"
}
}
2 changes: 1 addition & 1 deletion examples/graphql-config/package.json
Expand Up @@ -13,6 +13,6 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.4.1",
"eslint": "8.1.0"
"eslint": "8.2.0"
}
}
2 changes: 1 addition & 1 deletion examples/prettier/package.json
Expand Up @@ -13,7 +13,7 @@
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "2.4.1",
"eslint": "8.1.0",
"eslint": "8.2.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"prettier": "2.4.1"
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin/package.json
Expand Up @@ -27,13 +27,13 @@
},
"dependencies": {
"@babel/code-frame": "7.16.0",
"@graphql-tools/code-file-loader": "^7.0.2",
"@graphql-tools/graphql-tag-pluck": "^7.0.2",
"@graphql-tools/import": "^6.3.1",
"@graphql-tools/utils": "^8.0.2",
"graphql-config": "^4.0.1",
"@graphql-tools/code-file-loader": "7.2.2",
"@graphql-tools/graphql-tag-pluck": "7.1.3",
"@graphql-tools/import": "6.6.1",
"@graphql-tools/utils": "8.5.3",
"graphql-config": "4.1.0",
"graphql-depth-limit": "1.1.0",
"lodash.lowercase": "^4.3.0"
"lodash.lowercase": "4.3.0"
},
"devDependencies": {
"@types/babel__code-frame": "7.0.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin/tests/known-fragment-names.spec.ts
@@ -1,10 +1,9 @@
import { join } from 'path';
import { GraphQLRuleTester } from '../src';
import { GRAPHQL_JS_VALIDATIONS } from '../src/rules/graphql-js-validation';
import { GraphQLRuleTester, rules } from '../src';

const ruleTester = new GraphQLRuleTester();

ruleTester.runGraphQLTests('known-fragment-names', GRAPHQL_JS_VALIDATIONS['known-fragment-names'], {
ruleTester.runGraphQLTests('known-fragment-names', rules['known-fragment-names'], {
valid: [
{
filename: join(__dirname, 'mocks/user.graphql'),
Expand Down
24 changes: 24 additions & 0 deletions packages/plugin/tests/mocks/user-fields-with-nested-fragment.gql
@@ -0,0 +1,24 @@
fragment UserFields on User {
...AnotherUserFields
posts {
...PostFields
}
}

fragment AnotherUserFields on User {
firstName
}

fragment PostFields on Post {
id
...AnotherPostFields
}

fragment AnotherPostFields on Post {
title
...YetAnotherPostFields
}

fragment YetAnotherPostFields on Post {
content
}
2 changes: 1 addition & 1 deletion packages/plugin/tests/mocks/user.graphql
@@ -1,4 +1,4 @@
#import "./user-fields.graphql"
#import './user-fields-with-nested-fragment.gql'

query User {
user {
Expand Down
9 changes: 6 additions & 3 deletions packages/plugin/tests/no-unused-fragments.spec.ts
Expand Up @@ -7,11 +7,14 @@ const ruleTester = new GraphQLRuleTester();
ruleTester.runGraphQLTests('no-unused-fragments', GRAPHQL_JS_VALIDATIONS['no-unused-fragments'], {
valid: [
{
filename: join(__dirname, 'mocks/user-fields.graphql'),
code: ruleTester.fromMockFile('user-fields.graphql'),
filename: join(__dirname, 'mocks/user-fields-with-nested-fragment.gql'),
code: ruleTester.fromMockFile('user-fields-with-nested-fragment.gql'),
parserOptions: {
schema: join(__dirname, 'mocks/user-schema.graphql'),
operations: [join(__dirname, 'mocks/user-fields.graphql'), join(__dirname, 'mocks/user.graphql')],
operations: [
join(__dirname, 'mocks/user-fields-with-nested-fragment.gql'),
join(__dirname, 'mocks/user.graphql'),
],
},
},
{
Expand Down

0 comments on commit 1914d6a

Please sign in to comment.