Skip to content

Commit

Permalink
Merge pull request #8 from bmeg/feature/graphql-reader
Browse files Browse the repository at this point in the history
[WIP] Feature/graphql reader
  • Loading branch information
matthewpeterkort authored Feb 13, 2025
2 parents e201659 + 1154e75 commit b8cdee6
Show file tree
Hide file tree
Showing 95 changed files with 194,637 additions and 2,035 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ dmypy.json
.idea/

# scratch
tmp/
tmp/
.DS_Store
gencli
28 changes: 12 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ ENV PATH="/go/bin:${PATH}"
ADD ./ /go/src/github.com/bmeg/grip-graphql
WORKDIR /go/src/github.com/bmeg/grip-graphql

RUN go install github.com/bmeg/grip@54c6baa9a315aec2c5916ec11116609773bfc9b0
RUN make all

RUN go install github.com/bmeg/[email protected]
RUN go build --buildmode=plugin ./graphql_gen3
RUN go build --buildmode=plugin ./gen3_writer
RUN go build --buildmode=plugin ./grip-graphql-endpoint


FROM alpine
WORKDIR /data
VOLUME /data
ENV PATH="/app:${PATH}"
COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/graphql_gen3.so /data/
COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/gen3_writer.so /data/
COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/grip-graphql-endpoint.so /data/
COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/config/gen3.js /data/config/
COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/mongo.yml /data/
COPY --from=build-env /go/bin/grip /app/
#FROM alpine
#WORKDIR /data
#VOLUME /data
#ENV PATH="/app:${PATH}"
#COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/gql-gen.so /data/
#COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/gen3_writer.so /data/
#COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/grip-graphql-endpoint.so /data/
#COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/config/gen3.js /data/config/
#COPY --from=build-env /go/src/github.com/bmeg/grip-graphql/mongo.yml /data/
#COPY --from=build-env /go/bin/grip /app/
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

all: grip-graphql-endpoint.so gen3_writer.so grip-graphql-proxy
all: grip-graphql-endpoint.so gen3_writer.so gql-gen.so grip-graphql-proxy

gen3_writer.so : $(shell find gen3_writer -name "*.go")
go build --buildmode=plugin ./gen3_writer

grip-graphql-endpoint.so : $(shell find grip-graphql-endpoint -name "*.go")
go build --buildmode=plugin ./grip-graphql-endpoint

gql-gen.so: $(shell find gql-gen -name "*.go")
go build --buildmode=plugin ./gql-gen

grip-graphql-proxy : $(shell find cmd/grip-graphql-proxy -name "*.go")
go build ./cmd/grip-graphql-proxy

graphql_gen3 : $(shell find graphql_gen3 -name "*.go")
go build --buildmode=plugin ./graphql_gen3

