traefikgraphqllimits

package module
v0.0.0-...-3659ad3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

GraphQL Limits

Traefik Middleware which allows filtering GraphQL queries by different limits

Options

GraphQLPath

Optional, Default: /graphql

Controls which POST requests to check for GraphQL queries

DepthLimit

Optional, Default: 0

Check if the query depth does not exceed the limit. We count depth as each selection set, excluding top-level

BatchLimit

Optional, Default: 0

Check if the query does not have more batches than limit

NodeLimit

Optional, Default: 0

Check if query total number of nodes does not exceed the limit. We defined node as a selection set excluding top-level wrappers

Configuration

Static
pilot:
  token: xxx
experimental:
  plugins:
    traefik-graphql-limits:
      modulename: github.com/narrative-bi/traefik-graphql-limits
      version: v0.1.0
Dynamic
http:
  routers:
    graphql-server-entrypoint:
      service: graphql-server-service
      entrypoints:
        - graphql-server-entrypoint
      rule: Host(`localhost`)
      middlewares:
        - my-traefik-graphql-limits

  services:
    graphql-server-service:
      loadBalancer:
        servers:
          - url: http://localhost:5000/

  middlewares:
    my-traefik-graphql-limits:
      plugin:
        traefik-graphql-limits:
          GraphQLPath: /graphql
          DepthLimit: 5
          BatchLimit: 2
          NodeLimit: 25
Testing

You can run tests by running make

Documentation

Overview

Package traefikgraphqllimits provides a Traefik plugin to limit the depth of a GraphQL query

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new plugin.

Types

type Config

type Config struct {
	GraphQLPath string
	DepthLimit  int
	BatchLimit  int
	NodeLimit   int
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type GraphqlLimit

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

GraphqlLimit plugin configuration structure.

func (*GraphqlLimit) ServeHTTP

func (d *GraphqlLimit) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type QueryMetrics

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

QueryMetrics the query metrics for check.

func (QueryMetrics) CreateQueryMetrics

func (queryMetrics QueryMetrics) CreateQueryMetrics() QueryMetrics

CreateQueryMetrics creates the default query metrics.

Jump to

Keyboard shortcuts

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