@@ -5,72 +5,4 @@ icon: VueIcon
5
5
6
6
# Usage with ` .vue ` files
7
7
8
- <OfficialExampleCallout gitFolder = " vue-code-file" />
9
-
10
- ` graphql-eslint ` can lint GraphQL documents inside Vue Single-File Components (` .vue ` files). It
11
- does this in two steps: (1) extract the GraphQL documents from the Vue (or ` .js ` /` .ts ` ) file, and
12
- (2) lint the extracted GraphQL documents.
13
-
14
- If you don't embed GraphQL documents in your Vue files, you can skip this page.
15
-
16
- > [ !WARNING]
17
- >
18
- > Due to
19
- > [ a limitation in ` graphql-tag-pluck ` ] ( https://github.com/dimaMachina/graphql-eslint/issues/2103 ) ,
20
- > lint violations will show up at the top of the Vue document, on the first character, not inline.
21
-
22
- ## Configuration
23
-
24
- Add the following configuration to your ` eslint.config.js ` file to setup ` @graphql-eslint ` plugin.
25
- The intermediate graphql files always have the ` .graphql ` extension. Make sure the second block
26
- matches those files, even if you use another extension for your project's GraphQL (e.g. ` .gql ` ).
27
-
28
- > [ !WARNING]
29
- >
30
- > Make sure the first section, which extracts GraphQL from Vue files, comes ** before** any other Vue
31
- > rules. Otherwise, eslint may incorrectly rewrite all error messages to say only "clear".
32
-
33
- ``` js filename="eslint.config.js"
34
- import graphqlPlugin from ' @graphql-eslint/eslint-plugin'
35
-
36
- export default [
37
- {
38
- // NOTE: Order matters! This has to happen FIRST, before any block that
39
- // includes the Vue parser (including e.g. recommended Vue ESLint rules).
40
- // It also has to be before the .graphql block, below
41
- //
42
- // Extract GraphQL from files for linting -- this creates .graphql files
43
- // that are then linted below
44
- //
45
- // graphql-eslint scans all files (using the processor listed) and outputs
46
- // an intermediate file with the extracted GraphQL. That intermediate file
47
- // is then linted, generating the errors we see. The intermediate file has
48
- // a fixed .graphql extension, so you need to include that extension below
49
- // or these files won't be linted.
50
- files: [' **/*.js' , ' **/*.ts' , ' **/*.vue' ],
51
- processor: graphqlPlugin .processor
52
- // NOTE: While you CAN put rules here to affect JS/TS/Vue files, those
53
- // rules won't affect GraphQL. To modify rules that effect GraphQL inside
54
- // these files, add those to the block for .graphql files, below.
55
- },
56
- // ...other config
57
- {
58
- // Lint all GraphQL files, including the intermediate ones above. If you
59
- // want to tune the rules that appear in your files, even Vue/JS/TS files,
60
- // put those rule changes HERE
61
- files: [' **/*.graphql' ], // Add .gql extension if you use that
62
- languageOptions: {
63
- parser: graphqlPlugin .parser
64
- },
65
-
66
- // Any rule overrides for GraphQL go HERE. For example, to enable
67
- // recommended operations rules
68
- plugins: { ' @graphql-eslint' : graphqlPlugin },
69
- rules: {
70
- ... graphqlESLint .configs [' flat/operations-recommended' ].rules
71
- // Can also override the recommended rules here, e.g.:
72
- // "@graphql-eslint/naming-convention": ["off"],
73
- }
74
- }
75
- ]
76
- ```
8
+ <ESLintConfigs gitFolder = " vue-code-file" />
0 commit comments