gqt

package module
v4.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Coverage Status GoReportCard GoDoc

GraphQL Query Template Language

This Go package provides a parser for GQT, the GraphQL Query Template language which is used by Graph Guard for defining GraphQL query templates in a flexible and human-friendly way.

A GQT template declaratively defines the constraints of both the structure and input values of a GraphQL operation.

# This is a GQT query template example.
query {
  # Allow selecting a user with any id.
  user(id: *) {
    id
    name
    max 2 { # Allow a maximum of 2 selections out of this set.
      birthdate
      email
      address {country city street}
    }
    # Allow a maximum limit of 100 friends.
    friends(after: *, limit=$friendsLimit: < 100) {
      id name birthdate email
      # Allow a maximum limit of 100 friends in total with a maximum depth of 2.
      # limit is restricted to a maximum value of 100 divided by the limit above.
      friends(after: *, limit: < 100 / $friendsLimit) {
        id name birthdate email
      }
    }
    pictures(
      # Allow a string with a maximum byte length of 64.
      prefix: len <= 64,
      # Allow an array with a maximum of 8 items,
      # where each item string is not longer than 64 bytes.
      tags: len < 8 && [...len < 64],
      # Allow only a subset of possible enum values in the category argument.
      category: PUBLIC || FRIENDSONLY,
      # Allow a rating value between 10 and 20
      rating: > 10 && < 20, 
    ) { url }
  }
}

GraphQL Schema:

# This is a GQT query template example.
scalar Date
enum PictureCategory {
    PUBLIC
    FRIENDSONLY
    PRIVATE
}
type Query { user(id: ID!): User }
type User {
    id:        ID!
    name:      String
    birthdate: Date
    email:     String
    address:   Address
    friends(
        after: ID,
        limit: Int!,
    ): [User!]!
    pictures(
        prefix:   String,
        tags:     [String!],
        category: PictureCategory,
        rating:   Int,
    ): [Picture!]
}
type Address {
    country: String!
    city:    String!
    street:  String!
}
type Picture { url: String! }

Features

  • Flexible restriction of the structure of a GraphQL request including max depth.
  • Intuitive GraphQL-like syntax.
  • Schema-aware mode with full type checking and validation.
  • Schemaless mode (no validation against a GraphQL schema).
  • Arithmetic and boolean expressions in input value constraints.
  • Restriction of the maximum number of selections inside a max set.

Full documentation is available at docs.graphguard.io/gqt.

Documentation

Overview

Package gqt provides a GraphQL Query Template language (GQT) parser. The parser can be used in both schemaless and schema-aware modes. To use the schema-aware mode create a parser instance using NewParser and provide all .graphqls schema files. gqt.Parse will parse the template in schemaless mode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(src []byte) (
	operation *Operation,
	variables map[string]*VariableDeclaration,
	errors []Error,
)

Parse parses the template in schemaless mode and returns its abstract syntax tree.

func WriteYAML

func WriteYAML(w io.Writer, o *Operation) error

WriteYAML writes any AST object as YAML to w.

Types

type Argument

type Argument struct {
	LocRange
	Name
	Parent             Expression
	AssociatedVariable *VariableDeclaration
	Constraint         Expression
	Def                *ast.ArgumentDefinition
}

Argument is an input argument.

func (*Argument) GetLocation

func (e *Argument) GetLocation() LocRange

func (*Argument) GetParent

func (e *Argument) GetParent() Expression

func (*Argument) IsFloat

func (e *Argument) IsFloat() bool

func (*Argument) MarshalYAML

func (a *Argument) MarshalYAML() (any, error)

func (*Argument) TypeDesignation

func (e *Argument) TypeDesignation() string

type ArgumentList

type ArgumentList struct {
	LocRange
	Arguments []*Argument
}

ArgumentList is an argument list.

func (ArgumentList) MarshalYAML

func (l ArgumentList) MarshalYAML() (any, error)

type Array

type Array struct {
	LocRange
	Parent Expression
	Items  []Expression
	Type   *ast.Type
}

Array is an array value constant or an array constraint.

func (*Array) GetLocation

func (e *Array) GetLocation() LocRange

func (*Array) GetParent

func (e *Array) GetParent() Expression

func (*Array) IsFloat

func (e *Array) IsFloat() bool

func (*Array) MarshalYAML

func (a *Array) MarshalYAML() (any, error)

func (*Array) TypeDesignation

func (e *Array) TypeDesignation() string

type ConstrAny

type ConstrAny struct {
	LocRange
	Parent Expression
}

ConstrAny is the any value constraint (*)

func (*ConstrAny) GetLocation

func (e *ConstrAny) GetLocation() LocRange

func (*ConstrAny) GetParent

func (e *ConstrAny) GetParent() Expression

