extension

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

This package includes an extension that can be used as "github.com/99designs/gqlgen/graphql".HandlerExtension, e.g. in "github.com/99designs/gqlgen/graphql/handler".Server.Use.

The extension RecursionLimitByTypeAndField limits the number of times the same field of a type can be accessed in a request (query/mutation).

Usage:

gqlServer := handler.New()
gqlServer.Use(RecursionLimitByTypeAndField(1))

This allow only one of each "type.field" field access in a query. For following examples, consider that both root user and User.friends returns a type User (although friends may return a list).

Allows:

query {
  user {
    id
    friends {
      id
    }
  }
}

Forbids:

query {
  user {
    friends {
      friends {
        id
      }
    }
  }
}

User.friends is accessed twice here. Once in user.friends, and second time on friends.friends.

The intention of this extension is to replace extension.FixedComplexityLimit, as that is very difficult to configure properly. With RecursionLimitByTypeAndField, the client can query the whole graph in one query, but at least the query does have an upper bound of its size. If needed, both extensions can be used at the same time.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RecursionLimit

type RecursionLimit struct {
	// contains filtered or unexported fields
}

func RecursionLimitByTypeAndField

func RecursionLimitByTypeAndField(limit int) *RecursionLimit

func (*RecursionLimit) ExtensionName

func (r *RecursionLimit) ExtensionName() string

func (*RecursionLimit) MutateOperationContext

func (r *RecursionLimit) MutateOperationContext(_ context.Context, opCtx *graphql.OperationContext) *gqlerror.Error

func (*RecursionLimit) Validate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL