Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FilterOptions ¶ added in v1.1.1
type FilterOptions struct {
// contains filtered or unexported fields
}
FilterOptions holds the configuration for schema filtering
type FilteredSchema ¶
func NewSchemaFilter ¶
func NewSchemaFilter(schema *ast.Schema, exposeDirective, hideDirective string, overrideBuiltInOperations *[]string) *FilteredSchema
NewSchemaFilter creates a new schema filter using the legacy API. Deprecated: Use NewSchemaFilterWithOptions instead for more flexibility.
func NewSchemaFilterWithOptions ¶ added in v1.1.1
func NewSchemaFilterWithOptions(schema *ast.Schema, opts ...Option) *FilteredSchema
NewSchemaFilterWithOptions creates a new schema filter with flexible options. This is the recommended way to create a schema filter.
Example:
filter := NewSchemaFilterWithOptions(
schema,
WithExposeDirective("expose"),
WithInternalDirective("internal"),
WithHideDirective("hide"),
)
func (FilteredSchema) GetFilteredSchema ¶
func (fs FilteredSchema) GetFilteredSchema() *ast.Schema
GetFilteredSchema returns a new filtered ast schema out of the full schema, filtering out any fields, inputs, enums, types, queries & mutations that are not exposed.
func (*FilteredSchema) GetIntrospectionMiddleware ¶ added in v1.1.1
func (fs *FilteredSchema) GetIntrospectionMiddleware() *IntrospectionFilterMiddleware
GetIntrospectionMiddleware returns a gqlgen middleware that hides fields with internal directives from GraphQL introspection. This is necessary because the SchemaFilter operates at build-time, but @internal fields need to be executable (included in schema) yet hidden from introspection (runtime).
Usage:
schemaFilter := filter.NewSchemaFilterWithOptions(schema, filter.WithInternalDirective("internal"))
middleware := schemaFilter.GetIntrospectionMiddleware()
// Register middleware with gqlgen server
type IntrospectionFilterMiddleware ¶ added in v1.1.1
IntrospectionFilterMiddleware is a gqlgen middleware that filters fields from introspection based on directives. This works in conjunction with the SchemaFilter to provide runtime introspection control for fields that are included in the schema but should be hidden.
func NewIntrospectionFilterMiddleware ¶ added in v1.1.1
func NewIntrospectionFilterMiddleware(schema *ast.Schema, internalDirectives []string) *IntrospectionFilterMiddleware
NewIntrospectionFilterMiddleware creates a middleware that hides fields with internal directives from GraphQL introspection queries.
func (IntrospectionFilterMiddleware) ExtensionName ¶ added in v1.1.1
func (IntrospectionFilterMiddleware) ExtensionName() string
func (*IntrospectionFilterMiddleware) InterceptField ¶ added in v1.1.1
func (m *IntrospectionFilterMiddleware) InterceptField(ctx context.Context, next graphql.Resolver) (res any, err error)
InterceptField intercepts introspection queries to hide fields marked with internal directives
func (IntrospectionFilterMiddleware) Validate ¶ added in v1.1.1
func (IntrospectionFilterMiddleware) Validate(_ graphql.ExecutableSchema) error
type Option ¶ added in v1.1.1
type Option func(*FilterOptions)
Option is a function that modifies FilterOptions
func WithBuiltInOperations ¶ added in v1.1.1
WithBuiltInOperations overrides the default built-in operations list. Default is ["query", "mutation"].
func WithExposeDirective ¶ added in v1.1.1
WithExposeDirective adds a directive name that acts as an allowlist for Query/Mutation fields. Fields with this directive are visible in introspection and executable.
func WithHideDirective ¶ added in v1.1.1
WithHideDirective adds a directive name that acts as a denylist for type fields. Fields with this directive are hidden from the schema entirely.
func WithInternalDirective ¶ added in v1.1.1
WithInternalDirective adds a directive name that marks fields as internal. Internal fields are included in the schema (executable) but should be hidden from introspection. This is equivalent to having both @expose and @hide - the field exists but is not visible.