Skip to content

Commit

Permalink
Merge branch 'feature/new-docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Jun 6, 2024
2 parents 338a2e6 + d39368d commit d934bfc
Show file tree
Hide file tree
Showing 116 changed files with 465 additions and 181 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ repos:
hooks:
- id: blacken-docs
args: [--skip-errors]
files: '\.(rst|md|markdown|py|mdx)$'
6 changes: 5 additions & 1 deletion docs/README.md → docs/README.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: Strawberry docs
---

# Strawberry docs

- [Getting started](./index.md)
Expand Down Expand Up @@ -38,7 +42,7 @@

## [Extensions](./extensions)

## [Errors](./errors/)
## [Errors](./errors)

## Guides

Expand Down
13 changes: 10 additions & 3 deletions docs/_test.md → docs/_test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ class X:
You can show two different code blocks next to each other (useful when comparing
the GraphQL schema against the Python definition):

```python+schema
<CodeGrid>

```python
import strawberry


@strawberry.type
class Query:
@strawberry.field
def ping(self) -> str:
return "pong"
---
```

```graphql
type Query {
ping: String!
ping: String!
}
```

</CodeGrid>

or when showing the request and response to a query:

```graphql+response
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.146.0 Breaking Changes
slug: breaking-changes/0.146.0
---

# v0.146.0 Breaking Changes - 5 December 2022
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.159.0 Deprecations
slug: breaking-changes/0.159.0
---

# v0.159.0 Introduces changes how extension hooks are defined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.169.0 Breaking changes
slug: breaking-changes/0.169.0
---

# v0.169.0 Introduces a couple of breaking changes in the HTTP integrations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.180.0 Breaking changes
slug: breaking-changes/0.180.0
---

# v0.180.0 introduces a breaking change for the Django Channels HTTP integration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.213.0 Deprecation
slug: breaking-changes/0.213.0
---

# v0.213.0 introduces a deprecation for `graphiql` parameter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.217 Breaking Changes
slug: breaking-changes/0.217.0
---

# v0.217.0 changes how kwargs are passed to `has_permission` method
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: 0.233.0 Breaking Changes
slug: breaking-changes/0.233.0
---

# v0.233.0 changes the `info` argument in `resolve_reference` in Federation
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/editors/vscode.md → docs/editors/vscode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ checking mode. At the moment strict mode is not supported.
Once you have configured the settings, you can restart VS Code and you should be
getting type checking errors in vscode.

<img src="./pylance.png" alt="Pylance showing a type error" width="1990" height="522" />
<!-- ![Pylance showing a type error](./pylance.png) -->
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ the GraphQL schema, so using `strawberry.field` on that field won't be useful,
since it is meant to be used to change information about a field that is exposed
in the GraphQL schema.

<!--
note: this makes sense, but now we don't have a way to do something like:
strawberry.Private[list[str]] = strawberry.field(default_factory=list)
(workaround is to use dataclasses.field, explained below)
-->
<Note>
This makes sense, but now we don't have a way to do something like:
strawberry.Private[list[str]] = strawberry.field(default_factory=list)
(workaround is to use dataclasses.field, explained below)
</Note>

## How to fix this error

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ class Query:
```

<Note>

Note that if you are returning a type different than the connection type, you
will need to subclass the connection type and override its `resolve_node` method
to convert it to the correct type, as explained in the
[relay guide](../guides/relay).

<Note/>
Note that if you are returning a type different than the connection type, you
will need to subclass the connection type and override its `resolve_node`
method to convert it to the correct type, as explained in the [relay
guide](../guides/relay).
</Note>
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ strawberry.Schema(Query)
This happens because different types in Strawberry (and GraphQL) cannot have the
same name.

<!--
note: this error might happen also when trying to defined a scalar
with the same name as a type.
-->
<Note>
This error might happen also when trying to defined a scalar with the same
name as a type.
</Note>

## How to fix this error

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 11 additions & 7 deletions docs/general/mutations.md → docs/general/mutations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,23 @@ It is also possible to write a mutation that doesn't return anything.

This is mapped to a `Void` GraphQL scalar, and always returns `null`

```python+schema
<CodeGrid>
```python
@strawberry.type
class Mutation:
@strawberry.mutation
def restart() -> None:
print(f'Restarting the server')
---
print(f"Restarting the server")
```

