Custom Operators
FastGQL defines a set of operators that can be used to extend the schema. These operators are defined in the fastgql.graphql file.
These operators are used to run filters and queries on the database.
Standard Operators
By default, FastGQL supports these operators for scalar types (String, Int, Float, etc.):
eq- equalsneq- not equalsgt- greater thanlt- less thangte- greater than or equallte- less than or equalin- innotIn- not inlike- like (string matching with wildcards)ilike- case-insensitive likeisNull- is nullsuffix- string ends withprefix- string starts with
List/Array Operators
The following operators are available specifically for list/array types (StringListComparator, IntListComparator, etc.):
contains- array contains value(s)notContains- array does not contain value(s)overlap- arrays have overlapping elementscontainedBy- array is contained by another array
Note: These list operators are NOT available for scalar comparators like StringComparator or IntComparator.
Adding Custom Operators
FastGQL allows you to add custom operators to the schema. This can be done by defining a new input type in the fastgql.graphql file,
or by adding a new operator to an existing input type, by extending the input type.
# extend our input type to include a custom operatorextend input StringComparator { # The custom operator to use for the comparison. myCustomOperator: String}We will define our custom operator to always do “1 = 1”
func MyCustomOperator(table exp.AliasedExpression, key string, value interface{}) goqu.Expression { return goqu.L("1 = 1")}In our serve.go where we define our schema, we will add a resolver for the custom operator.
cfg := &builders.Config{ Schema: executableSchema.Schema(), Logger: adapters.NewZerologAdapter(log.Logger), CustomOperators: map[string]builders.Operator{ "myCustomOperator": MyCustomOperator, },}An example of a custom operator can be found here.
Adding FilterInputs for Custom Scalar Types
Similar to how StringComparator is used to filter strings, you can define a custom input type to filter custom scalar types.
# Define a custom scalar typescalar MyCustomScalar
# Define a custom input type to filter the custom scalar typeinput MyCustomScalarComparator { eq: MyCustomScalar # The custom operator to use for the comparison. myCustomOperator: MyCustomScalar}