-
Notifications
You must be signed in to change notification settings - Fork 1
Update dependency @graphql-eslint/eslint-plugin to v4 #217
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
base: main
Are you sure you want to change the base?
Changes from all commits
3204e2c
8cfac6b
798bbe1
4c798d7
bff80d2
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const schema = gql` | ||
| type Query { | ||
| user: UnknownUser | ||
| } | ||
| `; | ||
|
|
||
| const fragment = graphql` | ||
| fragment AuthorInfo on NonExistentAuthor { | ||
| id | ||
| name | ||
| } | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* eslint-disable no-unused-vars, no-undef */ | ||
|
|
||
| const query = gql` | ||
| query GetUser($id: ID!) { | ||
| user(id: $id) { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const mutation = graphql` | ||
| mutation CreateUser($name: String!) { | ||
| createUser(name: $name) { | ||
| id | ||
| } | ||
| } | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* eslint-disable no-unused-vars */ | ||
|
|
||
| import React from 'react'; | ||
| // eslint-disable-next-line import/no-unresolved | ||
| import { gql } from 'apollo-client'; | ||
|
|
||
| const UserQuery = gql` | ||
| query GetUser($id: ID!) { | ||
| user(id: $id) { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| export function UserProfile({ userId }: { userId: string }) { | ||
| return <div>User: {userId}</div>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| type Query { | ||
| user: UnknownType | ||
| } | ||
|
|
||
| type User { | ||
| id: ID | ||
| name: String | ||
| profile: NonExistentProfile | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| type Query { | ||
| user: User | ||
| } | ||
|
|
||
| type User { | ||
| id: ID | ||
| name: String | ||
| email: String | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import fs from 'node:fs'; | ||
| import { beforeEach, describe, it } from 'node:test'; | ||
|
|
||
| import { ESLint } from 'eslint'; | ||
|
|
||
| import config from '../index.js'; | ||
|
|
||
| describe('@alma-oss/eslint-config-graphql', () => { | ||
| describe('config structure', () => { | ||
| it('exports a flat config array', () => { | ||
| assert.ok(Array.isArray(config)); | ||
| }); | ||
|
|
||
| it('exports exactly 2 config entries', () => { | ||
| assert.equal(config.length, 2); | ||
| }); | ||
|
|
||
| it('first entry has correct name', () => { | ||
| assert.equal(config[0].name, '@alma-oss/eslint-config-graphql'); | ||
| }); | ||
|
|
||
| it('first entry registers the graphql-eslint processor', () => { | ||
| assert.ok(config[0].processor != null); | ||
| }); | ||
|
|
||
| it('second entry targets *.graphql files', () => { | ||
| assert.deepEqual(config[1].files, ['*.graphql']); | ||
| }); | ||
|
|
||
| it('second entry registers the @graphql-eslint plugin', () => { | ||
| assert.ok(config[1].plugins['@graphql-eslint'] != null); | ||
| }); | ||
|
|
||
| it('second entry enables known-type-names as error', () => { | ||
| assert.equal(config[1].rules['@graphql-eslint/known-type-names'], 'error'); | ||
| }); | ||
| }); | ||
|
literat marked this conversation as resolved.
|
||
|
|
||
| describe('valid GraphQL schema', () => { | ||
| const code = fs.readFileSync('./__tests__/__fixtures__/schema-valid.graphql', 'utf-8'); | ||
| let result; | ||
|
|
||
| beforeEach(async () => { | ||
| const overrideConfig = [ | ||
| config[0], | ||
| { | ||
| ...config[1], | ||
| languageOptions: { | ||
| ...config[1].languageOptions, | ||
| parserOptions: { | ||
| schemaSdl: code, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| const eslint = new ESLint({ | ||
| overrideConfigFile: true, | ||
| overrideConfig, | ||
| }); | ||
| const [lintResult] = await eslint.lintText(code, { filePath: 'schema-valid.graphql' }); | ||
| result = lintResult; | ||
| }); | ||
|
|
||
| it('flags no warnings', () => { | ||
| assert.equal(result.messages.length, 0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('invalid GraphQL schema (unknown type names)', () => { | ||
| const validCode = fs.readFileSync('./__tests__/__fixtures__/schema-valid.graphql', 'utf-8'); | ||
| const invalidCode = fs.readFileSync('./__tests__/__fixtures__/schema-invalid.graphql', 'utf-8'); | ||
| let result; | ||
|
|
||
| beforeEach(async () => { | ||
| const overrideConfig = [ | ||
| config[0], | ||
| { | ||
| ...config[1], | ||
| languageOptions: { | ||
| ...config[1].languageOptions, | ||
| parserOptions: { | ||
| // Use valid schema as the universe of known types | ||
| schemaSdl: validCode, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| const eslint = new ESLint({ | ||
| overrideConfigFile: true, | ||
| overrideConfig, | ||
| }); | ||
| // Lint the invalid schema against the valid schema's type universe | ||
| const [lintResult] = await eslint.lintText(invalidCode, { filePath: 'schema-invalid.graphql' }); | ||
| result = lintResult; | ||
| }); | ||
|
|
||
| it('flags warnings', () => { | ||
| assert.ok(result.messages.length > 0); | ||
| }); | ||
|
|
||
| it('flags the known-type-names rule', () => { | ||
| assert.ok(result.messages.some((m) => m.ruleId === '@graphql-eslint/known-type-names')); | ||
| }); | ||
|
|
||
| it('reports error severity', () => { | ||
| const errors = result.messages.filter((m) => m.ruleId === '@graphql-eslint/known-type-names'); | ||
| assert.ok(errors.every((m) => m.severity === 2)); | ||
| }); | ||
|
|
||
| it('flags exactly 2 unknown type references', () => { | ||
| const errors = result.messages.filter((m) => m.ruleId === '@graphql-eslint/known-type-names'); | ||
| assert.equal(errors.length, 2); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,21 +1,28 @@ | ||||||
| const globs = require('@lmc-eu/eslint-config-base/globs'); | ||||||
| import globs from '@alma-oss/eslint-config-base/globs'; | ||||||
| // eslint-disable-next-line import/no-unresolved | ||||||
| import graphqlPlugin from '@graphql-eslint/eslint-plugin'; | ||||||
|
|
||||||
| module.exports = { | ||||||
| overrides: [ | ||||||
| { | ||||||
| files: [...globs.configs, ...globs, globs.typescripts], | ||||||
| processor: '@graphql-eslint/graphql', | ||||||
| export default [ | ||||||
| { | ||||||
| name: '@alma-oss/eslint-config-graphql', | ||||||
| files: [...globs.configs, ...globs.javascripts, ...globs.typescripts], | ||||||
|
||||||
| files: [...globs.configs, ...globs.javascripts, ...globs.typescripts], | |
| files: [...globs.configs, ...globs.javascripts, ...globs.typescripts, '*.jsx'], |
Uh oh!
There was an error while loading. Please reload this page.