func (*ConstrAny) IsFloat

func (e *ConstrAny) IsFloat() bool

func (*ConstrAny) MarshalYAML

func (c *ConstrAny) MarshalYAML() (any, error)

func (*ConstrAny) TypeDesignation

func (e *ConstrAny) TypeDesignation() string

type ConstrEquals

type ConstrEquals struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrEquals is the equality constraint

func (*ConstrEquals) GetLocation

func (e *ConstrEquals) GetLocation() LocRange

func (*ConstrEquals) GetParent

func (e *ConstrEquals) GetParent() Expression

func (*ConstrEquals) IsFloat

func (e *ConstrEquals) IsFloat() bool

func (*ConstrEquals) MarshalYAML

func (c *ConstrEquals) MarshalYAML() (any, error)

func (*ConstrEquals) TypeDesignation

func (e *ConstrEquals) TypeDesignation() string

type ConstrGreater

type ConstrGreater struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrGreater is the relational "greater than" constraint (>)

func (*ConstrGreater) GetLocation

func (e *ConstrGreater) GetLocation() LocRange

func (*ConstrGreater) GetParent

func (e *ConstrGreater) GetParent() Expression

func (*ConstrGreater) IsFloat

func (e *ConstrGreater) IsFloat() bool

func (*ConstrGreater) MarshalYAML

func (c *ConstrGreater) MarshalYAML() (any, error)

func (*ConstrGreater) TypeDesignation

func (e *ConstrGreater) TypeDesignation() string

type ConstrGreaterOrEqual

type ConstrGreaterOrEqual struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrGreater is the relational "greater than or equal" constraint (>=)

func (*ConstrGreaterOrEqual) GetLocation

func (e *ConstrGreaterOrEqual) GetLocation() LocRange

func (*ConstrGreaterOrEqual) GetParent

func (e *ConstrGreaterOrEqual) GetParent() Expression

func (*ConstrGreaterOrEqual) IsFloat

func (e *ConstrGreaterOrEqual) IsFloat() bool

func (*ConstrGreaterOrEqual) MarshalYAML

func (c *ConstrGreaterOrEqual) MarshalYAML() (any, error)

func (*ConstrGreaterOrEqual) TypeDesignation

func (e *ConstrGreaterOrEqual) TypeDesignation() string

type ConstrLenEquals

type ConstrLenEquals struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenEquals is the relational length equality constraint for String or array values.

func (*ConstrLenEquals) GetLocation

func (e *ConstrLenEquals) GetLocation() LocRange

func (*ConstrLenEquals) GetParent

func (e *ConstrLenEquals) GetParent() Expression

func (*ConstrLenEquals) IsFloat

func (e *ConstrLenEquals) IsFloat() bool

func (*ConstrLenEquals) MarshalYAML

func (c *ConstrLenEquals) MarshalYAML() (any, error)

func (*ConstrLenEquals) TypeDesignation

func (e *ConstrLenEquals) TypeDesignation() string

type ConstrLenGreater

type ConstrLenGreater struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenGreater is the relational "greater than" constraint for String or array values (len >).

func (*ConstrLenGreater) GetLocation

func (e *ConstrLenGreater) GetLocation() LocRange

func (*ConstrLenGreater) GetParent

func (e *ConstrLenGreater) GetParent() Expression

func (*ConstrLenGreater) IsFloat

func (e *ConstrLenGreater) IsFloat() bool

func (*ConstrLenGreater) MarshalYAML

func (c *ConstrLenGreater) MarshalYAML() (any, error)

func (*ConstrLenGreater) TypeDesignation

func (e *ConstrLenGreater) TypeDesignation() string

type ConstrLenGreaterOrEqual

type ConstrLenGreaterOrEqual struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenGreaterOrEqual is the relational "greater than or equal" constraint for String or array values (len >=).

func (*ConstrLenGreaterOrEqual) GetLocation

func (e *ConstrLenGreaterOrEqual) GetLocation() LocRange

func (*ConstrLenGreaterOrEqual) GetParent

func (e *ConstrLenGreaterOrEqual) GetParent() Expression

func (*ConstrLenGreaterOrEqual) IsFloat

func (e *ConstrLenGreaterOrEqual) IsFloat() bool

func (*ConstrLenGreaterOrEqual) MarshalYAML

func (c *ConstrLenGreaterOrEqual) MarshalYAML() (any, error)

func (*ConstrLenGreaterOrEqual) TypeDesignation

func (e *ConstrLenGreaterOrEqual) TypeDesignation() string

type ConstrLenLess

type ConstrLenLess struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenLess is the relational "length less than" constraint for String or array values (len <).

func (*ConstrLenLess) GetLocation

