schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// QuerySchema gets basic info about the schema
	QuerySchema = `query { __schema { mutationType { name } queryType { name } subscriptionType { name } } }`

	// QuerySchemaTypes is used to fetch all of the data types in the schema
	QuerySchemaTypes = `query { __schema { types { ...FullType } } }` + " " + fragmentFullType

	// QueryType returns all of the data on that specific type, useful for fetching queries / mutations
	QueryType = `query($typeName:String!) { __type(name: $typeName) { ...FullType } }` + " " + fragmentFullType
)

https://github.com/graphql/graphql-js/blob/master/src/utilities/getIntrospectionQuery.js#L35

Modified from the following as we only care about the Types
query IntrospectionQuery {
  __schema {
    directives { name description locations args { ...InputValue } }
    mutationType { name }
    queryType { name }
    subscriptionType { name }
    types { ...FullType }
  }
}

Variables

This section is empty.

Functions

func ExpandType

func ExpandType(s *Schema, t *Type) (*[]*Type, error)

ExpandType receives a Type which is used to determine the Type for all nested fields.

func ExpandTypes

func ExpandTypes(s *Schema, types []config.TypeConfig, methods []config.MethodConfig) (*[]*Type, error)

ExpandTypes receives a set of config.TypeConfig, which is then expanded to include all the nested types from the fields.

Types

type EnumValue

type EnumValue struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Kind        Kind   `json:"kind,omitempty"`

	IsDeprecated      bool   `json:"isDeprecated"`
	DeprecationReason string `json:"deprecationReason"`
}

func (*EnumValue) GetDescription

func (e *EnumValue) GetDescription() string

GetDescription formats the description into a GoDoc comment.

func (*EnumValue) GetName

func (e *EnumValue) GetName() string

GetName returns a recusive lookup of the type name

type Field

type Field struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Kind        Kind   `json:"kind,omitempty"`

	Type         TypeRef     `json:"type"`
	Args         []Field     `json:"args,omitempty"`
	DefaultValue interface{} `json:"defaultValue,omitempty"`
}

Field is an attribute of a schema Type object.

func (*Field) GetDescription

func (f *Field) GetDescription() string

GetDescription formats the description into a GoDoc comment.

func (*Field) GetName

func (f *Field) GetName() string

GetName returns a recusive lookup of the type name

func (*Field) GetTags

func (f *Field) GetTags() string

GetTags is used to return the Go struct tags for a field.

func (*Field) GetTypeNameWithOverride

func (f *Field) GetTypeNameWithOverride(pkgConfig *config.PackageConfig) (string, error)

GetTypeNameWithOverride returns the typeName, taking into consideration any FieldTypeOverride specified in the PackageConfig.

type Kind

type Kind string
const (
	KindENUM        Kind = "ENUM"
	KindInputObject Kind = "INPUT_OBJECT"
	KindInterface   Kind = "INTERFACE"
	KindList        Kind = "LIST"
	KindNonNull     Kind = "NON_NULL"
	KindObject      Kind = "OBJECT"
	KindScalar      Kind = "SCALAR"
)

type MutationInfo

type MutationInfo struct {
	Name string `yaml:"name"`
}

type QueryInfo

type QueryInfo struct {
	Name string `yaml:"name"`
}

type QueryResponse

type QueryResponse struct {
	Data struct {
		Type   Type   `json:"__type"`
		Schema Schema `json:"__schema"`
	} `json:"data"`
}

func ParseResponse

func ParseResponse(resp *http.Response) (*QueryResponse, error)

type QueryTypeVars

type QueryTypeVars struct {
	Name string `json:"typeName"`
}

Helper function to make queries, lives here with the constant query

type Schema

type Schema struct {
	MutationType     *Type   `json:"mutationType,omitempty"`
	QueryType        *Type   `json:"queryType,omitempty"`
	SubscriptionType *Type   `json:"subscriptionType,omitempty"`
	Types            []*Type `json:"types,omitempty"`
}

Schema contains data about the GraphQL schema as returned by the server

func Load

func Load(file string) (*Schema, error)

Load takes a file and unmarshals the JSON into a Schema struct

func (*Schema) LookupTypeByName

func (s *Schema) LookupTypeByName(typeName string) (*Type, error)

LookupTypeByName digs in the schema for a type that matches the given name.

func (*Schema) Save

func (s *Schema) Save(file string) error

Save writes the schema out to a file for later use.

type SubscriptionInfo

type SubscriptionInfo struct {
	Name string `yaml:"name"`
}

type Type

type Type struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Kind        Kind   `json:"kind,omitempty"`

	EnumValues    []EnumValue `json:"enumValues,omitempty"`
	Fields        []Field     `json:"fields,omitempty"`
	InputFields   []Field     `json:"inputFields,omitempty"`
	Interfaces    []TypeRef   `json:"interfaces,omitempty"`
	PossibleTypes []TypeRef   `json:"possibleTypes,omitempty"`
}

Type defines a specific type within the schema

func (*Type) GetDescription

func (t *Type) GetDescription() string

GetDescription formats the description into a GoDoc comment.

func (*Type) GetName

func (t *Type) GetName() string

GetName returns the name of a Type, formatted for Go title casing.

func (*Type) IsGoType

func (t *Type) IsGoType() bool

IsGoType is used to determine if a type in NerdGraph is already a native type of Golang.

func (*Type) Save

func (t *Type) Save(file string) error

Save writes the schema out to a file

type TypeRef

type TypeRef struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Kind        Kind   `json:"kind,omitempty"`

	OfType *TypeRef `json:"ofType,omitempty"`
}

TypeRef is a GraphQL reference to a Type.

func (*TypeRef) GetDescription

func (r *TypeRef) GetDescription() string

GetDescription looks for anything in the description before \n\n---\n and filters off anything after that (internal messaging that is not useful here)

func (*TypeRef) GetKinds

func (r *TypeRef) GetKinds() []Kind

GetKinds returns an array or the type kind

func (*TypeRef) GetName

func (r *TypeRef) GetName() string

GetName returns a recusive lookup of the type name

func (*TypeRef) GetType

func (r *TypeRef) GetType() (string, bool, error)

GetType resolves the given SchemaInputField into a field name to use on a go struct.

type, recurse, error

func (*TypeRef) GetTypeName

func (r *TypeRef) GetTypeName() string

GetTypeName returns the name of the current type, or performs a recursive lookup to determine the name of the nested OfType object's name. In the case that neither are matched, the string "UNKNOWN" is returned. In the GraphQL schema, a non-empty name seems to appear only once in a TypeRef tree, so we want to find the first non-empty.

func (*TypeRef) IsList

func (r *TypeRef) IsList() bool

IsList determines if a TypeRef is of a KIND LIST.

Jump to

Keyboard shortcuts

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