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
* Add APQ support
* changes
* rem
* note
* progress
* progress
* fix variable name
* move APQ code to SendQueryAsync method to allow usage over websocket, too
* make the APQDisabledForSession flag public (helps for testing)
* create a test that uses the APQ feature
* test APQ with websocket transport
* move code for generation of the APQ extension into GraphQLRequest
* fix naming
* replace system.memory reference with narrower system.buffers reference
* Update src/GraphQL.Primitives/GraphQLRequest.cs
Co-authored-by: Shane Krueger <[email protected]>
* Update src/GraphQL.Primitives/GraphQLRequest.cs
Co-authored-by: Shane Krueger <[email protected]>
* document APQ feature +semver: feature
* optimize docs
---------
Co-authored-by: Alexander Rose <[email protected]>
Co-authored-by: Alexander Rose <[email protected]>
Co-authored-by: Shane Krueger <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+27-6
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,9 @@ The Library will try to follow the following standards and documents:
22
22
23
23
## Usage
24
24
25
+
The intended use of `GraphQLHttpClient` is to keep one instance alive per endpoint (obvious in case you're
26
+
operating full websocket, but also true for regular requests) and is built with thread-safety in mind.
27
+
25
28
### Create a GraphQLHttpClient
26
29
27
30
```csharp
@@ -159,17 +162,22 @@ var subscription = subscriptionStream.Subscribe(response =>
159
162
subscription.Dispose();
160
163
```
161
164
162
-
##Syntax Highlighting for GraphQL strings in IDEs
165
+
### Automatic persisted queries (APQ)
163
166
164
-
.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.
165
168
166
-
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`.
167
170
168
-
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
+
By default, the client will automatically disable APQ for the current session if the server responds with a `PersistedQueryNotSupported` error or a 400 or 600 HTTP status code.
172
+
This can be customized by configuring `GraphQLHttpClientOptions.DisableAPQ`.
169
173
170
-
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.
171
175
172
-
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.
173
181
174
182
```csharp
175
183
GraphQLQueryquery=new("""
@@ -191,6 +199,19 @@ var graphQLResponse = await graphQLClient.SendQueryAsync<ResponseType>(
191
199
new { id="cGVvcGxlOjE=" });
192
200
```
193
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
+
194
215
## Useful Links
195
216
196
217
*[StarWars Example Server (GitHub)](https://github.com/graphql/swapi-graphql)
@@ -33,6 +32,12 @@ public class GraphQLHttpClient : IGraphQLWebSocketClient, IDisposable
33
32
/// </summary>
34
33
publicGraphQLHttpClientOptionsOptions{get;}
35
34
35
+
/// <summary>
36
+
/// This flag is set to <see langword="true"/> when an error has occurred on an APQ and <see cref="GraphQLHttpClientOptions.DisableAPQ"/>
37
+
/// has returned <see langword="true"/>. To reset this, the instance of <see cref="GraphQLHttpClient"/> has to be disposed and a new one must be created.
/// Delegate permitting use of <see href="https://www.apollographql.com/docs/react/api/link/persisted-queries/">Automatic Persisted Queries (APQ)</see>.
105
+
/// By default, returns <see langword="false" /> for all requests. Note that GraphQL server should support APQ. Otherwise, the client disables APQ completely
106
+
/// after an unsuccessful attempt to send an APQ request and then send only regular requests.
0 commit comments