func (e *ConstrLenLess) GetLocation() LocRange

func (*ConstrLenLess) GetParent

func (e *ConstrLenLess) GetParent() Expression

func (*ConstrLenLess) IsFloat

func (e *ConstrLenLess) IsFloat() bool

func (*ConstrLenLess) MarshalYAML

func (c *ConstrLenLess) MarshalYAML() (any, error)

func (*ConstrLenLess) TypeDesignation

func (e *ConstrLenLess) TypeDesignation() string

type ConstrLenLessOrEqual

type ConstrLenLessOrEqual struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenLessOrEqual is the relational "length less than or equal" constraint for String or array values (len <=).

func (*ConstrLenLessOrEqual) GetLocation

func (e *ConstrLenLessOrEqual) GetLocation() LocRange

func (*ConstrLenLessOrEqual) GetParent

func (e *ConstrLenLessOrEqual) GetParent() Expression

func (*ConstrLenLessOrEqual) IsFloat

func (e *ConstrLenLessOrEqual) IsFloat() bool

func (*ConstrLenLessOrEqual) MarshalYAML

func (c *ConstrLenLessOrEqual) MarshalYAML() (any, error)

func (*ConstrLenLessOrEqual) TypeDesignation

func (e *ConstrLenLessOrEqual) TypeDesignation() string

type ConstrLenNotEquals

type ConstrLenNotEquals struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLenNotEquals is the relational length inequality constraint for String or array values.

func (*ConstrLenNotEquals) GetLocation

func (e *ConstrLenNotEquals) GetLocation() LocRange

func (*ConstrLenNotEquals) GetParent

func (e *ConstrLenNotEquals) GetParent() Expression

func (*ConstrLenNotEquals) IsFloat

func (e *ConstrLenNotEquals) IsFloat() bool

func (*ConstrLenNotEquals) MarshalYAML

func (c *ConstrLenNotEquals) MarshalYAML() (any, error)

func (*ConstrLenNotEquals) TypeDesignation

func (e *ConstrLenNotEquals) TypeDesignation() string

type ConstrLess

type ConstrLess struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLess is the relational "less than" constraint (<)

func (*ConstrLess) GetLocation

func (e *ConstrLess) GetLocation() LocRange

func (*ConstrLess) GetParent

func (e *ConstrLess) GetParent() Expression

func (*ConstrLess) IsFloat

func (e *ConstrLess) IsFloat() bool

func (*ConstrLess) MarshalYAML

func (c *ConstrLess) MarshalYAML() (any, error)

func (*ConstrLess) TypeDesignation

func (e *ConstrLess) TypeDesignation() string

type ConstrLessOrEqual

type ConstrLessOrEqual struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrLess is the relational "less than or equal" constraint (<=)

func (*ConstrLessOrEqual) GetLocation

func (e *ConstrLessOrEqual) GetLocation() LocRange

func (*ConstrLessOrEqual) GetParent

func (e *ConstrLessOrEqual) GetParent() Expression

func (*ConstrLessOrEqual) IsFloat

func (e *ConstrLessOrEqual) IsFloat() bool

func (*ConstrLessOrEqual) MarshalYAML

func (c *ConstrLessOrEqual) MarshalYAML() (any, error)

func (*ConstrLessOrEqual) TypeDesignation

func (e *ConstrLessOrEqual) TypeDesignation() string

type ConstrMap

type ConstrMap struct {
	LocRange
	Parent     Expression
	Constraint Expression
}

ConstrMap maps a constraint to all items of the array.

func (*ConstrMap) GetLocation

func (e *ConstrMap) GetLocation() LocRange

func (*ConstrMap) GetParent

func (e *ConstrMap) GetParent() Expression

func (*ConstrMap) IsFloat

func (e *ConstrMap) IsFloat() bool

func (*ConstrMap) MarshalYAML

func (c *ConstrMap) MarshalYAML() (any, error)

func (*ConstrMap) TypeDesignation

func (e *ConstrMap) TypeDesignation() string

type ConstrNotEquals

type ConstrNotEquals struct {
	LocRange
	Parent Expression
	Value  Expression
}

ConstrNotEquals is the inequality constraint

func (*ConstrNotEquals) GetLocation

func (e *ConstrNotEquals) GetLocation() LocRange

func (*ConstrNotEquals) GetParent

func (e *ConstrNotEquals) GetParent() Expression

func (*ConstrNotEquals) IsFloat

func (e *ConstrNotEquals) IsFloat() bool

func (*ConstrNotEquals) MarshalYAML

func (c *ConstrNotEquals) MarshalYAML() (any, error)

func (*ConstrNotEquals) TypeDesignation

func (e *ConstrNotEquals) TypeDesignation() string

type Enum

