@@ -4,180 +4,52 @@ Adds full GraphQL syntax highlighting and language support such as bracket
4
4
matching.
5
5
6
6
- Supports ` .graphql ` /` .gql ` /` .graphqls ` highlighting
7
- - [ Javascript, Typescript & JSX/TSX] ( #ts ) & Vue & Svelte
8
- - ReasonML/ReScript (` %graphql() ` )
9
- - Python
10
- - PHP
11
- - [ Markdown] ( #markdown )
12
- - [ Scala] ( #scala )
7
+ - Javascript, Typescript & JSX/TSX (examples: [ test.js] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.js ) & [ test.ts] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.ts ) )
8
+ - Vue (examples: [ test-sfc-comp.vue] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test-sfc-comp.vue ) & [ test-sfc.vue] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test-sfc.vue ) )
9
+ - Svelte (example: [ test.svelte] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.svelte ) )
10
+ - ReasonML/ReScript (` %graphql() ` ) (example: [ test.re] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.re ) )
11
+ - Python (example: [ test.py] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.py ) )
12
+ - PHP (example: [ test.php] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.php ) )
13
+ - Markdown (examples: [ test.md] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.md ) & [ test-py.md] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test-py.md ) )
14
+ - Scala (example: [ test.scala] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.scala ) )
15
+ - ruby (example: [ test.rb] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/tests/__fixtures__/test.rb ) )
13
16
14
17
You'll want to install this if you do not use ` graphql-config ` , or want to use
15
18
the highlighting with other extensions than ` vscode-graphql `
16
19
17
- ## Embedded Language Usage
18
-
19
- <span id =" ts " >
20
- ### Javascript & Typescript
21
-
22
- The following delimiters are accepted for syntax highlighting. If you are using
23
- any of these patterns and they do not work, please open an issue!
24
-
25
- #### Template Literal Expressions
26
-
27
- ``` ts
28
- const query = gql `
29
- {
30
- id
31
- }
32
- ` ;
33
- ```
34
-
35
- you can use these template tag literal expressions anywhere you like of course
36
-
37
- ``` ts
38
- useFancyGraphQLClient (
39
- graphql `
40
- {
41
- id
42
- }
43
- ` ,
44
- {
45
- networkStrategy: ' 🚀' ,
46
- },
47
- );
48
- ```
20
+ ## Contributing
49
21
50
- ``` ts
51
- const query = gql .experimental ` { id } ` ;
52
- ```
53
-
54
- and in typescript, template tag expressions with type arguments
55
-
56
- ``` ts
57
- const query = gql <MyType >`
58
- {
59
- id
60
- }
61
- ` ;
62
- ```
63
-
64
- #### Function Expressions
65
-
66
- as well as normal function expressions with template literals
67
-
68
- ``` ts
69
- gql (' { id }' );
70
- ```
71
-
72
- ``` ts
73
- graphql (`
74
- {
75
- id
76
- }
77
- ` );
78
- ```
79
-
80
- there is a bug with function expressions with type arguments like these that we
81
- need to fix:
82
-
83
- ``` ts
84
- gql <MyType >(' { id }' );
85
- ```
86
-
87
- Note, inline ` "" ` and ` '' ` string literals could also be delimited if needed,
88
- but we currently only delimit graphql template strings for obvious reasons
89
-
90
- #### Comment-Delimited patterns
91
-
92
- ``` ts
93
- const query = /* GraphQL */ `
94
- {
95
- id
96
- }
97
- ` ;
98
- ```
99
-
100
- ``` ts
101
- const query = ` #graphql
102
- { id }
103
- ` ;
104
- ```
105
-
106
- For full autocompletion, validation and other features, you can install
107
- ` GraphQL.vscode-graphql ` , which depends on this extension
108
-
109
- <span id =" markdown " >
110
-
111
- ### Markdown
112
-
113
- #### backtick code blocks
114
-
115
- ```` markdown
116
- # Hello Jan
117
-
118
- ```graphql
119
- query MyQuery {}
120
- ```
121
- ````
122
-
123
- #### embedded graphql in js & ts codeblocks
124
-
125
- simple js/ts` gql ` & ` graphql ` template tag expression support inside any
126
- backtick codeblocks.
127
-
128
- ```` markdown
129
- # Hello Jan
130
-
131
- ```js
132
- const myQuery = gql`
133
- {
134
- its {
135
- query
136
- time
137
- }
138
- }
139
- `;
140
- ```
141
- ````
142
-
143
- #### Scala
144
-
145
- Using a ` graphql ` , ` gql ` or ` schema ` string interpolator:
22
+ Feel free to open a PR to fix, enhance any language support, or even add new
23
+ languages 😍
146
24
147
- ``` scala
148
- val query = graphql """
149
- { id }
150
- """
151
- val query2 = gql """
152
- { id }
153
- """
154
- val query3 = schema """
155
- { id }
156
- """
157
- ```
25
+ see:
158
26
159
- Using a comment-delimited pattern:
27
+ - [ the grammars] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/grammars/ )
28
+ - [ the applicable vscode docs] ( https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide )
160
29
161
- ``` scala
162
- val query = """ #graphql
163
- { id }
164
- """
165
- ```
30
+ ### Contributor Guide: Improving a Language
166
31
167
- ## Other languages
168
-
169
- We actually support other languages than this! just need to extend this readme
170
- even further! 🥵
32
+ Whether fixing a bug or adding a new delimiter for your language, here are a few tips for you:
171
33
172
- ## Contributing
34
+ 1 . TDD approach: add your bug case or new delimiter example to the relevant file in ` tests/__fixtures__ `
35
+ 1 . run ` yarn test -u ` in the syntax extension workspace, and observe whether vscode-textmate tokenizes your example properly
36
+ 1 . fix/update/add the relevant pattern, and repeat the above to see if the tokenization changes. you should see ` meta.embedded.block.graphql `
37
+ 1 . to test manually, run ` yarn vsce:package ` in the workspace and right click to install the bundled vsix extension, and open the fixture file
173
38
174
- Feel free to open a PR to fix, enhance any language support, or even add new
175
- languages 😍
39
+ <span id =" adding-a-lang " ></span >
176
40
177
- see:
41
+ ### Contributor Guide: Adding a Language
178
42
179
- - [ the grammars] ( grammars/ )
180
- - [ the applicable vscode docs] ( https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide )
43
+ 1 . add a file to [ grammars] ( https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-syntax/grammars/ ) following our other examples.
44
+ 1 . be sure to add it to ` package.json ` contributions as well, in the ` grammars ` section. the ` text.html.markdown ` is for applying to markdown codeblocks
45
+ 1 . use a scope ala ` source.{lang} ` from a vscode-provided syntax grammar, or a popular, official contributed grammar. To find the name of the scope for any token's highlighting, use ` Developer: Inspect Editor Tokens & Scopes ` from the vscode command palette.
46
+ 1 . name it ` inline.graphql.{lang} ` for consistency
47
+ 1 . add a test file ` tests/__fixture__ ` to document example usage, and a test spec to ` __tests__ ` to assert the snapshot, pointing to the source you created
48
+ 1 . run ` yarn test -u ` in the workspace to add the snapshot
49
+ 1 . use the snapshots to ensure your capture groups are working and serializing the graphql as expected
50
+ 1 . in the test fixture, document all working cases and non working cases with Todo comments for common usage in your language. be sure to think of cases such as string interpolation and generics for typed languages.
51
+ 1 . add it to the list above in the readme, with links to your test fixtures as usage documentation
52
+ 1 . to manually test it in vscode itself, run ` yarn vsce:package ` in the syntax extension workspace and right click and install the bundled vsix file, then view the test fixture
181
53
182
54
## Usage Note
183
55
0 commit comments