graphcms

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetNode

type AssetNode struct {
	TypeName string `json:"__typename"`
	ID       string `json:"id"`
	Handle   string `json:"handle"`
	URL      string `json:"url"`
}

AssetNode simple content struct

type GraphCMS

type GraphCMS struct {
	NodeTypes    []string
	SpecialCases map[string]string
	Debug        bool
	Verbose      bool
	Exceptions   map[string]string
	RenderData   GraphResponse
	// contains filtered or unexported fields
}

GraphCMS struct

func (*GraphCMS) Backup

func (g *GraphCMS) Backup()

Backup content and schemas from GraphCMS

func (*GraphCMS) CallGraphAPI

func (g *GraphCMS) CallGraphAPI(requestQuery string, requestVars string) (GraphResponse, error)

CallGraphAPI to make a GraphQL API call with requestQuery & requestVars

func (*GraphCMS) DownloadAssets

func (g *GraphCMS) DownloadAssets(data map[string]interface{})

DownloadAssets loop through nodes, look for assets and download

func (*GraphCMS) DownloadContent

func (g *GraphCMS) DownloadContent()

DownloadContent from GraphCMS

func (*GraphCMS) DownloadEnumerations

func (g *GraphCMS) DownloadEnumerations() error

DownloadEnumerations to a file

func (*GraphCMS) DownloadModels

func (g *GraphCMS) DownloadModels() error

DownloadModels to a file

func (*GraphCMS) DownloadSchemas

func (g *GraphCMS) DownloadSchemas() error

DownloadSchemas to a file. Download both models and enumerations.

func (*GraphCMS) GetAllEnumerations

func (g *GraphCMS) GetAllEnumerations() []interface{}

GetAllEnumerations from the API using introspection This returns numerous ENUMS including any system enumerations

func (*GraphCMS) GetAllNodesByType

func (g *GraphCMS) GetAllNodesByType(name string) map[string]interface{}

GetAllNodesByType will give you all nodes for a given node type. GraphQL does not let you select * like SQL, so we need to take the fields grabbed by introspection and build a graphql query to pull all fields for a given node type (schema model)

func (*GraphCMS) GetEnumeration

func (g *GraphCMS) GetEnumeration(name string) interface{}

GetEnumeration get a single enumeration by name from the API using introspection

func (*GraphCMS) GetEnumerations

func (g *GraphCMS) GetEnumerations() map[string]interface{}

GetEnumerations from the CMS based on enumerations defined in your config

func (*GraphCMS) GetNodeFields

func (g *GraphCMS) GetNodeFields(name string) map[string]interface{}

GetNodeFields returns a single schema as json

func (*GraphCMS) GetNodeTypes

func (g *GraphCMS) GetNodeTypes() []string

GetNodeTypes will get node types from the API using introspection

func (*GraphCMS) GetNodes

func (g *GraphCMS) GetNodes() map[string]interface{}

GetNodes from the cms

func (*GraphCMS) GetSchema

func (g *GraphCMS) GetSchema(name string) (interface{}, error)

GetSchema returns a single schema as json

func (*GraphCMS) GetSchemaQuery

func (g *GraphCMS) GetSchemaQuery(name string) (string, string)

GetSchemaQuery returns a GraphQL query

func (*GraphCMS) GetSchemas

func (g *GraphCMS) GetSchemas() map[string]interface{}

GetSchemas retrives the schema and returns json

func (*GraphCMS) Init

func (g *GraphCMS) Init(url interface{}, key interface{}, stage interface{}, path interface{})

Init initialize config

func (*GraphCMS) IsNodeType

func (g *GraphCMS) IsNodeType(name string) bool

IsNodeType check to see if name is listed as one of the node types

func (*GraphCMS) IsSpecialCase

func (g *GraphCMS) IsSpecialCase(name string) bool

IsSpecialCase field type

func (*GraphCMS) Pluralize

func (g *GraphCMS) Pluralize(name string) string

Pluralize will transform the schema model (node type) name to plural Took the 80/20 rule here and tried to capture the bulk of the cases with minimal logic English can be an ugly language, see rules at https://www.grammarly.com/blog/plural-nouns/

func (*GraphCMS) RenderJson

func (g *GraphCMS) RenderJson(data map[string]interface{}) string

RenderJson converts the incoming data to a formatted json string

func (*GraphCMS) RenderJsonPretty

func (g *GraphCMS) RenderJsonPretty(data map[string]interface{}) string

RenderJsonPretty converts the incoming data to an indented json string

func (*GraphCMS) RenderTemplate

func (g *GraphCMS) RenderTemplate(query string, template string, outputFilename string)

RenderTemplate with CMS data

func (*GraphCMS) SetFlags

func (g *GraphCMS) SetFlags(debug bool, verbose bool)

Set the debug and verbose flags

func (*GraphCMS) WriteFileJSON

func (g *GraphCMS) WriteFileJSON(data map[string]interface{}, folder string, filename string)

WriteFileJSON write json struct to a file

type GraphResponse

type GraphResponse struct {
	Data   map[string]interface{} `json:"data"`
	Errors []struct {
		Message   string        `json:message`
		Locations []interface{} `json:"locations"`
	} `json:"errors"`
}

GraphResponse GraphCMS API response

type NodeFields

type NodeFields struct {
	Type struct {
		Name   string `json:"name"`
		Kind   string `json:"kind"`
		Fields []struct {
			Name        string `json:"name"`
			Description string `json:"description"`
			Args        []struct {
				Name         string `json:"name"`
				Description  string `json:"description"`
				DefaultValue string `json:"defaultValue"`
			} `json:"args"`
			Type struct {
				Name          string         `json:"name"`
				Kind          string         `json:"kind"`
				Description   string         `json:"description"`
				Fields        []NodeSubfield `json:"fields"`
				PossibleTypes []struct {
					Name        string `json:"name"`
					Description string `json:"description"`
				} `json:"possibleTypes"`
				OfType struct {
					Name        string `json:"name"`
					Description string `json:"description"`
				} `json:"ofType"`
				Interfaces []struct {
					Name        string `json:"name"`
					Description string `json:"description"`
					Typename    string `json:"__typename"`
				} `json:"interfaces"`
			} `json:"type"`
		} `json:"fields"`
	} `json:"__type"`
}

NodeFields structure

type NodeSubfield

type NodeSubfield struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Args        []struct {
		Name         string `json:"name"`
		Description  string `json:"description"`
		DefaultValue string `json:"defaultValue"`
	} `json:"args"`
	Type struct {
		Fields []struct {
			Name        string `json:"name"`
			Description string `json:"description"`
			Args        []struct {
				Name        string `json:"name"`
				Description string `json:"description"`
			} `json:"args"`
		} `json:"fields"`
	} `json:"type"`
}

NodeSubfield structure

Jump to

Keyboard shortcuts

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