Skip to content

Commit 7f8a49c

Browse files
authored
Merge pull request #1232 from Quramy/modify_doc
docs: Write about `enabledGlobalFragments`
2 parents 332d02b + a058f46 commit 7f8a49c

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

README.md

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![github actions](https://github.com/Quramy/ts-graphql-plugin/workflows/build/badge.svg)](https://github.com/Quramy/ts-graphql-plugin/actions)
44
[![codecov](https://codecov.io/gh/Quramy/ts-graphql-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/Quramy/ts-graphql-plugin)
55
[![npm version](https://badge.fury.io/js/ts-graphql-plugin.svg)](https://badge.fury.io/js/ts-graphql-plugin)
6-
![deps](https://david-dm.org/quramy/ts-graphql-plugin.svg)
76
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Quramy/ts-graphql-plugin/main/LICENSE.txt)
87

98
Provides functions to help TypeScript GraphQL client development including auto completion, query validation, type generation and so on.
@@ -50,6 +49,7 @@ This plugin has the following features:
5049
- [`documentTransformers` optional](#documenttransformers-optional)
5150
- [Template strings](#template-strings)
5251
- [Available editors](#available-editors)
52+
- [VSCode](#vscode)
5353
- [Contributing](#contributing)
5454
- [License](#license)
5555

@@ -270,7 +270,7 @@ For example:
270270
"plugins": [
271271
{
272272
"name": "ts-graphql-plugin",
273-
"tag": "gql",
273+
"tag": "gql"
274274
}
275275
]
276276
}
@@ -294,12 +294,13 @@ const str2 = `<div></div>`;
294294
const str3 = otherTagFn`foooo`;
295295
```
296296

297-
Sometimes you want to consider the arguments of a particular function calling as a GraphQL document, such as:
297+
Sometimes you want to consider the arguments of a particular function calling as a GraphQL document.
298+
For example, [graphql-codegen](https://the-guild.dev/graphql/codegen) and [octkit](https://github.com/octokit/graphql.js) use the `graphql` function as follows:
298299

299300
```ts
300-
import { graphql } from '@octokit/graphql';
301+
import { graphql } from './gql';
301302

302-
const { viewer } = await graphql(`
303+
const myQuery = graphql(`
303304
query MyQuery {
304305
viewer {
305306
name
@@ -320,7 +321,7 @@ Configure as the following:
320321
"name": "ts-graphql-plugin",
321322
"tag": {
322323
"name": "graphql",
323-
"ignoreFunctionCallExpression: false,
324+
"ignoreFunctionCallExpression": false
324325
}
325326
}
326327
]
@@ -350,16 +351,44 @@ It's useful if other code generator copies your GraphQL Template Strings.
350351
> [!NOTE]
351352
> Currently, the `exclude` option only accepts file or directory names. Wildcard characters such as `*` and `**` are not allowed.
352353

353-
<!--
354-
355354
### `enabledGlobalFragments`
356355

357356
It's optional and the default value is `false`. If enabled, the plugin automatically searches for and merges the dependent fragments for the target GraphQL operation in the TypeScript project.
358357

358+
```tsx
359+
/* Post.tsx */
360+
361+
import { graphql } from './gql';
362+
363+
const postFragment = graphql(`
364+
fragment PostFragment on Post {
365+
id
366+
name
367+
title
368+
}
369+
`);
370+
371+
/* App.tsx */
372+
373+
const appQuery = graphql(`
374+
query AppQuery {
375+
posts {
376+
id
377+
...PostFragment
378+
}
379+
}
380+
`);
381+
```
382+
383+
In the above example, note that `${postFragment}` is not in the `appQuery` template string literal.
384+
359385
> [!IMPORTANT]
360-
> Fragments must be given a unique name if this option is enabled.
386+
> This option does not depend on whether the query and fragment are combined at runtime.
387+
> Whether or not query and fragment are eventually combined depends on the build toolchain you are using.
388+
> For example, [graphql-codegen](https://the-guild.dev/graphql/codegen/docs/guides/react-vue#writing-graphql-fragments) and [Gatsby](https://www.gatsbyjs.com/docs/reference/graphql-data-layer/using-graphql-fragments/) have a mechanism for referencing global fragments.
361389

362-
-->
390+
> [!IMPORTANT]
391+
> Fragments must be given a unique name if this option is enabled.
363392

364393
### `localSchemaExtensions`
365394

@@ -671,7 +700,7 @@ Keep your queries static (see also https://blog.apollographql.com/5-benefits-of-
671700

672701
I've checked the operation with the following editors:
673702

674-
- Visual Studio Code
703+
- VSCode
675704
- Vim (with tsuquyomi)
676705

677706
And the following editor have TypeScript plugin with LanguageService so they're compatible with this plugin:
@@ -680,6 +709,19 @@ And the following editor have TypeScript plugin with LanguageService so they're
680709
- Sublime text
681710
- Eclipse
682711

712+
### VSCode
713+
714+
To use TypeScript Language Service Plugin within VSCode, confirm your VSCode uses [workspace version TypeScript](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript).
715+
716+
```js
717+
/* .vscode/setting.json */
718+
719+
{
720+
"typescript.tsdk": "node_modules/typescript/lib",
721+
"typescript.enablePromptUseWorkspaceTsdk": true
722+
}
723+
```
724+
683725
## Contributing
684726

685727
See [contribution guide](CONTRIBUTING.md).

0 commit comments

Comments
 (0)