Skip to content

Commit

Permalink
removing gql
Browse files Browse the repository at this point in the history
  • Loading branch information
kdivanov committed Sep 27, 2024
1 parent db77d25 commit 4ff979a
Show file tree
Hide file tree
Showing 44 changed files with 55 additions and 4,164 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ test-cover: ## Run tests with coverage
@go install github.com/ory/go-acc@latest
@go-acc ./... --output=coverage.out --covermode=atomic -- -race -p 1

init:
cd ./example && go run github.com/99designs/gqlgen init

hitrix:
./example/docker/services.sh hitrix
13 changes: 0 additions & 13 deletions docs/docs/.vuepress/config/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ module.exports = [
text: 'Template',
link: '/guide/services/template',
},
{
text: 'Gql',
link: '/guide/services/gql',
},
{
text: 'Request Logger',
link: '/guide/services/request_logger',
Expand Down Expand Up @@ -196,15 +192,6 @@ module.exports = [
},
],
},
{
text: 'GraphQL',
children: [
{
text: 'Dataloaders',
link: '/guide/graphql/dataloaders',
},
],
},
],
},
]
27 changes: 8 additions & 19 deletions docs/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Introduction

Hitrix is a web framework written in Go (Golang) and support Graphql and REST api.
It is based on top of [Gqlgen](https://gqlgen.com/]) and [Gin Framework](https://github.com/gin-gonic/gin)
Hitrix is a web framework written in Go (Golang) and REST api.
It is based on top of [Gin Framework](https://github.com/gin-gonic/gin)

#### Why to choose Hitrix?
Hitrix is combination between high performance and speed of development.
Expand All @@ -12,7 +12,7 @@ The only thing you need to do is to use Hitrix and deliver fast to the business

Built-in features:

* It supports all features of [Gqlgen](https://gqlgen.com/]) and [Gin Framework](https://github.com/gin-gonic/gin)
* It supports all features of [Gin Framework](https://github.com/gin-gonic/gin)
* Integrated with [ORM](https://github.com/latolukasz/beeorm)
* Follows [Dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) pattern
* Provides many DI services that makes your life easier. You can read more about them in our documentation
Expand All @@ -33,13 +33,7 @@ go get -u github.com/coretrix/hitrix


## Quick start
1. Run next command into your project's main folder and the graph structure will be created
```
go run github.com/99designs/gqlgen init
```


2. Create `cmd` folder into your project and file called `main.go`
1. Create `cmd` folder into your project and file called `main.go`

Put the next code into the file:
```go
Expand All @@ -48,17 +42,14 @@ package main
import (
"github.com/coretrix/hitrix"
"github.com/gin-gonic/gin"

"your-project/graph" //path you your graph
"your-project/graph/generated" //path you your graph generated folder
)

func main() {
s, deferFunc := hitrix.New(
"app-name", "your secret",
).Build()
defer deferFunc()
s.RunServer(9999, generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}), func(ginEngine *gin.Engine) {
s.RunServer(9999, func(ginEngine *gin.Engine) {
//here you can register all your middlewares
})
}
Expand All @@ -74,8 +65,6 @@ import (
"github.com/coretrix/hitrix"
"github.com/coretrix/hitrix/service/registry"
"your-project/entity"
"your-project/graph"
"your-project/graph/generated"
"github.com/coretrix/hitrix/pkg/middleware"
"github.com/gin-gonic/gin"
"github.com/coretrix/hitrix/service/component/app"
Expand All @@ -92,12 +81,12 @@ func main() {
registry.ServiceProviderJWT(), //register JWT DI service
registry.ServiceProviderPassword(password.NewSimpleManager), //register pasword DI service
).RegisterDIRequestService(
registry.ServiceProviderOrmEngineForContext(false), //register our ORM engine per context used in foreground processes
registry.ServiceProviderOrmEngineForContext(), //register our ORM engine per context used in foreground processes
).RegisterRedisPools(&app.RedisPools{Persistent: "your pool here"}).
Build()
defer deferFunc()

s.RunServer(9999, generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}), func(ginEngine *gin.Engine) {
s.RunServer(9999, func(ginEngine *gin.Engine) {
middleware.Cors(ginEngine)
})
}
Expand All @@ -122,7 +111,7 @@ Now I will explain the main.go file line by line

2.8. Request DI ORM engine used in foreground processes
3. We register redis pools. Those pools are used by different services as `authentication` service, `dev panel` and so on
4. We run the server on port `9999`, pass graphql resolver and as third param we pass all middlewares we need.
4. We run the server on port `9999` and pass all middlewares we need.
As you can see in our example we register only Cors middleware


Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guide/features/helper.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Helpers
We have different type of helpers that will provide you simple universal functions that will save your time.
Please review folder `pkg/helpers`. We have helpers like:
`array, auth, call, file, graphql, mysql, price, time, validator geo` and so on
`array, auth, call, file, mysql, price, time, validator geo` and so on

Only way to be aware with them is to spend some time check the code and inform yourself what can be helpful for you from our helpers
33 changes: 2 additions & 31 deletions docs/docs/guide/features/test.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Tests
Hitrix provide you test abstract layer that can be used to simulate requests to your graphql api
Hitrix provide you test abstract layer that can be used to simulate requests to your api

In your code you can create similar function that makes new instance of your app

```go
func createContextMyApp(t *testing.T, projectName string, resolvers graphql.ExecutableSchema) *test.Ctx {
func createContextMyApp(t *testing.T, projectName string) *test.Ctx {
defaultServices := []*service.Definition{
registry.ServiceProviderConfigDirectory("../example/config"),
registry.ServiceProviderOrmRegistry(entity.Init),
Expand All @@ -22,35 +22,6 @@ func createContextMyApp(t *testing.T, projectName string, resolvers graphql.Exec

```

After that you can call queries or mutations

```go
func TestProcessApplePurchaseWithEmail(t *testing.T) {
type queryRegisterTransactions struct {
RegisterTransactionsResponse *model.RegisterTransactionsResponse `graphql:"RegisterTransactions(applePurchaseRequest: $applePurchaseRequest)"`
}

variables := map[string]interface{}{
"applePurchaseRequest": model.ApplePurchaseRequest{
ForceEmail: false,
},
}

fakeMail := &mailMock.Sender{}
fakeMail.On("SendTemplate", "[email protected]").Return(nil)

got := &queryRegisterTransactions{}
projectName, resolver := tests.GetWebAPIResolver()
ctx := tests.CreateContextWebAPI(t, projectName, resolver, &tests.IoCMocks{MailService: fakeMail})

err := ctx.HandleMutation(got, variables)
assert.Nil(t, err)

//...
fakeMail.AssertExpectations(t)
}
```

Hitrix supports `parallel` tests
In case you want to execute parallel tests you need to set
`PARALLEL_TESTS=true` env var in your IDE config and be sure you don't have set `-p 1` in `Go tool arguments`
Expand Down
39 changes: 0 additions & 39 deletions docs/docs/guide/features/validator.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
# Validator
We support 2 types of validators. One of them is related to graphql, the other one is related to rest.

#### Graphql validator
There are 2 steps that needs to be executed if you want to use this kind of validator

1. Add `directive @validate(rules: String!) on INPUT_FIELD_DEFINITION` into your `schema.graphqls` file

2. Call `ValidateDirective` into your main.go file
```go
config := generated.Config{Resolvers: &graph.Resolver{}, Directives: generated.DirectiveRoot{Validate: hitrix.ValidateDirective()} }

s.RunServer(4001, generated.NewExecutableSchema(config), func(ginEngine *gin.Engine) {
commonMiddleware.Cors(ginEngine)
middleware.Router(ginEngine)
})
```

After that you can define the validation rules in that way:
```graphql
input ApplePurchaseRequest {
ForceEmail: Boolean!
Name: String
Email: String @validate(rules: "email") #for rules param you can use everything supported by https://github.com/go-playground/validator validate.Var(value, rules)
AppleReceipt: String!
}
```

To handle the errors you need to call function `hitrix.Validate(ctx, nil)` in your resolver
```go
func (r *mutationResolver) RegisterTransactions(ctx context.Context, applePurchaseRequest model.ApplePurchaseRequest) (*model.RegisterTransactionsResponse, error) {
if !hitrix.Validate(ctx, nil) {
return nil, nil
}
// your logic here...
}
```

The function `hitrix.Validate(ctx, nil)` as second param accept callback where you can define your custom validation related to business logic


#### REST validator

Expand Down
81 changes: 0 additions & 81 deletions docs/docs/guide/graphql/dataloaders.md

This file was deleted.

8 changes: 4 additions & 4 deletions docs/docs/guide/services/crud.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CRUD
This service it gives you ability to build gql query and apply different query parameters to the query that should be
This service it gives you ability to build query and apply different query parameters to the query that should be
used in listing pages

Register the service into your `main.go` file:
Expand Down Expand Up @@ -54,7 +54,7 @@ func columns() []crud.Column {
```

```go
//listing request using by gql
//listing request
type ListRequest struct {
Page *int `json:"Page"`
PageSize *int `json:"PageSize"`
Expand All @@ -70,7 +70,7 @@ cols := columns()

crudService := service.DI().CrudService()

searchParams := crudService.ExtractListParams(cols, crud.ListRequestConvertorFromGQL(userListRequest))
searchParams := crudService.ExtractListParams(cols, userListRequest)
query := crudService.GenerateListRedisSearchQuery(searchParams)

ormService := ioc.GetOrmEngineFromContext(ctx)
Expand All @@ -87,7 +87,7 @@ for i, userEntity := range userEntities {
return &model.UserList{
Rows: userEntityList,
Total: len(userEntityList),
Columns: crud.ColumnConvertorToGQL(cols),
Columns: cols,
}, nil
```

Expand Down
14 changes: 0 additions & 14 deletions docs/docs/guide/services/gql.md

This file was deleted.

10 changes: 4 additions & 6 deletions docs/docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ func main() {
type OrderEntity struct{
}
```

6. When instantiating graphql objects, use methods that are defined in `populate` package. If there is no method for your object, please declare one for your object.
7. Don't use `time.Now()` . Use `ioc.GetClockService().Now()` instead. If you need pointer, use `ioc.GetClockService().NowPointer()`.
8. All entity files should have `_entity.go` suffix, the entity itself should end with `Entity`.
9. In yaml config files we should set env vars only for values that going to be different in different environments(dev/demo/prod) If they are the same we should not use env var, but we can set the value into the yaml file
10. Custom redis indexes can be re-indexed using dev panel but dirty queues needs extra effort from developer side.
6. Don't use `time.Now()` . Use `ioc.GetClockService().Now()` instead. If you need pointer, use `ioc.GetClockService().NowPointer()`.
7. All entity files should have `_entity.go` suffix, the entity itself should end with `Entity`.
8. In yaml config files we should set env vars only for values that going to be different in different environments(dev/demo/prod) If they are the same we should not use env var, but we can set the value into the yaml file
9. Custom redis indexes can be re-indexed using dev panel but dirty queues needs extra effort from developer side.
- You need to extend the slice into `DevPanelController->GetActionListAction` slice `dirty`
This step will add new menu in dev panel dashboard.
- Be sure that you added GET url for in into your router
Expand Down
Loading

0 comments on commit 4ff979a

Please sign in to comment.