Skip to content

Commit 855aa82

Browse files
authored
more docs updates (#2755)
* more * more * more * more * more * more * more * more * polish * polish * rm * more * more * prettier * moreee
1 parent b2c97d6 commit 855aa82

File tree

6 files changed

+176
-180
lines changed

6 files changed

+176
-180
lines changed

website/app/_meta.global.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export default {
2929
type: 'page',
3030
items: {
3131
index: '',
32-
'getting-started': '',
33-
'parser-options': '',
3432
usage: {
3533
title: 'Usage',
3634
items: {
@@ -53,6 +51,7 @@ export default {
5351
prettier: '',
5452
},
5553
},
54+
'parser-options': '',
5655
_1: {
5756
type: 'separator',
5857
title: 'Users',

website/content/docs/configs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
| [`flat/operations-recommended`](https://github.com/B2o5T/graphql-eslint/tree/master/packages/plugin/src/configs/operations-recommended.ts) | enables recommended rules for consuming GraphQL (operations) development |
1616
| [`flat/operations-all`](https://github.com/B2o5T/graphql-eslint/tree/master/packages/plugin/src/configs/operations-all.ts) | enables all rules for consuming GraphQL (operations) development |
1717

18-
> [!WARNING]
18+
> [!TIP]
1919
>
2020
> If you are in a project that develops the GraphQL schema, you'll need `schema` rules.
2121
>

website/content/docs/getting-started.mdx

Lines changed: 0 additions & 174 deletions
This file was deleted.

website/content/docs/usage/index.mdx

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import PrettierIcon from '@icons/prettier.svg?svgr'
1111
import StackIcon from '@icons/stack.svg?svgr'
1212
import SvelteIcon from '@icons/svelte.svg?svgr'
1313
import VueIcon from '@icons/vue.svg?svgr'
14-
import { Cards, Steps } from '@theguild/components'
14+
import { Cards, Steps, Tabs } from '@theguild/components'
1515
import { createIndexPage, getPageMap, MDXRemote } from '@theguild/components/server'
1616

1717
# Usage
@@ -36,7 +36,12 @@ npm i -D @graphql-eslint/eslint-plugin
3636

3737
Create a new
3838
[configuration object](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects)
39-
in your `eslint.config.js` file to setup `@graphql-eslint` plugin.
39+
in your `eslint.config.js` file to apply this plugin to `.graphql` files and configure
40+
[the rules](/rules) you want to enforce.
41+
42+
> [!WARNING]
43+
>
44+
> This step is necessary even if you are declaring operations and/or schema in code files[^1].
4045
4146
```js filename="eslint.config.js"
4247
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
@@ -50,11 +55,140 @@ export default [
5055
},
5156
plugins: {
5257
'@graphql-eslint': graphqlPlugin
58+
},
59+
rules: {
60+
'@graphql-eslint/known-type-names': 'error'
61+
// ... other GraphQL-ESLint rules
62+
}
63+
}
64+
]
65+
```
66+
67+
### Lint GraphQL Definitions in Code Files <sup>_(Optional)_</sup>
68+
69+
If you're defining GraphQL schemas or operations directly within code files[^1], check out
70+
[the usage with `.js`/`.jsx`](./usage/js) files.
71+
72+
### Providing GraphQL Schema <sup>_(Optional)_</sup>
73+
74+
Some linting rules require access to the entire GraphQL schema. For example, the
75+
[no-unreachable-types](../rules/no-unreachable-types) rule checks that all types are reachable
76+
through root-level fields.
77+
78+
To enable these rules, you need to inform ESLint how to identify and load your complete schema.
79+
80+
The GraphQL ESLint plugin integrates seamlessly with
81+
[GraphQL Config](https://the-guild.dev/graphql/config) which it uses to automatically load your
82+
schema. GraphQL Config supports multiple ways to specify your schema, including `.json`
83+
(introspection) file, `.graphql` files, a URL endpoint, or a raw string.
84+
85+
> This integration uses [`graphql-tools`](https://the-guild.dev/graphql/tools) under the hood to
86+
> handle the schema loading.
87+
88+
Example of providing GraphQL schema:
89+
90+
<Tabs items={['GraphQL Config', 'Programmatic Usage']}>
91+
<Tabs.Tab>
92+
93+
```js filename="graphql.config.js"
94+
export default {
95+
schema: './schema.graphql'
96+
}
97+
```
98+
99+
</Tabs.Tab>
100+
101+
<Tabs.Tab>
102+
Alternatively, you can provide the schema directly within your ESLint configuration by specifying
103+
`languageOptions.parserOptions.graphQLConfig.schema`.
104+
105+
```diff filename="eslint.config.js"
106+
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
107+
108+
export default [
109+
// ... other config
110+
{
111+
files: ['**/*.graphql'],
112+
languageOptions: {
113+
parser: graphqlPlugin.parser,
114+
+ parserOptions: {
115+
+ graphQLConfig: {
116+
+ schema: './schema.graphql'
117+
+ }
118+
+ }
119+
},
120+
plugins: {
121+
'@graphql-eslint': graphqlPlugin
122+
},
123+
rules: {
124+
'@graphql-eslint/no-unreachable-types': 'error'
125+
}
126+
}
127+
]
128+
```
129+
130+
</Tabs.Tab>
131+
</Tabs>
132+
133+
### Providing GraphQL Operations <sup>_(Optional)_</sup>
134+
135+
While implementing this tool, we had to find solutions for a better integration of the GraphQL
136+
ecosystem and ESLint core.
137+
138+
GraphQL's operations can be distributed across many files, while ESLint operates on one file at a
139+
time. If you are using GraphQL fragments in separate files, some rules might yield incorrect
140+
results, due the missing information.
141+
142+
To workaround that, we allow you to provide additional information on your GraphQL operations,
143+
making it available for rules while doing the actual linting.
144+
145+
To provide that, we are using `graphql-tools` loaders to load your sibling operations and fragments,
146+
just specify a glob expression(s) that points to your code[^1] and/or `.graphql` files:
147+
148+
Example of providing GraphQL operations:
149+
150+
<Tabs items={['GraphQL Config', 'Programmatic Usage']}>
151+
<Tabs.Tab>
152+
```diff filename="graphql.config.js"
153+
export default {
154+
schema: './schema.graphql',
155+
+ documents: './src/**/*.graphql'
156+
}
157+
```
158+
</Tabs.Tab>
159+
160+
<Tabs.Tab>
161+
Alternatively, you can provide the documents directly within your ESLint configuration by specifying
162+
`languageOptions.parserOptions.graphQLConfig.documents`.
163+
164+
```diff filename="eslint.config.js"
165+
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
166+
167+
export default [
168+
// ... other config
169+
{
170+
files: ['**/*.graphql'],
171+
languageOptions: {
172+
parser: graphqlPlugin.parser,
173+
parserOptions: {
174+
graphQLConfig: {
175+
schema: './schema.graphql',
176+
+ documents: './src/**/*.graphql'
177+
}
178+
}
179+
},
180+
plugins: {
181+
'@graphql-eslint': graphqlPlugin
182+
},
183+
rules: {
184+
'@graphql-eslint/unique-operation-name': 'error'
53185
}
54186
}
55187
]
56188
```
57189

190+
</Tabs.Tab>
191+
</Tabs>
58192
</Steps>
59193

60194
## Usage
@@ -74,3 +208,5 @@ export default [
74208
PrettierIcon
75209
}}
76210
/>
211+
212+
[^1]: Code files (e.g., `.js`, `.jsx`, `.ts`, `.tsx` files)

0 commit comments

Comments
 (0)