type Enum struct {
	LocRange
	Parent  Expression
	Value   string
	TypeDef *ast.Definition
}

Enum is an enumeration value constant.

func (*Enum) GetLocation

func (e *Enum) GetLocation() LocRange

func (*Enum) GetParent

func (e *Enum) GetParent() Expression

func (*Enum) IsFloat

func (e *Enum) IsFloat() bool

func (*Enum) MarshalYAML

func (e *Enum) MarshalYAML() (any, error)

func (*Enum) TypeDesignation

func (e *Enum) TypeDesignation() string

type Error

type Error struct {
	LocRange
	Msg string
}

func (Error) Error

func (e Error) Error() string

func (Error) IsErr

func (e Error) IsErr() bool

type ExprAddition

type ExprAddition struct {
	LocRange
	Parent      Expression
	AddendLeft  Expression
	AddendRight Expression
	Float       bool
}

ExprAddition is an arithmetic addition expression using the operator "+".

func (*ExprAddition) GetLocation

func (e *ExprAddition) GetLocation() LocRange

func (*ExprAddition) GetParent

func (e *ExprAddition) GetParent() Expression

func (*ExprAddition) IsFloat

func (e *ExprAddition) IsFloat() bool

func (*ExprAddition) MarshalYAML

func (e *ExprAddition) MarshalYAML() (any, error)

func (*ExprAddition) TypeDesignation

func (e *ExprAddition) TypeDesignation() string

type ExprDivision

type ExprDivision struct {
	LocRange
	Parent   Expression
	Dividend Expression
	Divisor  Expression
	Float    bool
}

ExprDivision is an arithmetic division expression using the operator "/".

func (*ExprDivision) GetLocation

func (e *ExprDivision) GetLocation() LocRange

func (*ExprDivision) GetParent

func (e *ExprDivision) GetParent() Expression

func (*ExprDivision) IsFloat

func (e *ExprDivision) IsFloat() bool

func (*ExprDivision) MarshalYAML

func (e *ExprDivision) MarshalYAML() (any, error)

func (*ExprDivision) TypeDesignation

func (e *ExprDivision) TypeDesignation() string

type ExprEqual

type ExprEqual struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprEqual is a boolean equality expression using the operator "==".

func (*ExprEqual) GetLocation

func (e *ExprEqual) GetLocation() LocRange

func (*ExprEqual) GetParent

func (e *ExprEqual) GetParent() Expression

func (*ExprEqual) IsFloat

func (e *ExprEqual) IsFloat() bool

func (*ExprEqual) MarshalYAML

func (e *ExprEqual) MarshalYAML() (any, error)

func (*ExprEqual) TypeDesignation

func (e *ExprEqual) TypeDesignation() string

type ExprGreater

type ExprGreater struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprGreater is a boolean relational "greater than" expression using the operator ">".

func (*ExprGreater) GetLocation

func (e *ExprGreater) GetLocation() LocRange

func (*ExprGreater) GetParent

func (e *ExprGreater) GetParent() Expression

func (*ExprGreater) IsFloat

func (e *ExprGreater) IsFloat() bool

func (*ExprGreater) MarshalYAML

func (e *ExprGreater) MarshalYAML() (any, error)

func (*ExprGreater) TypeDesignation

func (e *ExprGreater) TypeDesignation() string

type ExprGreaterOrEqual

type ExprGreaterOrEqual struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprGreaterOrEqual is a boolean relational "greater than or equal" expression using the operator ">=".

func (*ExprGreaterOrEqual) GetLocation

func (e *ExprGreaterOrEqual) GetLocation() LocRange

func (*ExprGreaterOrEqual) GetParent

func (e *ExprGreaterOrEqual) GetParent() Expression

func (*ExprGreaterOrEqual) IsFloat

func (e *ExprGreaterOrEqual) IsFloat() bool

func (*ExprGreaterOrEqual) MarshalYAML

func (e *ExprGreaterOrEqual) MarshalYAML() (any, error)

func (*ExprGreaterOrEqual) TypeDesignation

func (e *ExprGreaterOrEqual) TypeDesignation() string

type ExprLess

type ExprLess struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprLess is a boolean relational "less than" expression using the operator "<".

func (*ExprLess) GetLocation

func (e *ExprLess) GetLocation() LocRange

func (*ExprLess) GetParent

func (e *ExprLess) GetParent() Expression

func (*ExprLess) IsFloat

func (e *ExprLess) IsFloat() bool

func (*ExprLess) MarshalYAML

func (e *ExprLess) MarshalYAML() (any, error)

func (*ExprLess) TypeDesignation

func (e *ExprLess) TypeDesignation() string

type ExprLessOrEqual

type ExprLessOrEqual struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprLessOrEqual is a boolean relational "less than or equal" expression using the operator "<=".

