-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation directory for StrawberryShake v14 (#7435)
- Loading branch information
Showing
18 changed files
with
1,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "Entities" | ||
--- | ||
|
||
> We are still working on the documentation for Strawberry Shake so help us by finding typos, missing things or write some additional docs with us. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
title: "Caching" | ||
--- | ||
|
||
> We are still working on the documentation for Strawberry Shake, so help us by finding typos, missing things, or write some additional docs with us. | ||
StrawberryShake stores the result of GraphQL requests in a normalized entity store. The entity store allows your client to execute GraphQL requests with various strategies to reduce the need for network requests. Moreover, the normalized entities are updated by every request the client does, which means that you can build fully reactive components that change as the state in the store changes. | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant Generated Client | ||
participant Operation Store | ||
participant Entity Store | ||
participant GraphQL Server | ||
Generated Client->>Operation Store: Queries local store | ||
Operation Store->>GraphQL Server: Queries GraphQL server | ||
Note over Entity Store: Normalize response into entities | ||
GraphQL Server->>Entity Store: Returns GraphQL response | ||
Note over Operation Store: Builds operation result from entities | ||
Entity Store->>Operation Store: Returns entities for operation | ||
Operation Store->>Generated Client: Returns operation result | ||
``` | ||
|
||
# Strategies | ||
|
||
We support three basic strategies to interact with the store and fetch data. | ||
|
||
## Network Only | ||
|
||
Network only is the simplest strategy and will fetch from the network and only then update the store. This means that our initial call will always get fresh data and at the same time update other request results watching the same entities. | ||
|
||
If we use the reactive APIs in combination with network only we will still get updates whenever other requests fetch data for the entities we are watching. | ||
|
||
## Cache First | ||
|
||
Cache first is essentially the opposite of network only since it will first fetch from the store, and if the store has the data needed, it will not make any network requests. If the store does not have the data needed, it will go to the network and try to get the data and update the store. | ||
|
||
## Cache and Network | ||
|
||
The last strategy is a combination of the first two. The client will first try to get the data from the store. This gives us fast data response time if the store already has the data. After that the store will update that data for this request with data from the network which in consequence will trigger our subscription and serve us new data. | ||
|
||
## Configuration | ||
|
||
The global strategy default can be set on our dependency injection setup method. | ||
|
||
```csharp | ||
builder.Services | ||
.AddConferenceClient(ExecutionStrategy.CacheFirst) // <---- | ||
.ConfigureHttpClient(client => client.BaseAddress = new Uri("http://localhost:5050/graphql")) | ||
.ConfigureWebSocketClient(client => client.Uri = new Uri("ws://localhost:5050/graphql")); | ||
``` | ||
|
||
The global strategy default can then be overwritten by any `Watch` method for a particular request. | ||
|
||
```csharp | ||
storeSession = | ||
ConferenceClient | ||
.GetSessions | ||
.Watch(ExecutionStrategy.CacheFirst) // <---- | ||
.Where(t => !t.Errors.Any()) | ||
.Select(t => t.Data!.Sessions!.Nodes) | ||
.Subscribe(result => | ||
{ | ||
sessions = result; | ||
StateHasChanged(); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "Invalidation" | ||
--- | ||
|
||
> We are still working on the documentation for Strawberry Shake so help us by finding typos, missing things or write some additional docs with us. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: Configuration | ||
--- | ||
|
||
Strawberry Shake is configured by altering the `.graphqlrc.json` at the root of your project. | ||
All settings to into `extensions.strawberryShake` object. | ||
Here is a full configuration with all possibilities: | ||
|
||
```json | ||
{ | ||
// The path of the schema file, that will be used to generate the client. | ||
// This setting may also be used by other tooling, because it is a default field of graphql-spec | ||
"schema": "schema.graphql", | ||
// The selector that determines, what files will be regarded as graphql documents | ||
// This setting may also be used by other tooling, because it is a default field of graphql-spec | ||
"documents": "**/*.graphql", | ||
"extensions": { | ||
// Here do only Strawberry Shake specific settings live | ||
"strawberryShake": { | ||
// The name of the generated client | ||
"name": "ChatClient", | ||
// The namespace of all the generated files of the client | ||
"namespace": "Demo", | ||
// The URL of the GraphQL api you want to consume with the client | ||
"url": "https://workshop.chillicream.com/graphql/", | ||
// The access level modifier of the generated client | ||
"accessModifier": "public", | ||
// Shall your client be based on dependency injection? If yes, all needed setup code | ||
// will be generated for you, so that you only have to add the client to your DI container. | ||
"dependencyInjection": true | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.