clean:
rm grip-graphql-proxy grip-graphql-endpoint.so gen3_writer.so
rm grip-graphql-proxy grip-graphql-endpoint.so gen3_writer.so gql-gen.so
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ gen3_writer directory contains a [Gin](https://github.com/gin-gonic/gin) go serv

gripgraphql directory contains a graphql based read query plugin that uses a [goja](https://github.com/dop251/goja) engine to read from a static schema defined as a config file to create custom graphql queries that can be used to abstract Grip's complex query language into a more digestible query format for the frontend to use.

graphql_gen3 is a legacy implementation of a reader reader plugin using a more traditional graphql schema builder.
gql-gen directory contains a graphql schema based read plugin that leverages [gql-gen](https://github.com/99designs/gqlgen) to autogenerate go structs and for schema introspection

See ./gen3_writer for tests and additional documentation

### Matching plugin versions to avoid go.mod version Errors:

Error messages when loading plugins into grip like the one below are quite common:

```
message Error loading pluging test: plugin.Open("gql-gen"): plugin was built with a different version of package golang.org/x/sys/unix
time 2024-12-11T16:27:49-08:00
```

These are caused when the grip executable's build package versions are not equivalent with the plugin's build package versions. There are a veriety of reasons why this might be true:

1. Make sure that the go version of Grip go.mod and the go version of this go.mod are the same.

2. Make sure that the versions of all of the packages across both go.mod files are the same

3. install grip with go install github.com/bmeg/grip@[hash] when deploying using a docker container and debug with a replace statement to avoid having to make a commit everytime a change is made to the grip go.mod file.

Ex:

```
replace github.com/bmeg/grip v0.0.0-20241211235035-b772edec00b9 => ../grip
```

Note: Go versions of packages can change when a new package is added in this repo, or when a new package is added in grip.
45 changes: 11 additions & 34 deletions gen3_writer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
```
go install github.com/bmeg/grip
go build --buildmode=plugin ./gen3_writer
grip server -w graphql=gen3_writer.so
grip server -w writer=gen3_writer.so
```

Note: the -w graphql=gen3_writer.so option can be stacked to include multiple endpoints and long as you have
Note: the -w writer=gen3_writer.so option can be stacked to include multiple endpoints and long as you have
built the .so file to the corresponding endplint as shown above. Ex:

`grip server -c mongo.yml -w graphql=gen3_writer.so -w reader=grip-graphql-endpoint.so -l reader:config=./config/gen3.js -l reader:graph=CALIPER`
`grip server -c mongo.yml -w writer=gen3_writer.so -w reader=grip-graphql-endpoint.so -l reader:config=./config/gen3.js -l reader:graph=CALIPER`

## Example queries:

Note: ENV var ACCESS_TOKEN is a valid Gen3 jwt token. An access token is needed for all queries except GET \_status and GET list-graphs

### Delete an edge and then grep for it to see if it has been deleted or not. Format:

_http://localhost:8201/graphql/[graph-name]/del-edge/[edge-id]/[gen3-project-id]_
_http://localhost:8201/writer/[graph-name]/del-edge/[edge-id]/[gen3-project-id]_

```
curl -X DELETE http://localhost:8201/graphql/CALIPER/del-edge/fb60e763-e799-4d59-82a3-66977cc6696c/ohsu-test
curl -X DELETE http://localhost:8201/writer/CALIPER/del-edge/fb60e763-e799-4d59-82a3-66977cc6696c/ohsu-test
-H "Content-Type: applicationjson" \
-H "Authorization: bearer $ACCESS_TOKEN"
Expand All @@ -31,10 +31,10 @@ grip query CALIPER "E()" | grep fb60e763-e799-4d59-82a3-66977cc6696c

### Bulk load some edges from a file:

_http://localhost:8201/graphql/[graph-name]/bulk-load/[gen3-project-id]_
_http://localhost:8201/writer/[graph-name]/bulk-load/[gen3-project-id]_

```
curl -X POST "http://localhost:8201/graphql/CALIPER/bulk-load/ohsu-test" \
curl -X POST "http://localhost:8201/writer/CALIPER/bulk-load/ohsu-test" \
-H "Authorization: bearer $ACCESS_TOKEN" \
-F "types=edge" \
-F "[email protected]"
Expand All @@ -55,48 +55,25 @@ With required keys "label", "from", "to", and "gid" and optional key "data" with

### Get the data from a vertex given a known vertex id

_http://localhost:8201/graphql/[graph-name]/get-vertex/[vertex-id]/[gen3-project-id]_
_http://localhost:8201/writer/[graph-name]/get-vertex/[vertex-id]/[gen3-project-id]_

```
curl -X GET http://localhost:8201/graphql/CALIPER/get-vertex/875ddaf8-42da-5d72-b5c5-39c2b16151cd/ohsu-test \
curl -X GET http://localhost:8201/writer/CALIPER/get-vertex/875ddaf8-42da-5d72-b5c5-39c2b16151cd/ohsu-test \
-H "Authorization: bearer $ACCESS_TOKEN"
```

### Get the list of graphs present

```
curl http://localhost:8201/graphql/list-graphs
curl http://localhost:8201/writer/list-graphs
```

### Revproxy Setup --

The above curl commands assume that you are acessing this grip plugin from within the cluster. equivalent queries can be used from outside the cluster by changing the nginx paths to the form:

`https://[your_instance_endpoint]/grip/writer/graphql/list-graphs` for the writer or
`https://[your_instance_endpoint]/grip/writer/writer/list-graphs` for the writer or
`https://[your_instance_endpoint]/grip/reader` for the reader api

These paths assume you have checked out to the grip branch of helm and reployed

## Tests:

Tests can be run locally by specifying that you want to turn on the plugin in testing mode using the `TEST` Graph. For example:

```
grip server -w graphql=gen3_writer.so \
-w reader=grip-graphql-endpoint.so \
-l reader:config=./config/gen3.js \
-l reader:graph=TEST \
-l graphql:test=true \
-l reader:test=true
```

then cd to gen3_writer directory and run:

`go test` or `go test -v` for logs or `go test -run [specific_test_name]` to run only a specific test

If the graph name is `TEST` and the config is setup for test=true, mock auth will be used, and these tests can be run locally outside of a gen3 instance.

## Version

go version go1.22.6

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

92 changes: 31 additions & 61 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,42 @@ module github.com/bmeg/grip-graphql
go 1.22.5

require (
github.com/bmeg/grip v0.0.0-20241130225536-67d787e0b831
github.com/99designs/gqlgen v0.17.57
github.com/bmeg/grip v0.0.0-20250203230556-54c6baa9a315
github.com/dop251/goja v0.0.0-20240707163329-b1681fb2a2f5
github.com/gin-gonic/gin v1.8.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/graphql-go/graphql v0.8.1
github.com/graphql-go/handler v0.2.4
github.com/mongodb/mongo-tools v0.0.0-20240715143021-aa6a140d3f17
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/vektah/gqlparser/v2 v2.5.19
go.mongodb.org/mongo-driver v1.11.9
google.golang.org/protobuf v1.34.2
golang.org/x/exp v0.0.0-20240707233637-46b078467d37
google.golang.org/protobuf v1.35.2
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Shopify/sarama v1.38.1 // indirect
github.com/Workiva/go-datastructures v1.1.5 // indirect
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
github.com/agnivade/levenshtein v1.2.0 // indirect
github.com/akuity/grpc-gateway-client v0.0.0-20231116134900-80c401329778 // indirect
github.com/alevinval/sse v1.0.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bmeg/jsonpath v0.0.0-20210207014051-cca5355553ad // indirect
github.com/bmeg/jsonschema/v5 v5.3.4-0.20241111204732-55db82022a92 // indirect
github.com/bmeg/jsonschemagraph v0.0.3-0.20241130225037-5545ec0ffd4b // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/casbin/casbin/v2 v2.97.0 // indirect
github.com/casbin/govaluate v1.2.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/crlib v0.0.0-20241112164430-1264a2edc35b // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/pebble v0.0.0-20250128214837-cd1252433ca0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dlclark/regexp2 v1.11.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eapache/go-resiliency v1.6.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
Expand All @@ -57,90 +47,70 @@ require (
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-resty/resty/v2 v2.13.1 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/tdigest v0.0.1 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jessevdk/go-flags v1.6.1 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/knakk/rdf v0.0.0-20190304171630-8521bf4c5042 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.23 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.73 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/paulbellamy/ratecounter v0.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/robertkrimen/otto v0.4.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/grpc v1.65.0 // indirect
gopkg.in/olivere/elastic.v5 v5.0.86 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit b8cdee6

Please sign in to comment.