func (*ExprLessOrEqual) GetLocation

func (e *ExprLessOrEqual) GetLocation() LocRange

func (*ExprLessOrEqual) GetParent

func (e *ExprLessOrEqual) GetParent() Expression

func (*ExprLessOrEqual) IsFloat

func (e *ExprLessOrEqual) IsFloat() bool

func (*ExprLessOrEqual) MarshalYAML

func (e *ExprLessOrEqual) MarshalYAML() (any, error)

func (*ExprLessOrEqual) TypeDesignation

func (e *ExprLessOrEqual) TypeDesignation() string

type ExprLogicalAnd

type ExprLogicalAnd struct {
	LocRange
	Parent      Expression
	Expressions []Expression
}

ExprLogicalAnd is a boolean logical AND expression using the operator "&&".

func (*ExprLogicalAnd) GetLocation

func (e *ExprLogicalAnd) GetLocation() LocRange

func (*ExprLogicalAnd) GetParent

func (e *ExprLogicalAnd) GetParent() Expression

func (*ExprLogicalAnd) IsFloat

func (e *ExprLogicalAnd) IsFloat() bool

func (*ExprLogicalAnd) MarshalYAML

func (e *ExprLogicalAnd) MarshalYAML() (any, error)

func (*ExprLogicalAnd) TypeDesignation

func (e *ExprLogicalAnd) TypeDesignation() string

type ExprLogicalNegation

type ExprLogicalNegation struct {
	LocRange
	Parent     Expression
	Expression Expression
}

ExprLogicalNegation is a logical negation expression using the prefix operator "!".

func (*ExprLogicalNegation) GetLocation

func (e *ExprLogicalNegation) GetLocation() LocRange

func (*ExprLogicalNegation) GetParent

func (e *ExprLogicalNegation) GetParent() Expression

func (*ExprLogicalNegation) IsFloat

func (e *ExprLogicalNegation) IsFloat() bool

func (*ExprLogicalNegation) MarshalYAML

func (e *ExprLogicalNegation) MarshalYAML() (any, error)

func (*ExprLogicalNegation) TypeDesignation

func (e *ExprLogicalNegation) TypeDesignation() string

type ExprLogicalOr

type ExprLogicalOr struct {
	LocRange
	Parent      Expression
	Expressions []Expression
}

ExprLogicalOr is a boolean logical OR expression using the operator "||".

func (*ExprLogicalOr) GetLocation

func (e *ExprLogicalOr) GetLocation() LocRange

func (*ExprLogicalOr) GetParent

func (e *ExprLogicalOr) GetParent() Expression

func (*ExprLogicalOr) IsFloat

func (e *ExprLogicalOr) IsFloat() bool

func (*ExprLogicalOr) MarshalYAML

func (e *ExprLogicalOr) MarshalYAML() (any, error)

func (*ExprLogicalOr) TypeDesignation

func (e *ExprLogicalOr) TypeDesignation() string

type ExprModulo

type ExprModulo struct {
	LocRange
	Parent   Expression
	Dividend Expression
	Divisor  Expression
	Float    bool
}

ExprModulo is a modulo expression using the operator "%".

func (*ExprModulo) GetLocation

func (e *ExprModulo) GetLocation() LocRange

func (*ExprModulo) GetParent

func (e *ExprModulo) GetParent() Expression

func (*ExprModulo) IsFloat

func (e *ExprModulo) IsFloat() bool

func (*ExprModulo) MarshalYAML

func (e *ExprModulo) MarshalYAML() (any, error)

func (*ExprModulo) TypeDesignation

func (e *ExprModulo) TypeDesignation() string

type ExprMultiplication

type ExprMultiplication struct {
	LocRange
	Parent        Expression
	Multiplicant  Expression
	Multiplicator Expression
	Float         bool
}

ExprMultiplication is an arithmetic multiplication expression using the operator "*".

func (*ExprMultiplication) GetLocation

func (e *ExprMultiplication) GetLocation() LocRange

func (*ExprMultiplication) GetParent

func (e *ExprMultiplication) GetParent() Expression

func (*ExprMultiplication) IsFloat

func (e *ExprMultiplication) IsFloat() bool

func (*ExprMultiplication) MarshalYAML

func (e *ExprMultiplication) MarshalYAML() (any, error)

func (*ExprMultiplication) TypeDesignation

func (e *ExprMultiplication) TypeDesignation() string

type ExprNotEqual

type ExprNotEqual struct {
	LocRange
	Parent Expression
	Left   Expression
	Right  Expression
}

ExprNotEqual is a boolean inequality expression using the operator "!=".

func (*ExprNotEqual) GetLocation

func (e *ExprNotEqual) GetLocation() LocRange

