Skip to content

Commit

Permalink
Merge pull request #41 from firstcontributions/reactions
Browse files Browse the repository at this point in the history
Reactions
  • Loading branch information
gokultp authored Aug 20, 2023
2 parents 0422f95 + 8e23daa commit 5afa41d
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Docker Image CI

on:
push:
branches: [ master ]


env:
IMAGE_TAG: ${{ github.sha }}

jobs:

build:

runs-on: ubuntu-latest
environment: prod

steps:
- uses: actions/checkout@v2
- name: docker login
env:
DOCKER_USER: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build the Docker image
run: docker build . --file Dockerfile --tag gokultp/matro:$IMAGE_TAG

- name: Docker Push
run: docker push gokultp/matro:$IMAGE_TAG
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.18 as builder
WORKDIR /matro/
COPY . /matro/
ARG VERSION=v1.0.1-alpha
ENV VERSION=${VERSION}

WORKDIR /matro/cmd/matro
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
-X github.com/firstcontributions/matro/internal/commands.Version=${VERSION} \
-X github.com/firstcontributions/matro/internal/commands.MinVersion=`git rev-parse HEAD` \
-X github.com/firstcontributions/matro/internal/commands.BuildTime=`date +%FT%T%z` " \
-o ./build/matro -mod vendor ./cmd/matro

FROM alpine:3.16 as deploy
COPY --from=builder /matro/build/* ./


Binary file added build/matro
Binary file not shown.
2 changes: 2 additions & 0 deletions internal/generators/graphql/gocode/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (m *Resolver) Create{{- title .Name }}(
{{- end}}
{{- end}}
ownership := &authorizer.Scope{
Users: []string{session.UserID()},
}
Expand Down
11 changes: 11 additions & 0 deletions internal/generators/models/mongo/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func (s *{{- title .Module.Name -}}Store) Create{{- title .Name -}} (ctx context
if err != nil {
return nil, err
}
if dproc, ok := interface{}({{.Name -}}).(utils.DataProcessor); ok {
if err := dproc.Process(ctx); err != nil {
return nil, err
}
}
{{.Name -}}.Id = uuid.String()
{{- if .IsViewerType}}
{{.Name -}}.Permissions = []authorizer.Permission{
Expand Down Expand Up @@ -199,6 +204,12 @@ func (s *{{- title .Module.Name -}}Store) Get{{- title (plural .Name) -}} (
}
func (s *{{- title .Module.Name -}}Store) Update{{- title .Name -}} (ctx context.Context, id string, {{.Name -}}Update *{{- .Module.Store -}}. {{- title .Name -}}Update) (error) {
if dproc, ok := interface{}({{.Name -}}Update).(utils.DataProcessor); ok {
if err := dproc.Process(ctx); err != nil {
return err
}
}
qb := mongoqb.NewQueryBuilder().
Eq("_id", id)
Expand Down
13 changes: 13 additions & 0 deletions internal/generators/models/mongo/dproctmpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal/generators/models/mongo/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (g *Generator) Generate(ctx context.Context) error {
if err := g.generateUtilsPkg(ctx); err != nil {
return err
}
if err := g.generateDataProcessorInterface(ctx); err != nil {
return err
}
for _, m := range g.Modules {
if err := g.generateStore(ctx, m); err != nil {
return err
Expand Down Expand Up @@ -115,6 +118,16 @@ func (g *Generator) generateUtilsPkg(ctx context.Context) error {
)
}

func (g *Generator) generateDataProcessorInterface(ctx context.Context) error {
return writer.CompileAndWrite(
ctx,
fmt.Sprintf("%s/internal/models/utils", g.Path),
"dataprocessor.go",
dprocTmpl,
g,
)
}

// generateStore generates the store interface,
func (g *Generator) generateStore(ctx context.Context, m Module) error {
return writer.CompileAndWrite(
Expand Down
11 changes: 11 additions & 0 deletions internal/generators/types/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Field struct {
IsList bool
IsNullable bool
IsPaginated bool
MaxCount int
IsQuery bool
Args []Field
IsPrimitive bool
Expand Down Expand Up @@ -47,6 +48,15 @@ func getPaginationArgs(f *Field) []Field {
func NewField(d *parser.Definition, typesMap map[string]*parser.Type, typeDef *parser.Type, name string, isViewerReferece bool) *Field {

if typeDef.IsPrimitive() {
if typeDef.Type == parser.List {
return &Field{
Name: name,
Type: typeDef.Schema,
IsPrimitive: true,
NoGraphql: typeDef.NoGraphql,
IsList: true,
}
}
return &Field{
Name: name,
Type: typeDef.Type,
Expand All @@ -62,6 +72,7 @@ func NewField(d *parser.Definition, typesMap map[string]*parser.Type, typeDef *p
IsJoinedData: typeDef.JoinedData,
HardcodedFilters: typeDef.HardcodedFilters,
ViewerRefence: isViewerReferece,
MaxCount: typeDef.MaxCount,
}
if typeDef.Schema == "" {
f.Type = typeDef.Name
Expand Down
7 changes: 7 additions & 0 deletions internal/parser/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type _Type struct {
Name string `json:"name"`
Type string `json:"type"`
Paginated bool `json:"paginated"`
MaxCount int `json:"max_count"`
Schema string `json:"schema"`
JoinedData bool `json:"joined_data"`
Properties map[string]*Type `json:"properties"`
Expand Down Expand Up @@ -152,6 +153,12 @@ func (t *Type) IsPrimitive() bool {
case Int, Bool, Float, ID, String, Time:
return true
}
if t.Type == List {
switch t.Schema {
case Int, Bool, Float, ID, String, Time:
return true
}
}
return false
}

Expand Down

0 comments on commit 5afa41d

Please sign in to comment.