Documentation ¶
Index ¶
- Constants
- Variables
- func ErrNodeNotFound(id interface{}) *gqlerror.Error
- type Annotation
- func Bind() Annotationdeprecated
- func Directives(directives ...Directive) Annotation
- func Implements(interfaces ...string) Annotation
- func MapsTo(names ...string) Annotation
- func OrderField(name string) Annotation
- func RelayConnection() Annotation
- func Skip(flags ...SkipMode) Annotation
- func Type(name string) Annotation
- func Unbind() Annotation
- type Directive
- type DirectiveArgument
- type Extension
- type ExtensionOption
- func WithConfigPath(path string, gqlgenOptions ...api.Option) ExtensionOption
- func WithMapScalarFunc(scalarFunc func(*gen.Field, gen.Op) string) ExtensionOption
- func WithSchemaGenerator() ExtensionOption
- func WithSchemaHook(hooks ...SchemaHook) ExtensionOption
- func WithSchemaPath(path string) ExtensionOption
- func WithTemplates(templates ...*gen.Template) ExtensionOption
- func WithWhereFilters(b bool) ExtensionOption
- type PaginationNames
- type SchemaHook
- type SkipMode
- type Transactioner
- func (Transactioner) ExtensionName() string
- func (t Transactioner) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response
- func (Transactioner) MutateOperationContext(_ context.Context, oc *graphql.OperationContext) *gqlerror.Error
- func (t Transactioner) Validate(graphql.ExecutableSchema) error
- type TxOpener
- type TxOpenerFunc
Constants ¶
const ( // OrderDirection is the name of enum OrderDirection OrderDirection = "OrderDirection" // RelayCursor is the name of the cursor type RelayCursor = "Cursor" // RelayNode is the name of the interface that all nodes implement RelayNode = "Node" // RelayPageInfo is the name of the PageInfo type RelayPageInfo = "PageInfo" )
Variables ¶
var ( // CollectionTemplate adds fields collection support using auto eager-load ent edges. // More info can be found here: https://spec.graphql.org/June2018/#sec-Field-Collection. CollectionTemplate = parseT("template/collection.tmpl") // EnumTemplate adds a template implementing MarshalGQL/UnmarshalGQL methods for enums. EnumTemplate = parseT("template/enum.tmpl") // NodeTemplate implements the Relay Node interface for all types. NodeTemplate = parseT("template/node.tmpl") // PaginationTemplate adds pagination support according to the GraphQL Cursor Connections Spec. // More info can be found in the following link: https://relay.dev/graphql/connections.htm. PaginationTemplate = parseT("template/pagination.tmpl") // TransactionTemplate adds support for ent.Client for opening transactions for the transaction // middleware. See transaction.go for for information. TransactionTemplate = parseT("template/transaction.tmpl") // EdgeTemplate adds edge resolution using eager-loading with a query fallback. EdgeTemplate = parseT("template/edge.tmpl") // WhereTemplate adds a template for generating <T>WhereInput filters for each schema type. WhereTemplate = parseT("template/where_input.tmpl") // AllTemplates holds all templates for extending ent to support GraphQL. AllTemplates = []*gen.Template{ CollectionTemplate, EnumTemplate, NodeTemplate, PaginationTemplate, TransactionTemplate, EdgeTemplate, } // TemplateFuncs contains the extra template functions used by entgql. TemplateFuncs = template.FuncMap{ "fieldCollections": fieldCollections, "filterEdges": filterEdges, "filterFields": filterFields, "orderFields": orderFields, "filterNodes": filterNodes, "findIDType": findIDType, "nodePaginationNames": nodePaginationNames, "skipMode": skipModeFromString, "isSkipMode": isSkipMode, "isRelayConn": isRelayConn, } )
var ( // ErrRelaySpecDisabled is the error returned when the relay specification is disabled ErrRelaySpecDisabled = errors.New("entgql: must enable relay specification via the WithRelaySpec option") )
Functions ¶
func ErrNodeNotFound ¶
ErrNodeNotFound creates a node not found graphql error.
Types ¶
type Annotation ¶
type Annotation struct { // OrderField is the ordering field as defined in graphql schema. OrderField string `json:"OrderField,omitempty"` // Unbind implies the edge field name in GraphQL schema is not equivalent // to the name used in ent schema. That means, by default, edges with this // annotation will not be eager-loaded on Paginate calls. See the `MapsTo` // option in order to load edges be different name mapping. Unbind bool `json:"Unbind,omitempty"` // Mapping is the edge field names as defined in graphql schema. Mapping []string `json:"Mapping,omitempty"` // Type is the underlying GraphQL type name (e.g. Boolean). Type string `json:"Type,omitempty"` // Skip exclude the type Skip SkipMode `json:"Skip,omitempty"` // RelayConnection enables the Relay Connection specification for the entity. // It's also can apply on an edge to create the Relay-style filter. RelayConnection bool `json:"RelayConnection,omitempty"` // Implements defines a list of interfaces implemented by the type. Implements []string `json:"Implements,omitempty"` // Directives to add on the field/type. Directives []Directive `json:"Directives,omitempty"` }
Annotation annotates fields and edges with metadata for templates.
func Bind
deprecated
func Bind() Annotation
Bind returns a binding annotation.
No-op function to avoid breaking the existing schema. You can safely remove this function from your scheme.
Deprecated: the Bind option predates the Unbind option, and it is planned to be removed in future versions. Users should not use this annotation as it is a no-op call, or use `Unbind` in order to disable `Bind`.
func Directives ¶
func Directives(directives ...Directive) Annotation
Directives returns a Directives annotation.
func Implements ¶
func Implements(interfaces ...string) Annotation
Implements returns an Implements annotation.
func OrderField ¶
func OrderField(name string) Annotation
OrderField returns an order field annotation.
func RelayConnection ¶
func RelayConnection() Annotation
RelayConnection returns a relay connection annotation.
func Unbind ¶
func Unbind() Annotation
Unbind implies the edge field name in GraphQL schema is not equivalent to the name used in ent schema. That means, by default, edges with this annotation will not be eager-loaded on Paginate calls. See the `MapsTo` option in order to load edges be different name mapping.
func (*Annotation) Decode ¶
func (a *Annotation) Decode(annotation interface{}) error
Decode unmarshalls the annotation.
func (Annotation) Merge ¶
func (a Annotation) Merge(other schema.Annotation) schema.Annotation
Merge implements the schema.Merger interface.
type Directive ¶
type Directive struct { Name string `json:"name,omitempty"` Arguments []DirectiveArgument `json:"arguments,omitempty"` }
Directive to apply on the field/type
func Deprecated ¶
Deprecated create `@deprecated` directive to apply on the field/type
func NewDirective ¶
func NewDirective(name string, args ...DirectiveArgument) Directive
NewDirective return a GraphQL directive
type DirectiveArgument ¶
type DirectiveArgument struct { Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` Kind ast.ValueKind `json:"kind,omitempty"` }
DirectiveArgument return a GraphQL directive argument
type Extension ¶
type Extension struct { entc.DefaultExtension // contains filtered or unexported fields }
Extension implements the entc.Extension for providing GraphQL integration.
func NewExtension ¶
func NewExtension(opts ...ExtensionOption) (*Extension, error)
NewExtension creates a new extension with the given configuration.
ex, err := entgql.NewExtension( entgql.WithWhereFilters(true), entgql.WithSchemaPath("../schema.graphql"), )
func (*Extension) CreatePlugin ¶
CreatePlugin create the plugin for GQLGen
type ExtensionOption ¶
ExtensionOption allows for managing the Extension configuration using functional options.
func WithConfigPath ¶
func WithConfigPath(path string, gqlgenOptions ...api.Option) ExtensionOption
WithConfigPath sets the filepath to gqlgen.yml configuration file and injects its parsed version to the global annotations.
Note that, enabling this option is recommended as it improves the GraphQL integration,
func WithMapScalarFunc ¶
WithMapScalarFunc allows users to provides a custom function that maps an ent.Field (*gen.Field) into its GraphQL scalar type. If the function returns an empty string, the extension fallbacks to the its default mapping.
ex, err := entgql.NewExtension( entgql.WithMapScalarFunc(func(f *gen.Field, op gen.Op) string { if t, ok := knowType(f, op); ok { return t } // Fallback to the default mapping. return "" }), )
func WithSchemaGenerator ¶
func WithSchemaGenerator() ExtensionOption
WithSchemaGenerator add a hook for generate GQL schema
func WithSchemaHook ¶
func WithSchemaHook(hooks ...SchemaHook) ExtensionOption
WithSchemaHook allows users to provide a list of hooks to run after the GQL schema generation.
func WithSchemaPath ¶
func WithSchemaPath(path string) ExtensionOption
WithSchemaPath sets the filepath to the GraphQL schema to write the generated Ent types. If the file does not exist, it will generate a new schema. Please note, that your gqlgen.yml config file should be updated as follows to support multiple schema files:
schema: - schema.graphql // existing schema. - ent.graphql // generated schema.
func WithTemplates ¶
func WithTemplates(templates ...*gen.Template) ExtensionOption
WithTemplates overrides the default templates (entgql.AllTemplates) with specific templates.
func WithWhereFilters ¶
func WithWhereFilters(b bool) ExtensionOption
WithWhereFilters configures the extension to either add or remove the WhereTemplate from the code generation templates.
The WhereTemplate generates GraphQL filters to all types in the ent/schema.
type PaginationNames ¶
type PaginationNames struct { Connection string Edge string Node string Order string OrderField string WhereInput string }
PaginationNames holds the names of the pagination fields.
type SchemaHook ¶
SchemaHook is the hook that run after the GQL schema generation.
type SkipMode ¶
type SkipMode int
SkipMode is a bit flag for the Skip annotation.
const ( // SkipType skips generating GraphQL types or fields in the schema. SkipType SkipMode = 1 << iota // SkipEnumField skips generating GraphQL enums for enum fields in the schema. SkipEnumField // SkipOrderField skips generating GraphQL order inputs and enums for ordered-fields in the schema. SkipOrderField // SkipWhereInput skips generating GraphQL WhereInput types. // If defined on a field, the type will be generated without the field. SkipWhereInput // SkipAll is default mode to skip all. SkipAll = SkipType | SkipEnumField | SkipOrderField | SkipWhereInput )
type Transactioner ¶
type Transactioner struct{ TxOpener }
Transactioner for graphql mutations.
func (Transactioner) ExtensionName ¶
func (Transactioner) ExtensionName() string
ExtensionName returns the extension name.
func (Transactioner) InterceptResponse ¶
func (t Transactioner) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response
InterceptResponse runs graphql mutations under a transaction.
func (Transactioner) MutateOperationContext ¶
func (Transactioner) MutateOperationContext(_ context.Context, oc *graphql.OperationContext) *gqlerror.Error
MutateOperationContext serializes field resolvers during mutations.
func (Transactioner) Validate ¶
func (t Transactioner) Validate(graphql.ExecutableSchema) error
Validate is called when adding an extension to the server, it allows validation against the servers schema.
type TxOpenerFunc ¶
The TxOpenerFunc type is an adapter to allow the use of ordinary functions as tx openers.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
todo/ent/schema/schematype
Package schematype provides custom types for ent/schema.
|
Package schematype provides custom types for ent/schema. |
todofed/ent/schema/schematype
Package schematype provides custom types for ent/schema.
|
Package schematype provides custom types for ent/schema. |
todopulid/ent/schema/pulid
Package pulid implements the pulid type.
|
Package pulid implements the pulid type. |