func (*ExprNotEqual) GetParent

func (e *ExprNotEqual) GetParent() Expression

func (*ExprNotEqual) IsFloat

func (e *ExprNotEqual) IsFloat() bool

func (*ExprNotEqual) MarshalYAML

func (e *ExprNotEqual) MarshalYAML() (any, error)

func (*ExprNotEqual) TypeDesignation

func (e *ExprNotEqual) TypeDesignation() string

type ExprNumericNegation

type ExprNumericNegation struct {
	LocRange
	Parent     Expression
	Expression Expression
	Float      bool
}

ExprNumericNegation is a numeric negation expression using the prefix operator "-".

func (*ExprNumericNegation) GetLocation

func (e *ExprNumericNegation) GetLocation() LocRange

func (*ExprNumericNegation) GetParent

func (e *ExprNumericNegation) GetParent() Expression

func (*ExprNumericNegation) IsFloat

func (e *ExprNumericNegation) IsFloat() bool

func (*ExprNumericNegation) MarshalYAML

func (e *ExprNumericNegation) MarshalYAML() (any, error)

func (*ExprNumericNegation) TypeDesignation

func (e *ExprNumericNegation) TypeDesignation() string

type ExprParentheses

type ExprParentheses struct {
	LocRange
	Parent     Expression
	Expression Expression
}

ExprParentheses is an expression enclosed by parentheses.

func (*ExprParentheses) GetLocation

func (e *ExprParentheses) GetLocation() LocRange

func (*ExprParentheses) GetParent

func (e *ExprParentheses) GetParent() Expression

func (*ExprParentheses) IsFloat

func (e *ExprParentheses) IsFloat() bool

func (*ExprParentheses) MarshalYAML

func (e *ExprParentheses) MarshalYAML() (any, error)

func (*ExprParentheses) TypeDesignation

func (e *ExprParentheses) TypeDesignation() string

type ExprSubtraction

type ExprSubtraction struct {
	LocRange
	Parent     Expression
	Minuend    Expression
	Subtrahend Expression
	Float      bool
}

ExprSubtraction is an arithmetic subtraction expression using the operator "-".

func (*ExprSubtraction) GetLocation

func (e *ExprSubtraction) GetLocation() LocRange

func (*ExprSubtraction) GetParent

func (e *ExprSubtraction) GetParent() Expression

func (*ExprSubtraction) IsFloat

func (e *ExprSubtraction) IsFloat() bool

func (*ExprSubtraction) MarshalYAML

func (e *ExprSubtraction) MarshalYAML() (any, error)

func (*ExprSubtraction) TypeDesignation

func (e *ExprSubtraction) TypeDesignation() string

type Expression

type Expression interface {
	GetParent() Expression
	GetLocation() LocRange
	TypeDesignation() string
	IsFloat() bool
}

Expression can be either of:

  • *Operation
  • *ConstrAny
  • *ConstrEquals
  • *ConstrNotEquals
  • *ConstrLess
  • *ConstrLessOrEqual
  • *ConstrGreater
  • *ConstrGreaterOrEqual
  • *ConstrLenEquals
  • *ConstrLenNotEquals
  • *ConstrLenLess
  • *ConstrLenLessOrEqual
  • *ConstrLenGreater
  • *ConstrLenGreaterOrEqual
  • *ConstrMap
  • *ExprParentheses
  • *ExprModulo
  • *ExprDivision
  • *ExprMultiplication
  • *ExprAddition
  • *ExprSubtraction
  • *ExprLogicalNegation
  • *ExprNumericNegation
  • *ExprEqual
  • *ExprNotEqual
  • *ExprLess
  • *ExprLessOrEqual
  • *ExprGreater
  • *ExprGreaterOrEqual
  • *ExprLogicalAnd
  • *ExprLogicalOr
  • *True
  • *False
  • *Int
  • *Float
  • *String
  • *Null
  • *Enum
  • *Array
  • *Object
  • *Variable
  • *SelectionInlineFrag
  • *ObjectField
  • *SelectionField
  • *SelectionMax
  • *Argument

func Optimize

func Optimize(e Expression) Expression

Optimize recursively reduces all constant expressions inside e. For example, an addition expression where the left and right addends are constant or reducable expressions will be reduced to, or in other words, replaced with a single constant containing the resulting sum.

type False

type False struct {
	LocRange
	Parent  Expression
	TypeDef *ast.Definition
}

False is a boolean value constant.

func (*False) GetLocation

func (e *False) GetLocation() LocRange

func (*False) GetParent

func (e *False) GetParent() Expression

func (*False) IsFloat

func (e *False) IsFloat() bool

func (*False) MarshalYAML

func (e *False) MarshalYAML() (any, error)

