Skip to content

Commit

Permalink
graphql-index
Browse files Browse the repository at this point in the history
  • Loading branch information
huyao committed Oct 31, 2023
1 parent 58836ed commit 64f9e22
Show file tree
Hide file tree
Showing 14 changed files with 6,743 additions and 0 deletions.
1 change: 1 addition & 0 deletions graphql/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DB_URL=postgresql://[user]:[password]@[host]:[port]/[database]?sslmode=require
1 change: 1 addition & 0 deletions graphql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
26 changes: 26 additions & 0 deletions graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# indexer-graphql

## How to start

### step 1

copy the config example file,then replace the database information
```cmd
cp .env.example .env
```


### step 2
```cmd
go mod tidy
```

### step 3
```cmd
go run server.go
```

then visit http://localhost:8088/ for GraphQL playground



37 changes: 37 additions & 0 deletions graphql/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module github.com/metaforo/indexer-graphql

go 1.18

require (
github.com/99designs/gqlgen v0.17.40
github.com/go-pg/pg/v10 v10.11.1
github.com/joho/godotenv v1.5.1
github.com/vektah/gqlparser/v2 v2.5.10
)

require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-pg/zerochecker v0.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sosodev/duration v1.1.0 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/urfave/cli/v2 v2.25.5 // indirect
github.com/vmihailenco/bufpool v0.1.11 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mellium.im/sasl v0.3.1 // indirect
)
210 changes: 210 additions & 0 deletions graphql/go.sum

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions graphql/gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- graph/*.graphqls

# Where should the generated server code go?
exec:
filename: graph/generated.go
package: graph

# Uncomment to enable federation
# federation:
# filename: graph/federation.go
# package: graph

# Where should any generated models go?
model:
filename: graph/model/models_gen.go
package: model

# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: graph
package: graph
filename_template: "{name}.resolvers.go"
# Optional: turn on to not generate template comments above resolvers
# omit_template_comment: false

# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: turn on to omit Is<Name>() methods to interface and unions
# omit_interface_checks : true

# Optional: turn on to skip generation of ComplexityRoot struct content and Complexity function
# omit_complexity: false

# Optional: turn on to not generate any file notice comments in generated files
# omit_gqlgen_file_notice: false

# Optional: turn on to exclude the gqlgen version in the generated file notice. No effect if `omit_gqlgen_file_notice` is true.
# omit_gqlgen_version_in_file_notice: false

# Optional: turn off to make struct-type struct fields not use pointers
# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing }
# struct_fields_always_pointers: true

# Optional: turn off to make resolvers return values instead of pointers for structs
# resolvers_always_return_pointers: true

# Optional: turn on to return pointers instead of values in unmarshalInput
# return_pointers_in_unmarshalinput: false

# Optional: wrap nullable input fields with Omittable
# nullable_input_omittable: true

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# Optional: set to skip running `go mod tidy` when generating server code
# skip_mod_tidy: true

# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
# - "github.com/metaforo/indexer-graphql/graph/model"

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
19 changes: 19 additions & 0 deletions graphql/graph/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package graph

import (
"os"
"github.com/go-pg/pg/v10"
)

func Connect() *pg.DB {
connStr := os.Getenv("DB_URL")
opt, err := pg.ParseURL(connStr)
if err != nil {
panic(err)
}
db := pg.Connect(opt)
if _, DBStatus := db.Exec("SELECT 1"); DBStatus != nil {
panic(DBStatus)
}
return db
}
Loading

0 comments on commit 64f9e22

Please sign in to comment.