Skip to content

Commit

Permalink
Upgrade to OperationContext and remove duplicate fields to fix #1161
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLindhout authored May 11, 2020
1 parent 0a40481 commit 6518d83
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions docs/content/reference/field-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,21 @@ The type `Circle` would satisfy `Circle`, `Shape`, and `Shapes` — these values
Say we have the following GraphQL query

```graphql
flowBlocks {
id
block{
id
title
type
choices{
id
title
description
slug
}
}
query {
flowBlocks {
id
block {
id
title
type
choices {
id
title
description
slug
}
}
}
}
```

Expand All @@ -83,19 +85,17 @@ Here is an example which get's all requested field as convenient string slice, w
```golang
func GetPreloads(ctx context.Context) []string {
return GetNestedPreloads(
graphql.GetRequestContext(ctx),
graphql.GetOperationContext(ctx),
graphql.CollectFieldsCtx(ctx, nil),
"",
)
}

func GetNestedPreloads(ctx *graphql.RequestContext, fields []graphql.CollectedField, prefix string) (preloads []string) {
func GetNestedPreloads(ctx *graphql.OperationContext, fields []graphql.CollectedField, prefix string) (preloads []string) {
for _, column := range fields {
prefixColumn := GetPreloadString(prefix, column.Name)
preloads = append(preloads, prefixColumn)
preloads = append(preloads, GetNestedPreloads(ctx, graphql.CollectFields(ctx, column.SelectionSet, nil), prefixColumn)...)
preloads = append(preloads, GetNestedPreloads(ctx, graphql.CollectFields(ctx, column.Selections, nil), prefixColumn)...)

}
return
}
Expand Down

0 comments on commit 6518d83

Please sign in to comment.