You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-6
Original file line number
Diff line number
Diff line change
@@ -162,17 +162,22 @@ var subscription = subscriptionStream.Subscribe(response =>
162
162
subscription.Dispose();
163
163
```
164
164
165
-
##Syntax Highlighting for GraphQL strings in IDEs
165
+
### Automatic persisted queries (APQ)
166
166
167
-
.NET 7.0 introduced the [StringSyntaxAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.stringsyntaxattribute?view=net-8.0) to have a unified way of telling what data is expected in a given `string` or `ReadOnlySpan<char>`. IDEs like Visual Studio and Rider can then use this to provide syntax highlighting and checking.
167
+
[Automatic persisted queries (APQ)](https://www.apollographql.com/docs/apollo-server/performance/apq/) are supported since client version 6.1.0.
168
168
169
-
From v6.0.4 on all GraphQL string parameters in this library are decorated with the `[StringSyntax("GraphQL")]` attribute.
169
+
APQ can be enabled by configuring `GraphQLHttpClientOptions.EnableAutomaticPersistedQueries` to resolve to `true`.
170
170
171
-
Currently, there is no native support for GraphQL formatting and syntax highlighting in Visual Studio, but the [GraphQLTools Extension](https://marketplace.visualstudio.com/items?itemName=codearchitects-research.GraphQLTools) provides that for you.
171
+
The client will automatically disable APQ if the server responds with a `PersistedQueryNotSupported` error or if a HTTP status code between 400 and 600 is returned.
172
+
This can be customized by configuring `GraphQLHttpClientOptions.DisableAPQ`.
172
173
173
-
For Rider, JetBrains provides a [Plugin](https://plugins.jetbrains.com/plugin/8097-graphql), too.
174
+
To re-enable APQ after it has been automatically disabled, `GraphQLHttpClient` needs to be disposed an recreated.
174
175
175
-
To leverage syntax highlighting in variable declarations, the `GraphQLQuery` value record type is provided:
176
+
APQ works by first sending a hash of the query string to the server, and only sending the full query string if the server has not yet cached a query with a matching hash.
177
+
With queries supplied as a string parameter to `GraphQLRequest`, the hash gets computed each time the request is sent.
178
+
179
+
When you want to reuse a query string (propably to leverage APQ :wink:), declare the query using the `GraphQLQuery` class. This way, the hash gets computed once on construction
180
+
of the `GraphQLQuery` object and handed down to each `GraphQLRequest` using the query.
176
181
177
182
```csharp
178
183
GraphQLQueryquery=new("""
@@ -194,6 +199,19 @@ var graphQLResponse = await graphQLClient.SendQueryAsync<ResponseType>(
194
199
new { id="cGVvcGxlOjE=" });
195
200
```
196
201
202
+
### Syntax Highlighting for GraphQL strings in IDEs
203
+
204
+
.NET 7.0 introduced the [StringSyntaxAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.stringsyntaxattribute?view=net-8.0) to have a unified way of telling what data is expected in a given `string` or `ReadOnlySpan<char>`. IDEs like Visual Studio and Rider can then use this to provide syntax highlighting and checking.
205
+
206
+
From v6.0.4 on all GraphQL string parameters in this library are decorated with the `[StringSyntax("GraphQL")]` attribute.
207
+
208
+
Currently, there is no native support for GraphQL formatting and syntax highlighting in Visual Studio, but the [GraphQLTools Extension](https://marketplace.visualstudio.com/items?itemName=codearchitects-research.GraphQLTools) provides that for you.
209
+
210
+
For Rider, JetBrains provides a [Plugin](https://plugins.jetbrains.com/plugin/8097-graphql), too.
211
+
212
+
To leverage syntax highlighting in variable declarations, use the `GraphQLQuery` class.
213
+
214
+
197
215
## Useful Links
198
216
199
217
*[StarWars Example Server (GitHub)](https://github.com/graphql/swapi-graphql)
0 commit comments