func (*False) TypeDesignation

func (e *False) TypeDesignation() string

type LocRange

type LocRange struct {
	Location
	LocationEnd
}

LocRange defines the start and end locations of an expression.

func (LocRange) MarshalYAML

func (s LocRange) MarshalYAML() (any, error)

type Location

type Location struct{ Index, Line, Column int }

Location defines the start location of an expression.

type LocationEnd

type LocationEnd struct{ IndexEnd, LineEnd, ColumnEnd int }

LocationEnd defines the end location of an expression.

type Name

type Name struct {
	LocRange
	Name string
}

func (Name) MarshalYAML

func (n Name) MarshalYAML() (any, error)

type Null

type Null struct {
	LocRange
	Parent Expression
	Type   *ast.Type
}

Null is a null-value constant.

func (*Null) GetLocation

func (e *Null) GetLocation() LocRange

func (*Null) GetParent

func (e *Null) GetParent() Expression

func (*Null) IsFloat

func (e *Null) IsFloat() bool

func (*Null) MarshalYAML

func (n *Null) MarshalYAML() (any, error)

func (*Null) TypeDesignation

func (e *Null) TypeDesignation() string

type Number

type Number struct {
	LocRange
	Parent  Expression
	Value   string
	TypeDef *ast.Definition
	// contains filtered or unexported fields
}

func (*Number) Float

func (n *Number) Float() (f float64, ok bool)

Float returns the float64 value and true if the number is of type Float, otherwise returns 0 and false.

func (*Number) GetLocation

func (e *Number) GetLocation() LocRange

func (*Number) GetParent

func (e *Number) GetParent() Expression

func (*Number) Int

func (n *Number) Int() (f int, ok bool)

Int returns the integer value and true if the number is of type Int, otherwise returns 0 and false.

func (*Number) IsFloat

func (e *Number) IsFloat() bool

func (*Number) MarshalYAML

func (n *Number) MarshalYAML() (any, error)

func (*Number) TypeDesignation

func (n *Number) TypeDesignation() string

type Object

type Object struct {
	LocRange
	Parent  Expression
	Fields  []*ObjectField
	TypeDef *ast.Definition
}

Object is an input object constraint.

func (*Object) GetLocation

func (e *Object) GetLocation() LocRange

func (*Object) GetParent

func (e *Object) GetParent() Expression

func (*Object) IsFloat

func (e *Object) IsFloat() bool

func (*Object) MarshalYAML

func (o *Object) MarshalYAML() (any, error)

func (*Object) TypeDesignation

func (e *Object) TypeDesignation() string

type ObjectField

type ObjectField struct {
	LocRange
	Name
	Parent             Expression
	AssociatedVariable *VariableDeclaration
	Constraint         Expression
	Def                *ast.FieldDefinition
}

ObjectField is an input object field.

func (*ObjectField) GetLocation

func (e *ObjectField) GetLocation() LocRange

func (*ObjectField) GetParent

func (e *ObjectField) GetParent() Expression

func (*ObjectField) IsFloat

func (e *ObjectField) IsFloat() bool

func (*ObjectField) MarshalYAML

func (f *ObjectField) MarshalYAML() (any, error)

func (*ObjectField) TypeDesignation

func (e *ObjectField) TypeDesignation() string

type Operation

type Operation struct {
	LocRange
	Type OperationType
	SelectionSet
	Def *ast.Definition
}

Operation is the root of the abstract syntax tree of an operation.

func (*Operation) GetLocation

func (e *Operation) GetLocation() LocRange

func (*Operation) GetParent

func (e *Operation) GetParent() Expression

func (*Operation) IsFloat

func (e *Operation) IsFloat() bool

func (*Operation) MarshalYAML

func (o *Operation) MarshalYAML() (any, error)

func (*Operation) TypeDesignation

func (e *Operation) TypeDesignation() string

type OperationType

type OperationType int8
const (
	OperationTypeQuery OperationType
	OperationTypeMutation
	OperationTypeSubscription
)

func (OperationType) String

func (t OperationType) String() string

type Parser

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

Parser is a GQT parser.

func NewParser

func NewParser(schema []Source) (*Parser, error)

NewParser reads a GraphQL schema from given sources (if any) and returns a new Parser instance that will parse in schema-aware mode, according to the specified schema. Returns schemaless parser instance if no sources are provided.

func (*Parser) Parse

func (p *Parser) Parse(src []byte) (
	operation *Operation,
	variables map[string]*VariableDeclaration,
	errors []Error,
)

Parse parses the template and returns its abstract syntax tree.

type Selection

type Selection Expression

Selection can be either of:

  • *SelectionField
  • *SelectionInlineFrag
  • *SelectionMax

type SelectionField

