3
3
[ ![ github actions] ( https://github.com/Quramy/ts-graphql-plugin/workflows/build/badge.svg )] ( https://github.com/Quramy/ts-graphql-plugin/actions )
4
4
[ ![ codecov] ( https://codecov.io/gh/Quramy/ts-graphql-plugin/branch/main/graph/badge.svg )] ( https://codecov.io/gh/Quramy/ts-graphql-plugin )
5
5
[ ![ 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 )
7
6
[ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( https://raw.githubusercontent.com/Quramy/ts-graphql-plugin/main/LICENSE.txt )
8
7
9
8
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:
50
49
- [ ` documentTransformers ` optional] ( #documenttransformers-optional )
51
50
- [ Template strings] ( #template-strings )
52
51
- [ Available editors] ( #available-editors )
52
+ - [ VSCode] ( #vscode )
53
53
- [ Contributing] ( #contributing )
54
54
- [ License] ( #license )
55
55
@@ -270,7 +270,7 @@ For example:
270
270
"plugins" : [
271
271
{
272
272
"name" : "ts-graphql-plugin" ,
273
- "tag" : "gql" ,
273
+ "tag" : "gql"
274
274
}
275
275
]
276
276
}
@@ -294,12 +294,13 @@ const str2 = `<div></div>`;
294
294
const str3 = otherTagFn `foooo `;
295
295
```
296
296
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 :
298
299
299
300
```ts
300
- import { graphql } from '@octokit / graphql ';
301
+ import { graphql } from './ gql ';
301
302
302
- const { viewer } = await graphql (`
303
+ const myQuery = graphql (`
303
304
query MyQuery {
304
305
viewer {
305
306
name
@@ -320,7 +321,7 @@ Configure as the following:
320
321
"name" : "ts-graphql-plugin" ,
321
322
"tag" : {
322
323
"name" : "graphql" ,
323
- "ignoreFunctionCallExpression: false,
324
+ "ignoreFunctionCallExpression" : false
324
325
}
325
326
}
326
327
]
@@ -350,16 +351,44 @@ It's useful if other code generator copies your GraphQL Template Strings.
350
351
> [!NOTE ]
351
352
> Currently , the `exclude ` option only accepts file or directory names . Wildcard characters such as `*` and `**` are not allowed .
352
353
353
- <!--
354
-
355
354
### `enabledGlobalFragments`
356
355
357
356
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 .
358
357
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
+
359
385
> [!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.
361
389
362
- -->
390
+ > [!IMPORTANT ]
391
+ > Fragments must be given a unique name if this option is enabled .
363
392
364
393
### `localSchemaExtensions`
365
394
@@ -671,7 +700,7 @@ Keep your queries static (see also https://blog.apollographql.com/5-benefits-of-
671
700
672
701
I 've checked the operation with the following editors :
673
702
674
- - Visual Studio Code
703
+ - VSCode
675
704
- Vim (with tsuquyomi)
676
705
677
706
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
680
709
- Sublime text
681
710
- Eclipse
682
711
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
+
683
725
## Contributing
684
726
685
727
See [contribution guide ](CONTRIBUTING .md ).
0 commit comments