Skip to content

Commit e771499

Browse files
docs: Add Vue usage instructions (#2598)
* add new docs * more * more * add * more * more * more * more * more * fix generate docs prettier, incorrectly formatted _meta.ts * add baseUrl * update eslint patch * fix snapshots * fix lint * move * more * more * more * more * more * prettier * more * more * more * prettier * more * prettier * more * more * more * prettier * fix for generate-configs * test legacy configs examples * more * more * prettier * more * more * more * run tests for examples with legacy configs * lint * Add Vue usage instructions * prettier * 1. graphql plugin can now we specified with ```js plugins: { '@graphql-eslint': graphqlPlugin }, ``` 2. config rules now should be specified with accessing `rules` property ```diff rules: { - ...graphqlESLint.configs['flat/operations-recommended'] + ...graphqlESLint.configs['flat/operations-recommended'].rules ``` 3. processor can now be specified with accessing `processor` property ```js processor: graphqlPlugin.processor ``` 4. plugin can now be imported with default import ```js import graphqlPlugin from '@graphql-eslint/eslint-plugin' ``` * improve * fix indent --------- Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
1 parent 055372d commit e771499

File tree

7 files changed

+107
-8
lines changed

7 files changed

+107
-8
lines changed

Diff for: .changeset/chilled-rivers-prove.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': major
3+
---
4+
5+
1. graphql plugin can now we be specified as
6+
7+
```js
8+
plugins: { '@graphql-eslint': graphqlPlugin }
9+
```
10+
11+
1. Config rules should now be accessed through the `rules` property
12+
13+
```diff
14+
rules: {
15+
- ...graphqlESLint.configs['flat/operations-recommended']
16+
+ ...graphqlESLint.configs['flat/operations-recommended'].rules
17+
```
18+
19+
1. processor can now be specified with accessing `processor` property
20+
21+
```js
22+
processor: graphqlPlugin.processor
23+
```
24+
25+
1. The plugin can now be imported using a default import
26+
27+
```js
28+
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
29+
```

Diff for: .changeset/healthy-moose-kneel.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
2-
"@graphql-eslint/eslint-plugin": patch
2+
'@graphql-eslint/eslint-plugin': patch
33
---
44

5-
The import attribute syntax (with { type: "json" }) is still experimental so warnings showed up when using the library as it was being used to import the package.json file to extract the package version
5+
The import attribute syntax (with { type: "json" }) is still experimental so warnings showed up when
6+
using the library as it was being used to import the package.json file to extract the package
7+
version
68

79
As an alternative, the current version will be injected on build time through tsup configuration.

Diff for: packages/plugin/src/meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version = process.env.VERSION
1+
export const version = process.env.VERSION;

Diff for: website/src/pages/docs/getting-started.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ If you are using [`graphql-config`](https://the-guild.dev/graphql/config), you a
7676
Alternatively, you can define `parserOptions.schema` in the `*.graphql` override in your ESLint
7777
config.
7878

79-
The parser allows you to specify a `.json` file / `.graphql` files(s) / url / raw string to locate your
80-
schema (We are using `graphql-tools` to do that). Just add `parserOptions.schema` to your
79+
The parser allows you to specify a `.json` file / `.graphql` files(s) / url / raw string to locate
80+
your schema (We are using `graphql-tools` to do that). Just add `parserOptions.schema` to your
8181
configuration file:
8282

8383
```diff filename=".eslintrc.json"

Diff for: website/src/pages/docs/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project integrates GraphQL and ESLint, for a better developer experience.
1111
<source src="/demo.mp4" type="video/mp4" />
1212
</video>
1313

14-
<p className="mt-3 text-center italic text-sm">Demo GraphQL-ESLint in VSCode</p>
14+
<p className="mt-3 text-center text-sm italic">Demo GraphQL-ESLint in VSCode</p>
1515

1616
## Features
1717

Diff for: website/src/pages/docs/parser.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ title: How Does a Parser Work?
77
The `graphql-eslint` parser is works in the following way:
88

99
1. Loads all relevant GraphQL code using ESLint core (either from `.graphql` files, or using
10-
[ESLint `processor`](https://eslint.org/docs/latest/extend/plugins#processors-in-plugins)
11-
to find in code-files).
10+
[ESLint `processor`](https://eslint.org/docs/latest/extend/plugins#processors-in-plugins) to find
11+
in code-files).
1212
1. Is uses `graphql-js` (and `graphql-tools`) to parse the found string into a `DocumentNode`.
1313
1. Extracts all comments (marked as `# ...`) from the parsed AST, and provides to ESLint as
1414
directives hints.

Diff for: website/src/pages/docs/usage/vue.mdx

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

0 commit comments

Comments
 (0)