Skip to content

Commit

Permalink
Added version docs for StrawberryShake
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Sep 5, 2022
1 parent cc04329 commit 59eccd9
Show file tree
Hide file tree
Showing 18 changed files with 2,159 additions and 1 deletion.
92 changes: 91 additions & 1 deletion website/src/docs/docs.json
Expand Up @@ -860,7 +860,97 @@
"versions": [
{
"path": "",
"title": "v11",
"title": "v13",
"items": [
{
"path": "index",
"title": "Introduction"
},
{
"path": "get-started",
"title": "Get Started",
"items": [
{
"path": "index",
"title": "Blazor"
},
{
"path": "xamarin",
"title": "Xamarin"
},
{
"path": "console",
"title": "Console"
}
]
},
{
"path": "subscriptions",
"title": "Subscriptions"
},
{
"path": "tooling",
"title": "Tooling / CLI"
},
{
"path": "caching",
"title": "Caching",
"items": [
{
"path": "index",
"title": "Overview"
},
{
"path": "entities",
"title": "Entities"
},
{
"path": "invalidation",
"title": "Invalidation"
}
]
},
{
"path": "performance",
"title": "Performance",
"items": [
{
"path": "index",
"title": "Overview"
},
{
"path": "persisted-queries",
"title": "Persisted Queries"
},
{
"path": "persisted-state",
"title": "Persisted State"
}
]
},
{
"path": "networking",
"title": "Networking",
"items": [
{
"path": "index",
"title": "Protocols"
},
{
"path": "authentication",
"title": "Authentication"
}
]
},
{
"path": "scalars",
"title": "Scalars"
}
]
},
{
"path": "v12",
"title": "v12",
"items": [
{
"path": "index",
Expand Down
4 changes: 4 additions & 0 deletions website/src/docs/strawberryshake/get-started/index.md
Expand Up @@ -14,6 +14,10 @@ In this tutorial, we will teach you:
- How to generate source code from .graphql files, that contain operations.
- How to use the generated client in a classical or reactive way.

<iframe width="560" height="315"
src="https://www.youtube.com/embed/-oq7YEciouM"frameborder="0"
allowfullscreen></iframe>

# Step 1: Add the Strawberry Shake CLI tools

The Strawberry Shake tool will help you to setup your project to create a GraphQL client.
Expand Down
1 change: 1 addition & 0 deletions website/src/docs/strawberryshake/v12/caching/entities.md
@@ -0,0 +1 @@
> 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.
67 changes: 67 additions & 0 deletions website/src/docs/strawberryshake/v12/caching/index.md
@@ -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();
});
```
@@ -0,0 +1 @@
> 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.
30 changes: 30 additions & 0 deletions website/src/docs/strawberryshake/v12/configuration.md
@@ -0,0 +1,30 @@
# Configuring Strawberry Shake

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/",
// 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
}
}
}
```

0 comments on commit 59eccd9

Please sign in to comment.