inflect

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package inflect defines the naming pipeline for every generated GraphQL identifier. All names produced by the schema builder flow through a chain of InflectionHook implementations, so plugins can override any name without touching core code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default(kind Kind, in Input) string

Default is the built-in PostGraphile-flavoured verbose naming.

func EnumValue

func EnumValue(s string) string

EnumValue converts a Postgres enum label to a GraphQL enum value name.

func LowerCamel

func LowerCamel(s string) string

LowerCamel converts snake_case to lowerCamelCase.

func Pluralize

func Pluralize(s string) string

Pluralize applies simple English pluralization rules.

func Singularize

func Singularize(s string) string

Singularize applies simple English singularization rules — enough for common table names; plugins can override anything it gets wrong.

func UpperCamel

func UpperCamel(s string) string

UpperCamel converts snake_case to UpperCamelCase.

Types

type Input

type Input struct {
	Schema     string   // pg schema name
	Table      string   // pg table/view name
	Column     string   // pg column name (when applicable)
	Columns    []string // multi-column keys
	Constraint string   // pg constraint name backing the name (relation kinds)
	Function   string   // pg function name (when applicable)
	Enum       string   // pg enum type name
	Value      string   // enum value
	IsList     bool
}

Input carries everything a hook may need to build a name.

type Kind

type Kind string

Kind identifies which name is being generated.

const (
	KindTypeName           Kind = "type_name"             // table -> object type (User)
	KindAllRowsField       Kind = "all_rows_field"        // table -> collection connection query (allUsers)
	KindRowByPKField       Kind = "row_by_pk_field"       // table -> single lookup (userById)
	KindRowByUniqueField   Kind = "row_by_unique_field"   // unique lookup (userByEmail)
	KindFieldName          Kind = "field_name"            // column -> field (firstName)
	KindEnumTypeName       Kind = "enum_type_name"        // pg enum -> GraphQL enum type
	KindEnumValueName      Kind = "enum_value_name"       // pg enum value -> GraphQL enum value
	KindFilterTypeName     Kind = "filter_type_name"      // UserFilter
	KindOrderByTypeName    Kind = "order_by_type_name"    // UsersOrderBy
	KindDistinctOnTypeName Kind = "distinct_on_type_name" // UsersDistinctOn
	KindCreateMutation     Kind = "create_mutation"       // createUser
	KindUpdateMutation     Kind = "update_mutation"       // updateUserById (primary key)
	KindDeleteMutation     Kind = "delete_mutation"       // deleteUserById (primary key)
	// The by-unique variants are distinct kinds so naming plugins can shorten
	// the primary-key mutation without colliding with unique-constraint ones.
	KindUpdateByUniqueMutation Kind = "update_by_unique_mutation" // updateUserByEmail
	KindDeleteByUniqueMutation Kind = "delete_by_unique_mutation" // deleteUserByEmail
	KindUpsertMutation         Kind = "upsert_mutation"           // upsertUserById (primary key)
	KindUpsertByUniqueMutation Kind = "upsert_by_unique_mutation" // upsertUserByEmail
	KindCreateManyMutation     Kind = "create_many_mutation"      // createUsers
	KindUpdateManyMutation     Kind = "update_many_mutation"      // updateUsers (filtered)
	KindDeleteManyMutation     Kind = "delete_many_mutation"      // deleteUsers (filtered)
	KindCreateInput            Kind = "create_input"              // UserCreateInput
	KindUpdateInput            Kind = "update_input"              // UserUpdateInput
	KindPayloadTypeName        Kind = "payload_type_name"         // CreateUserPayload
	KindRelationForward        Kind = "relation_forward"          // FK column -> parent object field (author)
	KindRelationBackward       Kind = "relation_backward"         // reverse FK -> child list field (postsByAuthorId)
	KindFunctionField          Kind = "function_field"            // pg function -> query/mutation field
	KindFunctionInput          Kind = "function_input"            // volatile function -> input object type (LoginInput)
	KindFunctionPayload        Kind = "function_payload"          // volatile function -> payload object type (LoginPayload)
	KindComputedField          Kind = "computed_field"            // row-type function -> field on the row's type (postCount)
)

type Next

type Next func(kind Kind, in Input) string

Next continues the chain; the last Next is the default inflector.

Jump to

Keyboard shortcuts

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