Documentation ¶
Index ¶
- Constants
- func ExpandTypes(s *Schema, pkgConfig *config.PackageConfig) (*[]*Type, error)
- func PrefixLineTab(s string) string
- type EnumValue
- type Expander
- type Field
- func (f *Field) GetDescription() string
- func (f *Field) GetName() string
- func (f *Field) GetTags() string
- func (f *Field) GetTagsWithOverrides(parentType Type, pkgConfig *config.PackageConfig) string
- func (f *Field) GetTypeNameWithOverride(pkgConfig *config.PackageConfig) (string, error)
- func (f *Field) HasRequiredArg() bool
- func (f *Field) IsEnum() bool
- func (f *Field) IsPrimitiveType() bool
- func (f *Field) IsRequired() bool
- func (f *Field) IsScalarID() bool
- type Kind
- type QueryArg
- type QueryResponse
- type QueryTypeVars
- type Schema
- func (s *Schema) BuildQueryArgsForEndpoint(t *Type, fields []string, includeArguments []string) []QueryArg
- func (s *Schema) GetInputFieldsForQueryPath(queryPath []string) map[string][]Field
- func (s *Schema) GetQueryArg(field Field) QueryArg
- func (s *Schema) GetQueryStringForEndpoint(typePath []*Type, fieldPath []string, endpoint config.EndpointConfig) string
- func (s *Schema) GetQueryStringForMutation(mutation *Field, cfg config.MutationConfig) string
- func (s *Schema) LookupMutationByName(mutationName string) (*Field, error)
- func (s *Schema) LookupMutationsByPattern(pattern string) []Field
- func (s *Schema) LookupQueryFieldsByFieldPath(fieldPath []string) ([]string, error)
- func (s *Schema) LookupQueryTypesByFieldPath(fieldPath []string) ([]*Type, error)
- func (s *Schema) LookupRootMutationTypeFieldByName(name string) (*Field, error)
- func (s *Schema) LookupRootQueryTypeFieldByName(name string) (*Field, error)
- func (s *Schema) LookupTypeByName(typeName string) (*Type, error)
- func (s *Schema) QueryFieldsForTypeName(name string, maxDepth int, isMutation bool, excludeFields []string) string
- func (s *Schema) RecursiveLookupFieldByPath(queryFieldPath []string, obj *Type) *Field
- func (s *Schema) Save(file string) error
- type Type
- func (t *Type) GetDescription() string
- func (t *Type) GetField(name string) (*Field, error)
- func (t *Type) GetName() string
- func (t *Type) GetQueryStringFields(s *Schema, depth, maxDepth int, isMutation bool, excludeFields []string) string
- func (t *Type) IsGoType() bool
- func (t *Type) Save(file string) error
- type TypeRef
- func (r *TypeRef) GetDescription() string
- func (r *TypeRef) GetKinds() []Kind
- func (r *TypeRef) GetName() string
- func (r *TypeRef) GetType() (string, bool, error)
- func (r *TypeRef) GetTypeName() string
- func (r *TypeRef) IsInputObject() bool
- func (r *TypeRef) IsInterface() bool
- func (r *TypeRef) IsList() bool
- func (r *TypeRef) IsNonNull() bool
- func (r *TypeRef) IsScalarID() bool
Constants ¶
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 ExpandTypes ¶
func ExpandTypes(s *Schema, pkgConfig *config.PackageConfig) (*[]*Type, error)
ExpandTypes receives a set of config.TypeConfig, which is then expanded to include all the nested types from the fields.
func PrefixLineTab ¶ added in v0.2.4
PrefixLineTab adds a \t character to the beginning of each line.
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 ¶
GetDescription formats the description into a GoDoc comment.
type Expander ¶ added in v0.2.4
Expander is mean to hold the state while the schema is being expanded.
func NewExpander ¶ added in v0.2.4
NewExpander is to return a sane Expander.
func (*Expander) ExpandType ¶ added in v0.2.4
ExpandType is used to populate the expander, one Type at a time.
func (*Expander) ExpandTypeFromName ¶ added in v0.2.4
ExpandTypeFromName will expand a named type if found or error.
func (*Expander) ExpandedTypes ¶ added in v0.2.4
ExpandedTypes is the final report of all the expanded types.
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 ¶
GetDescription formats the description into a GoDoc comment.
func (*Field) GetTagsWithOverrides ¶ added in v0.9.0
func (f *Field) GetTagsWithOverrides(parentType Type, pkgConfig *config.PackageConfig) string
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.
func (*Field) HasRequiredArg ¶ added in v0.4.0
func (*Field) IsPrimitiveType ¶ added in v0.3.0
func (*Field) IsRequired ¶ added in v0.3.0
Convenience method that proxies to TypeRef method
func (*Field) IsScalarID ¶ added in v0.3.0
Convenience method that proxies to TypeRef method
type QueryArg ¶ added in v0.2.4
QueryArg is the key value pair for an nerdgraph query argument on an endpoint. These might be required, or not.
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 (*Schema) BuildQueryArgsForEndpoint ¶ added in v0.3.0
func (s *Schema) BuildQueryArgsForEndpoint(t *Type, fields []string, includeArguments []string) []QueryArg
BuildQueryArgsForEndpoint is meant to fill in the data necessary for a query(<args_go_here>) string. i.e: query($guids: [String]!) { actor ...
func (*Schema) GetInputFieldsForQueryPath ¶ added in v0.3.0
GetInputFieldsForQueryPath is intended to return the fields that are available as input arguments when performing a query using the received query path. For example, a []string{"actor", "account"} would look at `actor { account { ...` for the representivate types at those schema levels and determine collect the available arguments for return.
func (*Schema) GetQueryArg ¶ added in v0.4.0
GetQueryArg returns the GraphQL formatted Query Argument including formatting for List and NonNull
Example:
{ "name": "tags", "type": { "kind": "NON_NULL", "ofType": { "kind": "LIST", "ofType": { "kind": "NON_NULL", "ofType": { "name": "TaggingTagInput", "kind": "INPUT_OBJECT" } } } } } [TaggingTagInput!]!
func (*Schema) GetQueryStringForEndpoint ¶ added in v0.2.4
func (s *Schema) GetQueryStringForEndpoint(typePath []*Type, fieldPath []string, endpoint config.EndpointConfig) string
GetQueryStringForEndpoint packs a nerdgraph query header and footer around the set of query fields for a given type name and endpoint.
func (*Schema) GetQueryStringForMutation ¶ added in v0.2.4
func (s *Schema) GetQueryStringForMutation(mutation *Field, cfg config.MutationConfig) string
GetQueryStringForMutation packs a nerdgraph query header and footer around the set of query fields GraphQL mutation name.
func (*Schema) LookupMutationByName ¶ added in v0.2.4
LookupMutationByName searches for the specific mutation by name and returns a reference if found.
func (*Schema) LookupMutationsByPattern ¶ added in v0.8.0
LookupMutationsByPattern finds all matching mutations given the regexp
func (*Schema) LookupQueryFieldsByFieldPath ¶ added in v0.6.1
LookupQueryFieldsByFieldPath is used to turn a GraphQL field path into Golang struct path
func (*Schema) LookupQueryTypesByFieldPath ¶ added in v0.2.4
LookupQueryTypesByFieldPath is used to retrieve the types, when all you know is the path of field names to an endpoint.
func (*Schema) LookupRootMutationTypeFieldByName ¶ added in v0.3.0
func (*Schema) LookupRootQueryTypeFieldByName ¶ added in v0.3.0
func (*Schema) LookupTypeByName ¶
LookupTypeByName digs in the schema for a type that matches the given name. This is commonly used for retrieving the Type of a TypeRef, since the name is the only piece of data to go on.
func (*Schema) QueryFieldsForTypeName ¶ added in v0.2.4
func (s *Schema) QueryFieldsForTypeName(name string, maxDepth int, isMutation bool, excludeFields []string) string
QueryFieldsForTypeName will lookup a type by the received name, and return the query fields for that type, or log an error and return and empty string. The returned string is used in a mutation, so that the relevant fields are returned once the mutation is performed, or during a query for a given type.
func (*Schema) RecursiveLookupFieldByPath ¶ added in v0.3.0
RecursiveLookupFieldByPath traverses the GraphQL query types based on the provided query fields path which represents a GraphQL query. This method returns the last field of the last "node" of the query tree "branch" - i.e. actor.apiAccess.key where `key` is the primary target "leaf".
e.g. `query { actor { apiAccess { key }}}` would have a path of ["actor", "apiAccess", "key"]
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"` SkipFields []string `json:"skipFields,omitempty"` }
Type defines a specific type within the schema
func (*Type) GetDescription ¶
GetDescription formats the description into a GoDoc comment.
func (*Type) GetQueryStringFields ¶ added in v0.2.4
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 ¶
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) GetType ¶
GetType resolves the given SchemaInputField into a field name to use on a go struct.
type, recurse, error
func (*TypeRef) GetTypeName ¶
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) IsInputObject ¶ added in v0.3.0
func (*TypeRef) IsInterface ¶ added in v0.4.0
IsList determines if a TypeRef is of a KIND INTERFACE.
func (*TypeRef) IsNonNull ¶ added in v0.3.0
IsNonNull walks down looking for NON_NULL kind, however that can appear multiple times, so this is likely a bit deceiving... Example:
{ "name": "tags", "description": "An array of key-values pairs to represent a tag. For example: Team:TeamName.", "type": { "kind": "NON_NULL", "ofType": { "kind": "LIST", "ofType": { "kind": "NON_NULL", "ofType": { "name": "TaggingTagInput", "kind": "INPUT_OBJECT" } } } } } ] }