documents

package
v0.13.8-0...-a8de8dd Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDocumentFields

func AddDocumentFields[PluginConfig any](
	ctx context.Context,
	db plugins.DatabasePool[PluginConfig],
) error

AddDocumentFields adds necessary documents to the selections of the user's project including keys and __typename for every object

func ExtractFromFilepaths

func ExtractFromFilepaths[PluginConfig any](
	ctx context.Context,
	db plugins.DatabasePool[PluginConfig],
	fs afero.Fs,
	files []string,
) error

func Generate

func Generate(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	fs afero.Fs,
	sortKeys bool,
) ([]string, error)

func GeneratePersistentQueries

func GeneratePersistentQueries(
	ctx context.Context,
	db plugins.DatabasePool[any],
	fs afero.Fs,
) ([]string, error)

func LoadDocumentDependencies

func LoadDocumentDependencies[PluginConfig any](
	ctx context.Context,
	db plugins.DatabasePool[PluginConfig],
	errs *plugins.ErrorList,
)

func LoadPendingQuery

func LoadPendingQuery(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	conn plugins.Conn,
	query PendingQuery,
	statements DocumentInsertStatements,
	typeCache TypeCache,
) *plugins.Error

LoadPendingQuery parses the graphql query and inserts the ast into the database. it handles both operations and fragment definitions.

func ProcessFile

func ProcessFile(fs afero.Fs, fp string, ch chan DiscoveredDocument) *plugins.Error

ProcessFile reads the file (using the provided afero.Fs) and sends each discovered GraphQL document on ch. Comments are stripped before scanning so commented-out graphql() calls are never extracted.

func ValidateConflictingSelections

