types

package
v0.0.0-...-89780f9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

FeatureTestInputType is the GraphQL schema for creating a feature test

View Source
var FeatureTestType = graphql.NewObject(graphql.ObjectConfig{
	Name: "FeatureTest",
	Fields: graphql.Fields{
		"id":        &graphql.Field{Type: graphql.ID},
		"name":      &graphql.Field{Type: graphql.String},
		"createdAt": &graphql.Field{Type: graphql.DateTime},
		"updatedAt": &graphql.Field{Type: graphql.DateTime},
		"startTime": &graphql.Field{Type: graphql.DateTime},
		"endTime":   &graphql.Field{Type: graphql.DateTime},
	},
})

FeatureTestType is the GraphQL schema for feature tests

View Source
var FeatureTestVariantInputType = graphql.NewInputObject(graphql.InputObjectConfig{
	Name: "FeatureTestVariantInput",
	Fields: graphql.InputObjectConfigFieldMap{
		"name": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.String),
		},
		"percentage": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.Int),
		},
		"isControl": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.Boolean),
		},
	},
})

FeatureTestVariantInputType is the Graphql schema for feature test variants, used in the feature test input object schema

View Source
var FeatureTestVariantType = graphql.NewObject(graphql.ObjectConfig{
	Name: "FeatureTestVariant",
	Fields: graphql.Fields{
		"id":         &graphql.Field{Type: graphql.ID},
		"name":       &graphql.Field{Type: graphql.String},
		"createdAt":  &graphql.Field{Type: graphql.DateTime},
		"updatedAt":  &graphql.Field{Type: graphql.DateTime},
		"percentage": &graphql.Field{Type: graphql.Int},
		"isControl":  &graphql.Field{Type: graphql.Boolean},
		"featureTest": &graphql.Field{
			Type: FeatureTestType,
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				featureTestID := params.Source.(FeatureTestVariant).FeatureTestID
				featureTest := new(FeatureTest)
				err := dal.DB.Model(featureTest).Where("id = ?", featureTestID).First()
				if err != nil {
					fmt.Printf("Error retrieving feature test from test variant: %v", err)
					return nil, err
				}
				return featureTest, nil
			},
		},
	},
})

FeatureTestVariantType is the graphql type for feature test variants

View Source
var RoleType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Role",
	Fields: graphql.Fields{
		"id":   &graphql.Field{Type: graphql.Int},
		"name": &graphql.Field{Type: graphql.String},
	},
})

RoleType is the GraphQL schema for the role type

View Source
var UserFeatureTestVariantInputType = graphql.NewInputObject(graphql.InputObjectConfig{
	Name: "UserFeatureTestVariantInput",
	Fields: graphql.InputObjectConfigFieldMap{
		"userID": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.Int),
		},
		"featureTestVariantID": &graphql.InputObjectFieldConfig{
			Type: graphql.NewNonNull(graphql.Int),
		},
	},
})

UserFeatureTestVariantInputType is the Graphql schema for user feature test variants, used in the user feature test variant input object schema

View Source
var UserFeatureTestVariantType = graphql.NewObject(graphql.ObjectConfig{
	Name: "UserFeatureTestVariant",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.Int,
		},
		"userID": &graphql.Field{
			Type: graphql.Int,
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				return params.Source.(UserToFeatureUserTestVariant).UserID, nil
			},
		},
		"featureTestVariantID": &graphql.Field{
			Type: graphql.Int,
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				return params.Source.(UserToFeatureUserTestVariant).FeatureTestVariantID, nil
			},
		},
		"user": &graphql.Field{
			Type: UserType,
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				userID := params.Source.(UserToFeatureUserTestVariant).UserID
				user := User{ID: userID}
				err := dal.DB.Select(&user)
				if err != nil {
					fmt.Printf("Error retrieving user from user feature test variant: %v", err)
					return nil, err
				}

				return user, nil
			},
		},
		"featureTestVariant": &graphql.Field{
			Type: FeatureTestVariantType,
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				variantID := params.Source.(UserToFeatureUserTestVariant).FeatureTestVariantID
				variant := FeatureTestVariant{ID: variantID}
				err := dal.DB.Select(&variant)
				if err != nil {
					fmt.Printf("Error retrieving feature test variant from user feature test variant: %v", err)
					return nil, err
				}

				return variant, nil
			},
		},
	},
})

UserFeatureTestVariantType is GraphQL schema for the user feature test variant type

View Source
var UserType = graphql.NewObject(graphql.ObjectConfig{
	Name: "User",
	Fields: graphql.Fields{
		"id":        &graphql.Field{Type: graphql.Int},
		"firstname": &graphql.Field{Type: graphql.String},
		"lastname":  &graphql.Field{Type: graphql.String},
		"roles": &graphql.Field{
			Type: graphql.NewList(RoleType),
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				userID := params.Source.(User).ID
				user := new(User)
				err := dal.DB.Model(user).Where("id = ?", userID).Relation("Roles").First()
				if err != nil {
					fmt.Printf("Error retrieving user roles: %v", err)
					return nil, err
				}

				return user.Roles, nil
			},
		},
		"featureTestVariants": &graphql.Field{
			Type: graphql.NewList(FeatureTestVariantType),
			Resolve: func(params graphql.ResolveParams) (interface{}, error) {
				userID := params.Source.(User).ID
				user := new(User)
				err := dal.DB.Model(user).Where("id = ?", userID).Relation("FeatureTestVariants").First()
				if err != nil {
					fmt.Printf("Error retrieving user feature test variants: %v", err)
					return nil, err
				}
				return user.FeatureTestVariants, nil
			},
		},
	},
})

UserType is GraphQL schema for the user type

Functions

This section is empty.

Types

type FeatureTest

type FeatureTest struct {
	ID        int
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
	StartTime time.Time
	EndTime   time.Time
	DeletedAt time.Time `pg:",soft_delete"`
}

FeatureTest type definition

type FeatureTestVariant

type FeatureTestVariant struct {
	ID            int
	Name          string
	Percentage    int
	IsControl     bool `pg:",use_zero"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
	DeletedAt     time.Time `pg:",soft_delete"`
	FeatureTestID int
	FeatureTest   FeatureTest
	// contains filtered or unexported fields
}

FeatureTestVariant type definition

type Role

type Role struct {
	ID   int
	Name string
}

Role type definition

type User

type User struct {
	ID                  int                  `json:"id"`
	Firstname           string               `json:"firstname"`
	Lastname            string               `json:"lastname"`
	Roles               []Role               `pg:"many2many:user_roles,joinFK:role_id"`
	FeatureTestVariants []FeatureTestVariant `pg:"many2many:feature_usertestvariants,joinFK:feature_testvariant_id"`
	DeletedAt           time.Time            `pg:",soft_delete"`
}

User type definition

type UserToFeatureUserTestVariant

type UserToFeatureUserTestVariant struct {
	ID                   int
	UserID               int
	FeatureTestVariantID int       `pg:"feature_testvariant_id"`
	DeletedAt            time.Time `pg:",soft_delete"`
	// contains filtered or unexported fields
}

UserToFeatureUserTestVariant - join table for users and feature test variants

type UserToRole

type UserToRole struct {
	UserID int
	RoleID int
	// contains filtered or unexported fields
}

UserToRole type definition - join table for users and roles

Jump to

Keyboard shortcuts

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