Documentation ¶
Index ¶
Constants ¶
const ( ActionGet = "get" ActionList = "list" ActionUpdate = "update" ActionDelete = "delete" ActionInsert = "insert" )
Constants for resolver actions
Variables ¶
var ( ErrFieldHasNoName = errors.New("fields must have a 'name' attribute") ErrFieldHasBadTypeDefinition = errors.New("field has bad type definition, must be <type> or [<type>]") ErrTypeAndResolver = errors.New("field cannot declare Type and Resolver") )
Custom errors
var GeneratedFilesPath = "./generated"
GeneratedFilesPath defines where to put files created from parsing the schema
Functions ¶
This section is empty.
Types ¶
type DynamoKeyType ¶
DynamoKeyType represents a key with type
type DynamoSource ¶
type DynamoSource struct { HashKey *DynamoKeyType `yaml:"hash_key"` SortKey *DynamoKeyType `yaml:"sort_key,omitempty"` Backup bool `yaml:"backup,omitempty"` }
DynamoSource represents a dynamo db data source
type Field ¶
type Field struct { Name string // (Optional) Type defines the scalar or object type of the field. If a type is not // specified, it will default to the `String` scalar type if not set and // Resolver has not been specified // Must specify exactly one of Type OR Resolver Type *FieldType // (Optional) Only applicable when used as a field is used as a key in // a nested resolver. It gives the name of the field in the parent to // be used as the key to the nested data source. Parent string // (Optional) Define a resolver to fetch the value for this field // Resolver *Resolver `yaml:"resolver,omitempty"` // Must specify exactly one of Type OR Resolver Resolver *Resolver // (Optional) Type to be used when this field is included in an input // object definition if it differs from the main defined type InputType *FieldType }
Field represents a field of a graphql object
func (*Field) IsLegalScalarType ¶
IsLegalScalarType tests whether a the field is defined with one of the allowable graphql (and AWS) scalar types
func (*Field) UnmarshalYAML ¶
UnmarshalYAML satisfies the custom unmarshaler interface for go-yaml. It's called automatically by the unmarshaler to ensure default values get set where they haven't been supplied in the user's definition.
type FieldType ¶
FieldType represents the type associated with a field.
func (*FieldType) UnmarshalYAML ¶
UnmarshalYAML satisfies the custom unmarshaler interface for go-yaml. It is called automatically by the YAML unmarshal to deal with the [] list notation in field type definitions as they need to be read as scalar values, not YAML lists.
type FilterObject ¶
type FilterObject Object
FilterObject is generated from a base object and used to filter queries
func NewFilterFromObject ¶
func NewFilterFromObject(o *Object) *FilterObject
NewFilterFromObject creates a new filter object input type from an existing Object definition. Fields that can't be (currently) filtered (custom types and embedded objects) are omitted. Non-standard, but mappable, types are translated to simple scalar types
type FilterObjectList ¶
type FilterObjectList []*FilterObject
FilterObjectList is a list type containing FilterObjects
type InputObject ¶
type InputObject Object
InputObject is generated from a base object and used for mutation queries
func NewInputFromObject ¶
func NewInputFromObject(o *Object, action string) (*InputObject, error)
NewInputFromObject creates a new input object type from an existing Object definition. Fields that can't be (currently) filtered (custom types and embedded objects) are omitted. Non-standard, but mappable, types are translated to simple scalar types
type InputObjectList ¶
type InputObjectList []*InputObject
InputObjectList is a list type containing InputObjects
type Query ¶
type Query struct { Name string `yaml:"name"` Type *FieldType `yaml:"type"` Resolver *Resolver `yaml:"resolver"` }
Query represents the definition for a graphql query
Query { - name: <query_name> type: <return_type> resolver: action: <get|list|insert|update> source: <source_name> # optional ... }
type Resolver ¶
type Resolver struct { // The Action for the resolver to perform - get, list, insert, update, delete Action string `yaml:"action"` // The graphql type that the resolver returns. Where this resolver action // is other than get or delete, set this to be the base object type. // Appropriate "Input" variants of the object will then be defined. // Where the action is "list", the base type will also have an associated // "Connection" object defined. // Type string `yaml:"type"` Type *FieldType `yaml:"type"` // Set of fields to be used as keys in the query (primary key etc) KeyFields []*Field `yaml:"keyFields"` // Name of the datasource to be used for this resolver. Must have // been defined in the `sources` section of the manifest SourceKey string `yaml:"source"` // The below are set automatically as the schema is parsed. They should // not be included in the manifest YAML. DataSource *Source // Key to a datasource defined in the manifest ArgsSource string // $ctx.{{ArgSource}}.get() - "args" or "source" Parent string // Parent field FieldName string // Field name attached to }
Resolver is the represenatation of a field resolver
func (*Resolver) GenerateBytes ¶
GenerateBytes renders the resolver ready to be written to an output stream
func (*Resolver) KeyFieldArgsString ¶
KeyFieldArgsString returns the keyfield names and types in a string format suitable to be used as the arguments list in a resolver defintion in the schemea
func (*Resolver) KeyFieldJSONList ¶
KeyFieldJSONList converts the `KeyFields` into a JSON formatted list of names
func (*Resolver) KeyFieldJSONMap ¶
KeyFieldJSONMap converts the `KeyFields` into a JSON formatted map
func (*Resolver) OutputName ¶
OutputName returns the file name to be written for the resolver
type SQLSource ¶
type SQLSource struct {
PrimaryKey string `yaml:"primary_key"`
}
SQLSource represents a sql based db data source
type Schema ¶
type Schema struct { Enums []*Enum `yaml:"enums"` Objects []*Object `yaml:"objects"` Queries []*Query `yaml:"queries"` Mutations []*Mutation `yaml:"mutations"` Sources map[string]*Source `yaml:"sources"` // Automatically populated to create // filtering options for list types FilterInputs []string // Connection objects to be built - populated automatically by "list" resolvers Connections []string FilterObjects FilterObjectList InputObjects InputObjectList // Contains any errors raised during the generation process Errors []error // contains filtered or unexported fields }
Schema represents the elements of a graphql schema
func NewSchemaFromManifest ¶
NewSchemaFromManifest parses a schema manifest in YAML format and generates a new schema struct
func (*Schema) AddFilterFromObject ¶
AddFilterFromObject adds a new filter object definition to the schema
func (*Schema) AddInputFromObject ¶
AddInputFromObject adds a new filter object definition to the schema
func (*Schema) CleanOutput ¶
CleanOutput empties the output path
func (*Schema) GenerateBytes ¶
GenerateBytes renders the schema to a bytes buffer ready to be writen to an output stream
func (*Schema) OutputName ¶
OutputName returns the file name to be written for the schema
type Source ¶
type Source struct { Name string `yaml:"name"` Dynamo *DynamoSource `yaml:"dynamo"` SQL *SQLSource `yaml:"sql"` // Set automatically Type string }
Source is a datasource configuration
func (*Source) GenerateBytes ¶
GenerateBytes renders the datasource ready to be written to the output stream
func (*Source) OutputName ¶
OutputName returns the file name to be written for the data source
func (*Source) UnmarshalYAML ¶
UnmarshalYAML satisfies the custom unmarshaler interface for go-yaml. It is called automatically by the YAML unmarshal.