...

Source file src/github.com/udacity/graphb/error.go

Documentation: github.com/udacity/graphb

     1  package graphb
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  type nameType string
     8  
     9  const (
    10  	operationName nameType = "operation name"
    11  	aliasName     nameType = "alias name"
    12  	fieldName     nameType = "field name"
    13  	argumentName  nameType = "argument name"
    14  )
    15  
    16  // InvalidNameErr is returned when an invalid name is used. In GraphQL, operation, alias, field and argument all have names.
    17  // A valid name matches ^[_A-Za-z][_0-9A-Za-z]*$ exactly.
    18  type InvalidNameErr struct {
    19  	Type nameType
    20  	Name string
    21  }
    22  
    23  func (e InvalidNameErr) Error() string {
    24  	return fmt.Sprintf("'%s' is an invalid %s in GraphQL. A valid name matches /[_A-Za-z][_0-9A-Za-z]*/, see: http://facebook.github.io/graphql/October2016/#sec-Names", e.Name, e.Type)
    25  }
    26  
    27  // InvalidOperationTypeErr is returned when the operation is not one of query, mutation and subscription.
    28  type InvalidOperationTypeErr struct {
    29  	Type operationType
    30  }
    31  
    32  func (e InvalidOperationTypeErr) Error() string {
    33  	return fmt.Sprintf("'%s' is an invalid operation type in GraphQL. A valid type is one of 'query', 'mutation', 'subscription'", e.Type)
    34  }
    35  
    36  // NilFieldErr is returned when any field is nil. Of course the author could choose to ignore nil fields. But, author chose a stricter construct.
    37  type NilFieldErr struct{}
    38  
    39  func (e NilFieldErr) Error() string {
    40  	return "nil Field is not allowed. Please initialize a correct Field with NewField(...) function or Field{...} literal"
    41  }
    42  
    43  // CyclicFieldErr is returned when any field contains a loop which goes back to itself.
    44  type CyclicFieldErr struct {
    45  	Field Field
    46  }
    47  
    48  func (e CyclicFieldErr) Error() string {
    49  	return fmt.Sprintf("Field %+v contains cyclic loop", e.Field)
    50  }
    51  
    52  // ArgumentTypeNotSupportedErr is returned when user tries to pass an unsupported type to ArgumentAny.
    53  type ArgumentTypeNotSupportedErr struct {
    54  	Value interface{}
    55  }
    56  
    57  func (e ArgumentTypeNotSupportedErr) Error() string {
    58  	return fmt.Sprintf("Argument %+v of Type %T is not supported", e.Value, e.Value)
    59  }
    60  

View as plain text