Skip to content

Commit c8b6254

Browse files
committed
document APQ feature +semver: feature
1 parent 3f50777 commit c8b6254

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

README.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,22 @@ var subscription = subscriptionStream.Subscribe(response =>
162162
subscription.Dispose();
163163
```
164164

165-
## Syntax Highlighting for GraphQL strings in IDEs
165+
### Automatic persisted queries (APQ)
166166

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.
168168

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`.
170170

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`.
172173

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.
174175

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.
176181

177182
```csharp
178183
GraphQLQuery query = new("""
@@ -194,6 +199,19 @@ var graphQLResponse = await graphQLClient.SendQueryAsync<ResponseType>(
194199
new { id = "cGVvcGxlOjE=" });
195200
```
196201

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+
197215
## Useful Links
198216

199217
* [StarWars Example Server (GitHub)](https://github.com/graphql/swapi-graphql)

0 commit comments

Comments
 (0)