func ValidateConflictingSelections(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateDuplicateArgumentInField

func ValidateDuplicateArgumentInField(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateDuplicateDocumentNames

func ValidateDuplicateDocumentNames(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateDuplicateKeysInInputObject

func ValidateDuplicateKeysInInputObject(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateDuplicateVariables

func ValidateDuplicateVariables(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateEndpointDirective

func ValidateEndpointDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

ValidateEndpointDirective enforces the build-time guarantees for @endpoint:

  • it only sits on mutation documents
  • its redirect (when present) is a relative path, which is what closes open-redirect at build time
  • every redirect interpolation path resolves to a leaf scalar in the mutation's selection set, so we can never emit /users/undefined

func ValidateFragmentCycles

func ValidateFragmentCycles(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateFragmentOnScalar

func ValidateFragmentOnScalar(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateFragmentUnknownType

func ValidateFragmentUnknownType(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateIncompatibleFragmentSpread

func ValidateIncompatibleFragmentSpread(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateKnownDirectiveArguments

func ValidateKnownDirectiveArguments(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateLoadingDirective

func ValidateLoadingDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateMaskDirectives

func ValidateMaskDirectives(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateMissingRequiredArgument

func ValidateMissingRequiredArgument(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateNoKeyAlias

func ValidateNoKeyAlias(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateOptimisticKeyFullSelection

func ValidateOptimisticKeyFullSelection(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateOptimisticKeyOnScalar

func ValidateOptimisticKeyOnScalar(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateOutputTypeAsInput

func ValidateOutputTypeAsInput(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidatePluralDirective

func ValidatePluralDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

ValidatePluralDirective enforces the constraints around the @plural directive (mirrors Relay's @relay(plural: true) rules):

  • a @plural fragment may only be spread on a list field (a field backed by a GraphQL list), since the consumer receives the whole list as an array.
  • @plural may not be combined with @paginate, whose refetch machinery assumes a single record.

func ValidateRefetchDirective

func ValidateRefetchDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateRepeatingNonRepeatable

func ValidateRepeatingNonRepeatable(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateRequiredDirective

func ValidateRequiredDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateScalarWithSelection

func ValidateScalarWithSelection(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateSessionDirective

func ValidateSessionDirective(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

ValidateSessionDirective enforces the build-time guarantees for @session, the directive that writes the session from a mutation result (orthogonal to @endpoint's form story):

  • it only sits on mutation documents
  • it carries a `path`, which must resolve to an object in the mutation's selection set — that object's fields become App.Session

func ValidateSubscriptionsWithMultipleRootFields

func ValidateSubscriptionsWithMultipleRootFields(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateUndefinedVariables

func ValidateUndefinedVariables(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateUnknownField

func ValidateUnknownField(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateUnknownFieldArguments

func ValidateUnknownFieldArguments(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateUnknownVariableTypes

func ValidateUnknownVariableTypes(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

ValidateUnknownVariableTypes makes sure that every operation variable and fragment argument declares a type that actually exists in the schema. without this, a typo'd type name would only surface as a confusing mismatch where the variable is used (or not at all if it's only passed through @with)

func ValidateUnusedVariables

func ValidateUnusedVariables(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func ValidateWrongTypesToArg

func ValidateWrongTypesToArg(
	ctx context.Context,
	db plugins.DatabasePool[config.PluginConfig],
	errs *plugins.ErrorList,
)

func Walk

func Walk[PluginConfig any](
	ctx context.Context,
	db plugins.DatabasePool[PluginConfig],
	fs afero.Fs,
) error

Walk is responsible for walking down the project directory structure and extracting the raw graphql documents from the files. These files will be parsed in a later step to allow for other plugins to find additional documents we don't know about

Types

type DiscoveredDocument

type DiscoveredDocument struct {
	FilePath string
	Content  string
	// if we run into a component field we need to record the prop during extraction
	Prop         string
	OffsetColumn int
	OffsetRow    int
}

DiscoveredDocument holds the file path and the extracted GraphQL query.

type DocumentInsertStatements

type DocumentInsertStatements struct {
	InsertDocument                          plugins.Stmt
	InsertDocumentVariable                  plugins.Stmt
	UpdateLoadedWith                        plugins.Stmt
	InsertDocumentVariableDirective         plugins.Stmt
	InsertDocumentVariableDirectiveArgument plugins.Stmt
	InsertSelection                         plugins.Stmt
	CheckExistingSelection                  plugins.Stmt
	InsertSelectionRef                      plugins.Stmt
	InsertSelectionArgument                 plugins.Stmt
	InsertArgumentValue                     plugins.Stmt
	InsertArgumentValueChild                plugins.Stmt
	InsertSelectionDirective                plugins.Stmt
	InsertSelectionDirectiveArgument        plugins.Stmt
	InsertDocumentDirective                 plugins.Stmt
	InsertDocumentDirectiveArgument         plugins.Stmt
}

func PrepareDocumentInsertStatements

func PrepareDocumentInsertStatements(conn plugins.Conn) (DocumentInsertStatements, error, func())

type OperationDoc

type OperationDoc struct {
	ID      string
	Name    string
	Kind    string
	Hash    string
	Printed string
}

type PendingQuery

type PendingQuery struct {
	Filepath                 string
	ColumnOffset             int
	RowOffset                int
	Query                    string
	ID                       int
	LastLoadedWith           string
	InlineComponentField     bool
	InlineComponentFieldProp *string
}

type RootTypeNames

type RootTypeNames struct {
	Query        string
	Mutation     string
	Subscription string
}

type TypeCache

type TypeCache struct {
	TypeFields         map[string]TypeWithModifiers
	FieldArguments     map[string]TypeWithModifiers
	DirectiveArguments map[string]TypeWithModifiers
	RootTypes          RootTypeNames
}

func LoadTypeCache

func LoadTypeCache[PluginConfig any](
	ctx context.Context,
	db plugins.DatabasePool[PluginConfig],
) (TypeCache, error)

type TypeWithModifiers

type TypeWithModifiers struct {
	Type      string
	Modifiers string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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