type SelectionField struct {
	LocRange
	Name
	Parent Expression
	ArgumentList
	SelectionSet
	Def *ast.FieldDefinition
}

SelectionField is a field selection.

func (*SelectionField) GetLocation

func (e *SelectionField) GetLocation() LocRange

func (*SelectionField) GetParent

func (e *SelectionField) GetParent() Expression

func (*SelectionField) IsFloat

func (e *SelectionField) IsFloat() bool

func (*SelectionField) MarshalYAML

func (s *SelectionField) MarshalYAML() (any, error)

func (*SelectionField) TypeDesignation

func (e *SelectionField) TypeDesignation() string

type SelectionInlineFrag

type SelectionInlineFrag struct {
	LocRange
	Parent        Expression
	TypeCondition TypeCondition
	SelectionSet
}

SelectionInlineFrag is an inline fragment.

func (*SelectionInlineFrag) GetLocation

func (e *SelectionInlineFrag) GetLocation() LocRange

func (*SelectionInlineFrag) GetParent

func (e *SelectionInlineFrag) GetParent() Expression

func (*SelectionInlineFrag) IsFloat

func (e *SelectionInlineFrag) IsFloat() bool

func (*SelectionInlineFrag) MarshalYAML

func (s *SelectionInlineFrag) MarshalYAML() (any, error)

func (*SelectionInlineFrag) TypeDesignation

func (e *SelectionInlineFrag) TypeDesignation() string

type SelectionMax

type SelectionMax struct {
	LocRange
	Parent  Expression
	Limit   int
	Options SelectionSet
}

SelectionMax is the max selection set.

func (*SelectionMax) GetLocation

func (e *SelectionMax) GetLocation() LocRange

func (*SelectionMax) GetParent

func (e *SelectionMax) GetParent() Expression

func (*SelectionMax) IsFloat

func (e *SelectionMax) IsFloat() bool

func (*SelectionMax) MarshalYAML

func (e *SelectionMax) MarshalYAML() (any, error)

func (*SelectionMax) TypeDesignation

func (e *SelectionMax) TypeDesignation() string

type SelectionSet

type SelectionSet struct {
	LocRange
	Selections []Selection
}

SelectionSet is a selection set.

func (SelectionSet) MarshalYAML

func (s SelectionSet) MarshalYAML() (any, error)

type Source

type Source struct {
	Name    string
	Content string
}

Source is a GraphQL schema source file.

type String

type String struct {
	LocRange
	Parent  Expression
	Value   string
	TypeDef *ast.Definition
}

String is a UTF-8 string value constant.

func (*String) GetLocation

func (e *String) GetLocation() LocRange

func (*String) GetParent

func (e *String) GetParent() Expression

func (*String) IsFloat

func (e *String) IsFloat() bool

func (*String) MarshalYAML

func (s *String) MarshalYAML() (any, error)

func (*String) TypeDesignation

func (e *String) TypeDesignation() string

type True

type True struct {
	LocRange
	Parent  Expression
	TypeDef *ast.Definition
}

True is a boolean value constant.

func (*True) GetLocation

func (e *True) GetLocation() LocRange

func (*True) GetParent

func (e *True) GetParent() Expression

func (*True) IsFloat

func (e *True) IsFloat() bool

func (*True) MarshalYAML

func (e *True) MarshalYAML() (any, error)

func (*True) TypeDesignation

func (e *True) TypeDesignation() string

type TypeCondition

type TypeCondition struct {
	LocRange
	TypeName string
	TypeDef  *ast.Definition
}

TypeCondition is the type condition inside an inline fragment.

func (TypeCondition) MarshalYAML

func (c TypeCondition) MarshalYAML() (any, error)

type Variable

type Variable struct {
	LocRange
	Name
	Parent      Expression
	Declaration *VariableDeclaration
}

Variable is a named value placeholder.

func (*Variable) GetLocation

func (e *Variable) GetLocation() LocRange

func (*Variable) GetParent

func (e *Variable) GetParent() Expression

func (*Variable) IsFloat

func (e *Variable) IsFloat() bool

func (*Variable) MarshalYAML

func (r *Variable) MarshalYAML() (any, error)

func (*Variable) TypeDesignation

func (e *Variable) TypeDesignation() string

type VariableDeclaration

type VariableDeclaration struct {
	LocRange

	Name string

	// References can be any of:
	//   • *Argument
	//   • *ObjectField
	References []Expression

	// Parent can be any of:
	//   • *Argument
	//   • *ObjectField
	Parent Expression
}

func (*VariableDeclaration) GetInfo

func (v *VariableDeclaration) GetInfo() (
	schemaType *ast.Type,
	constr Expression,
)

GetInfo returns the schema-type and constraint expression of the value behind the variable.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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