```graphql
type Mutation {
restart: Void
}
```

</CodeGrid>

<Note>

Mutations with void-result go against
Expand Down Expand Up @@ -166,12 +171,10 @@ import strawberry
@strawberry.type
class FruitMutations:
@strawberry.mutation
def add(self, info, input: AddFruitInput) -> Fruit:
# ...
def add(self, info, input: AddFruitInput) -> Fruit: ...

@strawberry.mutation
def update_weight(self, info, input: UpdateFruitWeightInput) -> Fruit:
# ...
def update_weight(self, info, input: UpdateFruitWeightInput) -> Fruit: ...


@strawberry.type
Expand Down Expand Up @@ -211,4 +214,5 @@ For more details, see
[Apollo's guide on Namespaces for serial mutations](https://www.apollographql.com/docs/technotes/TN0012-namespacing-by-separation-of-concern/#namespaces-for-serial-mutations)
and
[Rapid API's Interactive Guide to GraphQL Queries: Aliases and Variables](https://rapidapi.com/guides/graphql-aliases-variables).

</Note>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ subscription {

In this example, the data looks like this as it passes over the websocket:

<img src="../images/subscriptions-count-websocket.png" alt="A view of the data that's been passed via websocket" width="1013" height="267" />
![A view of the data that's been passed via websocket](../images/subscriptions-count-websocket.png)

This is a very short example of what is possible. Like with queries and
mutations the subscription can return any GraphQL type, not only scalars as
Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions docs/general/why.md → docs/general/why.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ GraphQL APIs while also helping finding bugs when using type checkers like MyPy.
Here's a basic example of a type and how it compares to the equivalent type in
GraphQL:

```python+schema
<CodeGrid>

```python
@strawberry.type
class User:
id: strawberry.ID
name: str
---
```

```graphql
type User {
id: ID!
name: String!
}
```

</CodeGrid>

As you can see the code is very similar to what you would write using the
GraphQL SDL. Thanks to this, we think Strawberry hits a perfect middle ground
between code first and schema first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ It is quite common to want to be able to access the data from the field's parent
in a resolver. For example let's say that we want to define a `fullName` field
on our `User`. This would be our code:

```python+schema
<CodeGrid>

```python
import strawberry


Expand All @@ -17,14 +19,18 @@ class User:
first_name: str
last_name: str
full_name: str
---
```

```graphql
type User {
firstName: String!
lastName: String!
fullName: String!
firstName: String!
lastName: String!
fullName: String!
}
```

</CodeGrid>

In this case `full_name` will need to access the `first_name` and `last_name`
fields, and depending on whether we define the resolver as a function or as a
method, we'll have a few options! Let's start with the defining a resolver as a
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 18 additions & 5 deletions docs/guides/dataloaders.md → docs/guides/dataloaders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,18 @@ the dataloader, in order to avoid reloading data afterwards.

For example:

```python+graphql
<CodeGrid>

```python
@strawberry.type
class Person:
id: strawberry.ID
friends_ids: strawberry.Private[List[strawberry.ID]]

@strawberry.field
async def friends(self) -> List[Person]:
return await loader.load_many(self.friends_ids)
return await loader.load_many(self.friends_ids)


@strawberry.type
class Query:
Expand All @@ -220,7 +223,9 @@ class Query:
loader.prime_many({person.id: person for person in people})

return people
---
```

```graphql
{
getAllPeople {
id
Expand All @@ -231,6 +236,8 @@ class Query:
}
```

</CodeGrid>

### Custom Cache

DataLoader's default cache is per-request and it caches data in memory. This
Expand Down Expand Up @@ -341,7 +348,9 @@ that allows to fetch a single user by id.

We can use this query by doing the following request:

```graphql+response
<CodeGrid>

```graphql
{
first: getUser(id: 1) {
id
Expand All @@ -350,7 +359,9 @@ We can use this query by doing the following request:
id
}
}
---
```

```json
{
"data": {
"first": {
Expand All @@ -363,6 +374,8 @@ We can use this query by doing the following request:
}
```

</CodeGrid>

Even if this query is fetching two users, it still results in one call to
`load_users`.

Expand Down
Loading

0 comments on commit d934bfc

Please sign in to comment.