Skip to content

Commit

Permalink
Make spacing consistent (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJCompton committed Mar 15, 2021
1 parent 52ded95 commit b995f7f
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions docs/content/reference/complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ Consider a schema that allows listing blog posts. Each blog post is also related

```graphql
type Query {
posts(count: Int = 10): [Post!]!
posts(count: Int = 10): [Post!]!
}

type Post {
title: String!
text: String!
related(count: Int = 10): [Post!]!
title: String!
text: String!
related(count: Int = 10): [Post!]!
}
```

It's not too hard to craft a query that will cause a very large response:

```graphql
{
posts(count: 100) {
related(count: 100) {
related(count: 100) {
related(count: 100) {
title
}
}
}
}
posts(count: 100) {
related(count: 100) {
related(count: 100) {
related(count: 100) {
title
}
}
}
}
}
```

Expand All @@ -47,12 +47,12 @@ Limiting query complexity is as simple as specifying it with the provided extens

```go
func main() {
c := Config{ Resolvers: &resolvers{} }
c := Config{ Resolvers: &resolvers{} }


srv := handler.NewDefaultServer(blog.NewExecutableSchema(c))
srv.Use(extension.FixedComplexityLimit(5)) // This line is key
r.Handle("/query", srv)
r.Handle("/query", srv)
}
```

Expand All @@ -66,17 +66,17 @@ To apply higher costs to certain fields, we can use custom complexity functions.

```go
func main() {
c := Config{ Resolvers: &resolvers{} }
c := Config{ Resolvers: &resolvers{} }

countComplexity := func(childComplexity, count int) int {
return count * childComplexity
}
c.Complexity.Query.Posts = countComplexity
c.Complexity.Post.Related = countComplexity
countComplexity := func(childComplexity, count int) int {
return count * childComplexity
}
c.Complexity.Query.Posts = countComplexity
c.Complexity.Post.Related = countComplexity

srv := handler.NewDefaultServer(blog.NewExecutableSchema(c))
srv := handler.NewDefaultServer(blog.NewExecutableSchema(c))
srv.Use(extension.FixedComplexityLimit(5))
http.Handle("/query", gqlHandler)
http.Handle("/query", gqlHandler)
}
```

Expand Down

0 comments on commit b995f7f

Please sign in to comment.