entx

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package entx is a package of tools for interacting with ent. Providing tools to make generating federated gql easier, working with JSON values in ent, and provided helpers for using idx as your ID on types.

Index

Constants

View Source
const CopyrightHeader string = `` /* 647-byte string literal not displayed */

Variables

View Source
var (
	// FederationTemplate adds support for generating the required output to support gql federation
	FederationTemplate = parseT("template/gql_federation.tmpl")

	// NamespacedDataWhereFuncsTemplate adds support for generating <T>WhereInput filters for schema types using the NamespacedData mixin
	NamespacedDataWhereFuncsTemplate = parseT("template/namespaceddata_where_funcs.tmpl")

	// TemplateFuncs contains the extra template functions used by entx.
	TemplateFuncs = template.FuncMap{}

	// MixinTemplates includes all templates for extending ent to support entx mixins.
	MixinTemplates = []*gen.Template{
		NamespacedDataWhereFuncsTemplate,
	}
)
View Source
var AnnotationName = "I12R_ENTX"

AnnotationName is the value of the annotation when read during ent compilation

Functions

func GraphKeyDirective

func GraphKeyDirective(fields string) entgql.Annotation

GraphKeyDirective returns an entgql.Directive for setting the @key field on a graphql type

func MarshalRawMessage

func MarshalRawMessage(t json.RawMessage) graphql.Marshaler

MarshalRawMessage provides a graphql.Marshaler for json.RawMessage

func UnmarshalRawMessage

func UnmarshalRawMessage(v interface{}) (json.RawMessage, error)

UnmarshalRawMessage provides a graphql.Unmarshaler for json.RawMessage

Types

type Annotation

type Annotation struct {
	IsNamespacedDataJSONField bool
}

Annotation provides a ent.Annotaion spec

func (Annotation) Name

func (a Annotation) Name() string

Name implements the ent Annotation interface.

type Extension

type Extension struct {
	entc.DefaultExtension
	// contains filtered or unexported fields
}

Extension is an implementation of entc.Extension that adds all the templates that entx needs.

func NewExtension

func NewExtension(opts ...ExtensionOption) (*Extension, error)

NewExtension returns an entc Extension that allows the entx package to generate the schema changes and templates needed to function

func (*Extension) GQLSchemaHooks

func (e *Extension) GQLSchemaHooks() []entgql.SchemaHook

GQLSchemaHooks of the extension to seamlessly edit the final gql interface.

func (*Extension) Templates

func (e *Extension) Templates() []*gen.Template

Templates of the extension

type ExtensionOption

type ExtensionOption func(*Extension) error

ExtensionOption allow for control over the behavior of the generator

func WithFederation

func WithFederation() ExtensionOption

WithFederation adds support for graphql federation by adding the Entity interface to all types, as well as removing the node() and nodes() query calls.

func WithJSONScalar

func WithJSONScalar() ExtensionOption

WithJSONScalar adds the JSON scalar definition

type NamespacedDataMixin

type NamespacedDataMixin struct {
	mixin.Schema
}

NamespacedDataMixin defines an ent Mixin that captures raw json associated with a namespace.

func (NamespacedDataMixin) Fields

func (m NamespacedDataMixin) Fields() []ent.Field

Fields provides the namespace and data fields used in this mixin.

type TimestampsMixin

type TimestampsMixin interface {
	ent.Mixin
	CreatedAtAnnotations(...schema.Annotation) TimestampsMixin
	UpdatedAtAnnotations(...schema.Annotation) TimestampsMixin
}

TimestampsMixin defines an interface of a Mixin that provides the created_at and updated_at timestamp fields

func NewTimestampMixin

func NewTimestampMixin() TimestampsMixin

NewTimestampMixin returns a Mixin that provides the created_at and updated_at timestamp fields

Jump to

Keyboard shortcuts

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