mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
Fix arm32v6 build (#3501)
* Downgrade gqlgen to v0.17.2 The current version of gqlgen (v0.17.24) gives SIGILL crashes on armv7. * Update gqlparser
This commit is contained in:
parent
a081b62823
commit
3dcc23c001
100 changed files with 2731 additions and 4169 deletions
5
go.mod
5
go.mod
|
|
@ -1,7 +1,7 @@
|
||||||
module github.com/stashapp/stash
|
module github.com/stashapp/stash
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/99designs/gqlgen v0.17.24
|
github.com/99designs/gqlgen v0.17.2
|
||||||
github.com/Yamashou/gqlgenc v0.0.6
|
github.com/Yamashou/gqlgenc v0.0.6
|
||||||
github.com/anacrolix/dms v1.2.2
|
github.com/anacrolix/dms v1.2.2
|
||||||
github.com/antchfx/htmlquery v1.2.5-0.20211125074323-810ee8082758
|
github.com/antchfx/htmlquery v1.2.5-0.20211125074323-810ee8082758
|
||||||
|
|
@ -57,6 +57,7 @@ require (
|
||||||
github.com/spf13/cast v1.4.1
|
github.com/spf13/cast v1.4.1
|
||||||
github.com/vearutop/statigz v1.1.6
|
github.com/vearutop/statigz v1.1.6
|
||||||
github.com/vektah/dataloaden v0.3.0
|
github.com/vektah/dataloaden v0.3.0
|
||||||
|
github.com/vektah/gqlparser/v2 v2.4.2
|
||||||
github.com/xWTF/chardet v0.0.0-20230208095535-c780f2ac244e
|
github.com/xWTF/chardet v0.0.0-20230208095535-c780f2ac244e
|
||||||
gopkg.in/guregu/null.v4 v4.0.0
|
gopkg.in/guregu/null.v4 v4.0.0
|
||||||
)
|
)
|
||||||
|
|
@ -82,6 +83,7 @@ require (
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
github.com/matryer/moq v0.2.3 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
|
@ -99,7 +101,6 @@ require (
|
||||||
github.com/subosito/gotenv v1.2.0 // indirect
|
github.com/subosito/gotenv v1.2.0 // indirect
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/urfave/cli/v2 v2.8.1 // indirect
|
github.com/urfave/cli/v2 v2.8.1 // indirect
|
||||||
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
|
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
|
|
|
||||||
15
go.sum
15
go.sum
|
|
@ -50,9 +50,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
|
||||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
|
github.com/99designs/gqlgen v0.17.2 h1:yczvlwMsfcVu/JtejqfrLwXuSP0yZFhmcss3caEvHw8=
|
||||||
github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
|
github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
|
||||||
github.com/99designs/gqlgen v0.17.24 h1:pcd/HFIoSdRvyADYQG2dHvQN2KZqX/nXzlVm6TMMq7E=
|
|
||||||
github.com/99designs/gqlgen v0.17.24/go.mod h1:BMhYIhe4bp7OlCo5I2PnowSK/Wimpv/YlxfNkqZGwLo=
|
|
||||||
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
|
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
|
||||||
github.com/Azure/azure-storage-blob-go v0.13.0/go.mod h1:pA9kNqtjUeQF2zOSu4s//nUdBD+e64lEuc4sVnuOfNs=
|
github.com/Azure/azure-storage-blob-go v0.13.0/go.mod h1:pA9kNqtjUeQF2zOSu4s//nUdBD+e64lEuc4sVnuOfNs=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||||
|
|
@ -64,7 +63,6 @@ github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935
|
||||||
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
|
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
|
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
github.com/ClickHouse/clickhouse-go v1.4.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
|
|
@ -558,8 +556,8 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
|
||||||
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
||||||
github.com/markbates/pkger v0.15.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
|
github.com/markbates/pkger v0.15.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
|
||||||
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
|
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
|
||||||
|
github.com/matryer/moq v0.2.3 h1:Q06vEqnBYjjfx5KKgHfYRKE/lvlRu+Nj+xodG4YdHnU=
|
||||||
github.com/matryer/moq v0.2.3/go.mod h1:9RtPYjTnH1bSBIkpvtHkFN7nbWAnO7oRpdJkEIn6UtE=
|
github.com/matryer/moq v0.2.3/go.mod h1:9RtPYjTnH1bSBIkpvtHkFN7nbWAnO7oRpdJkEIn6UtE=
|
||||||
github.com/matryer/moq v0.2.7/go.mod h1:kITsx543GOENm48TUAQyJ9+SAvFSr7iGQXPoth/VUBk=
|
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
|
@ -567,7 +565,6 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
|
||||||
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
|
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
|
@ -578,7 +575,6 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
|
||||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
|
||||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
||||||
|
|
@ -762,8 +758,8 @@ github.com/vektah/dataloaden v0.3.0 h1:ZfVN2QD6swgvp+tDqdH/OIT/wu3Dhu0cus0k5gIZS
|
||||||
github.com/vektah/dataloaden v0.3.0/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
|
github.com/vektah/dataloaden v0.3.0/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
|
||||||
github.com/vektah/gqlparser/v2 v2.4.0/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0=
|
github.com/vektah/gqlparser/v2 v2.4.0/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0=
|
||||||
github.com/vektah/gqlparser/v2 v2.4.1/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0=
|
github.com/vektah/gqlparser/v2 v2.4.1/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0=
|
||||||
github.com/vektah/gqlparser/v2 v2.5.1 h1:ZGu+bquAY23jsxDRcYpWjttRZrUz07LbiY77gUOHcr4=
|
github.com/vektah/gqlparser/v2 v2.4.2 h1:29TGc6QmhEUq5fll+2FPoTmhUhR65WEKN4VK/jo0OlM=
|
||||||
github.com/vektah/gqlparser/v2 v2.5.1/go.mod h1:mPgqFBu/woKTVYWyNk8cO3kh4S/f4aRFZrvOnp3hmCs=
|
github.com/vektah/gqlparser/v2 v2.4.2/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0=
|
||||||
github.com/vektra/mockery/v2 v2.10.0 h1:MiiQWxwdq7/ET6dCXLaJzSGEN17k758H7JHS9kOdiks=
|
github.com/vektra/mockery/v2 v2.10.0 h1:MiiQWxwdq7/ET6dCXLaJzSGEN17k758H7JHS9kOdiks=
|
||||||
github.com/vektra/mockery/v2 v2.10.0/go.mod h1:m/WO2UzWzqgVX3nvqpRQq70I4Z7jbSCRhdmkgtp+Ab4=
|
github.com/vektra/mockery/v2 v2.10.0/go.mod h1:m/WO2UzWzqgVX3nvqpRQq70I4Z7jbSCRhdmkgtp+Ab4=
|
||||||
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
||||||
|
|
@ -1064,7 +1060,6 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
|
@ -1080,7 +1075,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
|
@ -1321,7 +1315,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
|
||||||
2
vendor/github.com/99designs/gqlgen/.gitignore
generated
vendored
2
vendor/github.com/99designs/gqlgen/.gitignore
generated
vendored
|
|
@ -14,5 +14,3 @@
|
||||||
.idea/
|
.idea/
|
||||||
*.test
|
*.test
|
||||||
*.out
|
*.out
|
||||||
gqlgen
|
|
||||||
*.exe
|
|
||||||
|
|
|
||||||
2370
vendor/github.com/99designs/gqlgen/CHANGELOG.md
generated
vendored
2370
vendor/github.com/99designs/gqlgen/CHANGELOG.md
generated
vendored
File diff suppressed because it is too large
Load diff
14
vendor/github.com/99designs/gqlgen/README.md
generated
vendored
14
vendor/github.com/99designs/gqlgen/README.md
generated
vendored
|
|
@ -22,8 +22,7 @@ Still not convinced enough to use **gqlgen**? Compare **gqlgen** with other Go g
|
||||||
|
|
||||||
2. Add `github.com/99designs/gqlgen` to your [project's tools.go](https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)
|
2. Add `github.com/99designs/gqlgen` to your [project's tools.go](https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)
|
||||||
|
|
||||||
printf '// +build tools\npackage tools\nimport (_ "github.com/99designs/gqlgen"\n _ "github.com/99designs/gqlgen/graphql/introspection")' | gofmt > tools.go
|
printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
|
||||||
|
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
3. Initialise gqlgen config and generate models
|
3. Initialise gqlgen config and generate models
|
||||||
|
|
@ -143,20 +142,9 @@ first model in this list is used as the default type and it will always be used
|
||||||
|
|
||||||
There isn't any way around this, gqlgen has no way to know what you want in a given context.
|
There isn't any way around this, gqlgen has no way to know what you want in a given context.
|
||||||
|
|
||||||
### Why do my interfaces have getters? Can I disable these?
|
|
||||||
These were added in v0.17.14 to allow accessing common interface fields without casting to a concrete type.
|
|
||||||
However, certain fields, like Relay-style Connections, cannot be implemented with simple getters.
|
|
||||||
|
|
||||||
If you'd prefer to not have getters generated in your interfaces, you can add the following in your `gqlgen.yml`:
|
|
||||||
```yaml
|
|
||||||
# gqlgen.yml
|
|
||||||
omit_getters: true
|
|
||||||
```
|
|
||||||
|
|
||||||
## Other Resources
|
## Other Resources
|
||||||
|
|
||||||
- [Christopher Biscardi @ Gophercon UK 2018](https://youtu.be/FdURVezcdcw)
|
- [Christopher Biscardi @ Gophercon UK 2018](https://youtu.be/FdURVezcdcw)
|
||||||
- [Introducing gqlgen: a GraphQL Server Generator for Go](https://99designs.com.au/blog/engineering/gqlgen-a-graphql-server-generator-for-go/)
|
- [Introducing gqlgen: a GraphQL Server Generator for Go](https://99designs.com.au/blog/engineering/gqlgen-a-graphql-server-generator-for-go/)
|
||||||
- [Dive into GraphQL by Iván Corrales Solera](https://medium.com/@ivan.corrales.solera/dive-into-graphql-9bfedf22e1a)
|
- [Dive into GraphQL by Iván Corrales Solera](https://medium.com/@ivan.corrales.solera/dive-into-graphql-9bfedf22e1a)
|
||||||
- [Sample Project built on gqlgen with Postgres by Oleg Shalygin](https://github.com/oshalygin/gqlgen-pg-todo-example)
|
- [Sample Project built on gqlgen with Postgres by Oleg Shalygin](https://github.com/oshalygin/gqlgen-pg-todo-example)
|
||||||
- [Hackernews GraphQL Server with gqlgen by Shayegan Hooshyari](https://www.howtographql.com/graphql-go/0-introduction/)
|
|
||||||
|
|
|
||||||
7
vendor/github.com/99designs/gqlgen/RELEASE-CHECKLIST.md
generated
vendored
7
vendor/github.com/99designs/gqlgen/RELEASE-CHECKLIST.md
generated
vendored
|
|
@ -6,10 +6,9 @@ Assuming the next version is $NEW_VERSION=v0.16.0 or something like that.
|
||||||
./bin/release $NEW_VERSION
|
./bin/release $NEW_VERSION
|
||||||
```
|
```
|
||||||
2. git-chglog -o CHANGELOG.md
|
2. git-chglog -o CHANGELOG.md
|
||||||
3. go generate ./...; cd _examples; go generate ./...; cd ..
|
3. git commit and push the CHANGELOG.md
|
||||||
4. git commit and push the CHANGELOG.md
|
4. Go to https://github.com/99designs/gqlgen/releases and draft new release, autogenerate the release notes, and Create a discussion for this release
|
||||||
5. Go to https://github.com/99designs/gqlgen/releases and draft new release, autogenerate the release notes, and Create a discussion for this release
|
5. Comment on the release discussion with any really important notes (breaking changes)
|
||||||
6. Comment on the release discussion with any really important notes (breaking changes)
|
|
||||||
|
|
||||||
I used https://github.com/git-chglog/git-chglog to automate the changelog maintenance process for now. We could just as easily use go releaser to make the whole thing automated.
|
I used https://github.com/git-chglog/git-chglog to automate the changelog maintenance process for now. We could just as easily use go releaser to make the whole thing automated.
|
||||||
|
|
||||||
|
|
|
||||||
3
vendor/github.com/99designs/gqlgen/TESTING.md
generated
vendored
3
vendor/github.com/99designs/gqlgen/TESTING.md
generated
vendored
|
|
@ -36,4 +36,5 @@ npm install
|
||||||
|
|
||||||
will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql`
|
will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql`
|
||||||
|
|
||||||
CI will run this and fail the build if the two files don't match.
|
CI will run this and fail the build if the two files dont match.
|
||||||
|
|
||||||
|
|
|
||||||
16
vendor/github.com/99designs/gqlgen/api/generate.go
generated
vendored
16
vendor/github.com/99designs/gqlgen/api/generate.go
generated
vendored
|
|
@ -2,7 +2,6 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/codegen"
|
"github.com/99designs/gqlgen/codegen"
|
||||||
|
|
@ -25,20 +24,7 @@ func Generate(cfg *config.Config, option ...Option) error {
|
||||||
}
|
}
|
||||||
plugins = append(plugins, resolvergen.New())
|
plugins = append(plugins, resolvergen.New())
|
||||||
if cfg.Federation.IsDefined() {
|
if cfg.Federation.IsDefined() {
|
||||||
if cfg.Federation.Version == 0 { // default to using the user's choice of version, but if unset, try to sort out which federation version to use
|
plugins = append([]plugin.Plugin{federation.New()}, plugins...)
|
||||||
urlRegex := regexp.MustCompile(`(?s)@link.*\(.*url:.*?"(.*?)"[^)]+\)`) // regex to grab the url of a link directive, should it exist
|
|
||||||
|
|
||||||
// check the sources, and if one is marked as federation v2, we mark the entirety to be generated using that format
|
|
||||||
for _, v := range cfg.Sources {
|
|
||||||
cfg.Federation.Version = 1
|
|
||||||
urlString := urlRegex.FindStringSubmatch(v.Input)
|
|
||||||
if urlString != nil && urlString[1] == "https://specs.apollo.dev/federation/v2.0" {
|
|
||||||
cfg.Federation.Version = 2
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plugins = append([]plugin.Plugin{federation.New(cfg.Federation.Version)}, plugins...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range option {
|
for _, o := range option {
|
||||||
|
|
|
||||||
12
vendor/github.com/99designs/gqlgen/codegen/args.go
generated
vendored
12
vendor/github.com/99designs/gqlgen/codegen/args.go
generated
vendored
|
|
@ -73,15 +73,11 @@ func (b *builder) buildArg(obj *Object, arg *ast.ArgumentDefinition) (*FieldArgu
|
||||||
return &newArg, nil
|
return &newArg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *builder) bindArgs(field *Field, sig *types.Signature, params *types.Tuple) ([]*FieldArgument, error) {
|
func (b *builder) bindArgs(field *Field, params *types.Tuple) ([]*FieldArgument, error) {
|
||||||
n := params.Len()
|
var newArgs []*FieldArgument
|
||||||
newArgs := make([]*FieldArgument, 0, len(field.Args))
|
|
||||||
// Accept variadic methods (i.e. have optional parameters).
|
|
||||||
if params.Len() > len(field.Args) && sig.Variadic() {
|
|
||||||
n = len(field.Args)
|
|
||||||
}
|
|
||||||
nextArg:
|
nextArg:
|
||||||
for j := 0; j < n; j++ {
|
for j := 0; j < params.Len(); j++ {
|
||||||
param := params.At(j)
|
param := params.At(j)
|
||||||
for _, oldArg := range field.Args {
|
for _, oldArg := range field.Args {
|
||||||
if strings.EqualFold(oldArg.Name, param.Name()) {
|
if strings.EqualFold(oldArg.Name, param.Name()) {
|
||||||
|
|
|
||||||
37
vendor/github.com/99designs/gqlgen/codegen/config/binder.go
generated
vendored
37
vendor/github.com/99designs/gqlgen/codegen/config/binder.go
generated
vendored
|
|
@ -192,7 +192,6 @@ type TypeReference struct {
|
||||||
Unmarshaler *types.Func // When using external marshalling functions this will point to the Unmarshal function
|
Unmarshaler *types.Func // When using external marshalling functions this will point to the Unmarshal function
|
||||||
IsMarshaler bool // Does the type implement graphql.Marshaler and graphql.Unmarshaler
|
IsMarshaler bool // Does the type implement graphql.Marshaler and graphql.Unmarshaler
|
||||||
IsContext bool // Is the Marshaler/Unmarshaller the context version; applies to either the method or interface variety.
|
IsContext bool // Is the Marshaler/Unmarshaller the context version; applies to either the method or interface variety.
|
||||||
PointersInUmarshalInput bool // Inverse values and pointers in return.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ref *TypeReference) Elem() *TypeReference {
|
func (ref *TypeReference) Elem() *TypeReference {
|
||||||
|
|
@ -217,6 +216,7 @@ func (t *TypeReference) IsPtr() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix for https://github.com/golang/go/issues/31103 may make it possible to remove this (may still be useful)
|
// fix for https://github.com/golang/go/issues/31103 may make it possible to remove this (may still be useful)
|
||||||
|
//
|
||||||
func (t *TypeReference) IsPtrToPtr() bool {
|
func (t *TypeReference) IsPtrToPtr() bool {
|
||||||
if p, isPtr := t.GO.(*types.Pointer); isPtr {
|
if p, isPtr := t.GO.(*types.Pointer); isPtr {
|
||||||
_, isPtr := p.Elem().(*types.Pointer)
|
_, isPtr := p.Elem().(*types.Pointer)
|
||||||
|
|
@ -252,39 +252,6 @@ func (t *TypeReference) IsStruct() bool {
|
||||||
return isStruct
|
return isStruct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TypeReference) IsUnderlyingBasic() bool {
|
|
||||||
_, isUnderlyingBasic := t.GO.Underlying().(*types.Basic)
|
|
||||||
return isUnderlyingBasic
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TypeReference) IsUnusualBasic() bool {
|
|
||||||
if basic, isBasic := t.GO.(*types.Basic); isBasic {
|
|
||||||
switch basic.Kind() {
|
|
||||||
case types.Int8, types.Int16, types.Uint, types.Uint8, types.Uint16, types.Uint32:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TypeReference) IsUnderlyingUnusualBasic() bool {
|
|
||||||
if basic, isUnderlyingBasic := t.GO.Underlying().(*types.Basic); isUnderlyingBasic {
|
|
||||||
switch basic.Kind() {
|
|
||||||
case types.Int8, types.Int16, types.Uint, types.Uint8, types.Uint16, types.Uint32:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TypeReference) IsScalarID() bool {
|
|
||||||
return t.Definition.Kind == ast.Scalar && t.Marshaler.Name() == "MarshalID"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TypeReference) IsScalar() bool {
|
func (t *TypeReference) IsScalar() bool {
|
||||||
return t.Definition.Kind == ast.Scalar
|
return t.Definition.Kind == ast.Scalar
|
||||||
}
|
}
|
||||||
|
|
@ -446,8 +413,6 @@ func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret
|
||||||
ref.GO = bindTarget
|
ref.GO = bindTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
ref.PointersInUmarshalInput = b.cfg.ReturnPointersInUmarshalInput
|
|
||||||
|
|
||||||
return ref, nil
|
return ref, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
23
vendor/github.com/99designs/gqlgen/codegen/config/config.go
generated
vendored
23
vendor/github.com/99designs/gqlgen/codegen/config/config.go
generated
vendored
|
|
@ -1,8 +1,8 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/99designs/gqlgen/internal/code"
|
"github.com/99designs/gqlgen/internal/code"
|
||||||
"github.com/vektah/gqlparser/v2"
|
"github.com/vektah/gqlparser/v2"
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
@ -26,11 +26,6 @@ type Config struct {
|
||||||
StructTag string `yaml:"struct_tag,omitempty"`
|
StructTag string `yaml:"struct_tag,omitempty"`
|
||||||
Directives map[string]DirectiveConfig `yaml:"directives,omitempty"`
|
Directives map[string]DirectiveConfig `yaml:"directives,omitempty"`
|
||||||
OmitSliceElementPointers bool `yaml:"omit_slice_element_pointers,omitempty"`
|
OmitSliceElementPointers bool `yaml:"omit_slice_element_pointers,omitempty"`
|
||||||
OmitGetters bool `yaml:"omit_getters,omitempty"`
|
|
||||||
OmitComplexity bool `yaml:"omit_complexity,omitempty"`
|
|
||||||
StructFieldsAlwaysPointers bool `yaml:"struct_fields_always_pointers,omitempty"`
|
|
||||||
ReturnPointersInUmarshalInput bool `yaml:"return_pointers_in_unmarshalinput,omitempty"`
|
|
||||||
ResolversAlwaysReturnPointers bool `yaml:"resolvers_always_return_pointers,omitempty"`
|
|
||||||
SkipValidation bool `yaml:"skip_validation,omitempty"`
|
SkipValidation bool `yaml:"skip_validation,omitempty"`
|
||||||
SkipModTidy bool `yaml:"skip_mod_tidy,omitempty"`
|
SkipModTidy bool `yaml:"skip_mod_tidy,omitempty"`
|
||||||
Sources []*ast.Source `yaml:"-"`
|
Sources []*ast.Source `yaml:"-"`
|
||||||
|
|
@ -51,9 +46,6 @@ func DefaultConfig() *Config {
|
||||||
Exec: ExecConfig{Filename: "generated.go"},
|
Exec: ExecConfig{Filename: "generated.go"},
|
||||||
Directives: map[string]DirectiveConfig{},
|
Directives: map[string]DirectiveConfig{},
|
||||||
Models: TypeMap{},
|
Models: TypeMap{},
|
||||||
StructFieldsAlwaysPointers: true,
|
|
||||||
ReturnPointersInUmarshalInput: false,
|
|
||||||
ResolversAlwaysReturnPointers: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +57,7 @@ func LoadDefaultConfig() (*Config, error) {
|
||||||
filename = filepath.ToSlash(filename)
|
filename = filepath.ToSlash(filename)
|
||||||
var err error
|
var err error
|
||||||
var schemaRaw []byte
|
var schemaRaw []byte
|
||||||
schemaRaw, err = os.ReadFile(filename)
|
schemaRaw, err = ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to open schema: %w", err)
|
return nil, fmt.Errorf("unable to open schema: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -102,15 +94,12 @@ var path2regex = strings.NewReplacer(
|
||||||
func LoadConfig(filename string) (*Config, error) {
|
func LoadConfig(filename string) (*Config, error) {
|
||||||
config := DefaultConfig()
|
config := DefaultConfig()
|
||||||
|
|
||||||
b, err := os.ReadFile(filename)
|
b, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to read config: %w", err)
|
return nil, fmt.Errorf("unable to read config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := yaml.NewDecoder(bytes.NewReader(b))
|
if err := yaml.UnmarshalStrict(b, config); err != nil {
|
||||||
dec.KnownFields(true)
|
|
||||||
|
|
||||||
if err := dec.Decode(config); err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to parse config: %w", err)
|
return nil, fmt.Errorf("unable to parse config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +173,7 @@ func CompleteConfig(config *Config) error {
|
||||||
filename = filepath.ToSlash(filename)
|
filename = filepath.ToSlash(filename)
|
||||||
var err error
|
var err error
|
||||||
var schemaRaw []byte
|
var schemaRaw []byte
|
||||||
schemaRaw, err = os.ReadFile(filename)
|
schemaRaw, err = ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to open schema: %w", err)
|
return fmt.Errorf("unable to open schema: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
vendor/github.com/99designs/gqlgen/codegen/config/package.go
generated
vendored
1
vendor/github.com/99designs/gqlgen/codegen/config/package.go
generated
vendored
|
|
@ -12,7 +12,6 @@ import (
|
||||||
type PackageConfig struct {
|
type PackageConfig struct {
|
||||||
Filename string `yaml:"filename,omitempty"`
|
Filename string `yaml:"filename,omitempty"`
|
||||||
Package string `yaml:"package,omitempty"`
|
Package string `yaml:"package,omitempty"`
|
||||||
Version int `yaml:"version,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PackageConfig) ImportPath() string {
|
func (c *PackageConfig) ImportPath() string {
|
||||||
|
|
|
||||||
48
vendor/github.com/99designs/gqlgen/codegen/data.go
generated
vendored
48
vendor/github.com/99designs/gqlgen/codegen/data.go
generated
vendored
|
|
@ -2,10 +2,7 @@ package codegen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
|
|
||||||
|
|
@ -33,26 +30,6 @@ type Data struct {
|
||||||
QueryRoot *Object
|
QueryRoot *Object
|
||||||
MutationRoot *Object
|
MutationRoot *Object
|
||||||
SubscriptionRoot *Object
|
SubscriptionRoot *Object
|
||||||
AugmentedSources []AugmentedSource
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Data) HasEmbeddableSources() bool {
|
|
||||||
hasEmbeddableSources := false
|
|
||||||
for _, s := range d.AugmentedSources {
|
|
||||||
if s.Embeddable {
|
|
||||||
hasEmbeddableSources = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasEmbeddableSources
|
|
||||||
}
|
|
||||||
|
|
||||||
// AugmentedSource contains extra information about graphql schema files which is not known directly from the Config.Sources data
|
|
||||||
type AugmentedSource struct {
|
|
||||||
// path relative to Config.Exec.Filename
|
|
||||||
RelativePath string
|
|
||||||
Embeddable bool
|
|
||||||
BuiltIn bool
|
|
||||||
Source string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type builder struct {
|
type builder struct {
|
||||||
|
|
@ -170,31 +147,6 @@ func BuildData(cfg *config.Config) (*Data, error) {
|
||||||
// otherwise show a generic error message
|
// otherwise show a generic error message
|
||||||
return nil, fmt.Errorf("invalid types were encountered while traversing the go source code, this probably means the invalid code generated isnt correct. add try adding -v to debug")
|
return nil, fmt.Errorf("invalid types were encountered while traversing the go source code, this probably means the invalid code generated isnt correct. add try adding -v to debug")
|
||||||
}
|
}
|
||||||
aSources := []AugmentedSource{}
|
|
||||||
for _, s := range cfg.Sources {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get working directory: %w", err)
|
|
||||||
}
|
|
||||||
outputDir := cfg.Exec.Dir()
|
|
||||||
sourcePath := filepath.Join(wd, s.Name)
|
|
||||||
relative, err := filepath.Rel(outputDir, sourcePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to compute path of %s relative to %s: %w", sourcePath, outputDir, err)
|
|
||||||
}
|
|
||||||
relative = filepath.ToSlash(relative)
|
|
||||||
embeddable := true
|
|
||||||
if strings.HasPrefix(relative, "..") || s.BuiltIn {
|
|
||||||
embeddable = false
|
|
||||||
}
|
|
||||||
aSources = append(aSources, AugmentedSource{
|
|
||||||
RelativePath: relative,
|
|
||||||
Embeddable: embeddable,
|
|
||||||
BuiltIn: s.BuiltIn,
|
|
||||||
Source: s.Input,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
s.AugmentedSources = aSources
|
|
||||||
|
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
vendor/github.com/99designs/gqlgen/codegen/directives.gotpl
generated
vendored
10
vendor/github.com/99designs/gqlgen/codegen/directives.gotpl
generated
vendored
|
|
@ -70,7 +70,7 @@ func (ec *executionContext) _mutationMiddleware(ctx context.Context, obj *ast.Op
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if .Directives.LocationDirectives "SUBSCRIPTION" }}
|
{{ if .Directives.LocationDirectives "SUBSCRIPTION" }}
|
||||||
func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *ast.OperationDefinition, next func(ctx context.Context) (interface{}, error)) func(ctx context.Context) graphql.Marshaler {
|
func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *ast.OperationDefinition, next func(ctx context.Context) (interface{}, error)) func() graphql.Marshaler {
|
||||||
for _, d := range obj.Directives {
|
for _, d := range obj.Directives {
|
||||||
switch d.Name {
|
switch d.Name {
|
||||||
{{- range $directive := .Directives.LocationDirectives "SUBSCRIPTION" }}
|
{{- range $directive := .Directives.LocationDirectives "SUBSCRIPTION" }}
|
||||||
|
|
@ -80,7 +80,7 @@ func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *as
|
||||||
args, err := ec.{{ $directive.ArgsFunc }}(ctx,rawArgs)
|
args, err := ec.{{ $directive.ArgsFunc }}(ctx,rawArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec.Error(ctx, err)
|
ec.Error(ctx, err)
|
||||||
return func(ctx context.Context) graphql.Marshaler {
|
return func() graphql.Marshaler {
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,15 +98,15 @@ func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *as
|
||||||
tmp, err := next(ctx)
|
tmp, err := next(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec.Error(ctx, err)
|
ec.Error(ctx, err)
|
||||||
return func(ctx context.Context) graphql.Marshaler {
|
return func() graphql.Marshaler {
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if data, ok := tmp.(func(ctx context.Context) graphql.Marshaler); ok {
|
if data, ok := tmp.(func() graphql.Marshaler); ok {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
ec.Errorf(ctx, `unexpected type %T from directive, should be graphql.Marshaler`, tmp)
|
ec.Errorf(ctx, `unexpected type %T from directive, should be graphql.Marshaler`, tmp)
|
||||||
return func(ctx context.Context) graphql.Marshaler {
|
return func() graphql.Marshaler {
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
56
vendor/github.com/99designs/gqlgen/codegen/field.go
generated
vendored
56
vendor/github.com/99designs/gqlgen/codegen/field.go
generated
vendored
|
|
@ -3,7 +3,6 @@ package codegen
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
goast "go/ast"
|
|
||||||
"go/types"
|
"go/types"
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -13,8 +12,6 @@ import (
|
||||||
"github.com/99designs/gqlgen/codegen/config"
|
"github.com/99designs/gqlgen/codegen/config"
|
||||||
"github.com/99designs/gqlgen/codegen/templates"
|
"github.com/99designs/gqlgen/codegen/templates"
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
"golang.org/x/text/cases"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Field struct {
|
type Field struct {
|
||||||
|
|
@ -74,7 +71,7 @@ func (b *builder) buildField(obj *Object, field *ast.FieldDefinition) (*Field, e
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.IsResolver && b.Config.ResolversAlwaysReturnPointers && !f.TypeReference.IsPtr() && f.TypeReference.IsStruct() {
|
if f.IsResolver && !f.TypeReference.IsPtr() && f.TypeReference.IsStruct() {
|
||||||
f.TypeReference = b.Binder.PointerTo(f.TypeReference)
|
f.TypeReference = b.Binder.PointerTo(f.TypeReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,8 +179,8 @@ func (b *builder) bindField(obj *Object, f *Field) (errret error) {
|
||||||
params = types.NewTuple(vars...)
|
params = types.NewTuple(vars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to match target function's arguments with GraphQL field arguments.
|
// Try to match target function's arguments with GraphQL field arguments
|
||||||
newArgs, err := b.bindArgs(f, sig, params)
|
newArgs, err := b.bindArgs(f, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s:%d: %w", pos.Filename, pos.Line, err)
|
return fmt.Errorf("%s:%d: %w", pos.Filename, pos.Line, err)
|
||||||
}
|
}
|
||||||
|
|
@ -472,11 +469,10 @@ func (f *Field) GoNameUnexported() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Field) ShortInvocation() string {
|
func (f *Field) ShortInvocation() string {
|
||||||
caser := cases.Title(language.English, cases.NoLower)
|
|
||||||
if f.Object.Kind == ast.InputObject {
|
if f.Object.Kind == ast.InputObject {
|
||||||
return fmt.Sprintf("%s().%s(ctx, &it, data)", caser.String(f.Object.Definition.Name), f.GoFieldName)
|
return fmt.Sprintf("%s().%s(ctx, &it, data)", strings.Title(f.Object.Definition.Name), f.GoFieldName)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s().%s(%s)", caser.String(f.Object.Definition.Name), f.GoFieldName, f.CallArgs())
|
return fmt.Sprintf("%s().%s(%s)", strings.Title(f.Object.Definition.Name), f.GoFieldName, f.CallArgs())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Field) ArgsFunc() string {
|
func (f *Field) ArgsFunc() string {
|
||||||
|
|
@ -487,14 +483,6 @@ func (f *Field) ArgsFunc() string {
|
||||||
return "field_" + f.Object.Definition.Name + "_" + f.Name + "_args"
|
return "field_" + f.Object.Definition.Name + "_" + f.Name + "_args"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Field) FieldContextFunc() string {
|
|
||||||
return "fieldContext_" + f.Object.Definition.Name + "_" + f.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Field) ChildFieldContextFunc(name string) string {
|
|
||||||
return "fieldContext_" + f.TypeReference.Definition.Name + "_" + name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Field) ResolverType() string {
|
func (f *Field) ResolverType() string {
|
||||||
if !f.IsResolver {
|
if !f.IsResolver {
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -504,12 +492,6 @@ func (f *Field) ResolverType() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Field) ShortResolverDeclaration() string {
|
func (f *Field) ShortResolverDeclaration() string {
|
||||||
return f.ShortResolverSignature(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShortResolverSignature is identical to ShortResolverDeclaration,
|
|
||||||
// but respects previous naming (return) conventions, if any.
|
|
||||||
func (f *Field) ShortResolverSignature(ft *goast.FuncType) string {
|
|
||||||
if f.Object.Kind == ast.InputObject {
|
if f.Object.Kind == ast.InputObject {
|
||||||
return fmt.Sprintf("(ctx context.Context, obj %s, data %s) error",
|
return fmt.Sprintf("(ctx context.Context, obj %s, data %s) error",
|
||||||
templates.CurrentImports.LookupType(f.Object.Reference()),
|
templates.CurrentImports.LookupType(f.Object.Reference()),
|
||||||
|
|
@ -530,17 +512,8 @@ func (f *Field) ShortResolverSignature(ft *goast.FuncType) string {
|
||||||
if f.Object.Stream {
|
if f.Object.Stream {
|
||||||
result = "<-chan " + result
|
result = "<-chan " + result
|
||||||
}
|
}
|
||||||
// Named return.
|
|
||||||
var namedV, namedE string
|
res += fmt.Sprintf(") (%s, error)", result)
|
||||||
if ft != nil {
|
|
||||||
if ft.Results != nil && len(ft.Results.List) > 0 && len(ft.Results.List[0].Names) > 0 {
|
|
||||||
namedV = ft.Results.List[0].Names[0].Name
|
|
||||||
}
|
|
||||||
if ft.Results != nil && len(ft.Results.List) > 1 && len(ft.Results.List[1].Names) > 0 {
|
|
||||||
namedE = ft.Results.List[1].Names[0].Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res += fmt.Sprintf(") (%s %s, %s error)", namedV, result, namedE)
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -576,20 +549,7 @@ func (f *Field) CallArgs() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range f.Args {
|
for _, arg := range f.Args {
|
||||||
tmp := "fc.Args[" + strconv.Quote(arg.Name) + "].(" + templates.CurrentImports.LookupType(arg.TypeReference.GO) + ")"
|
args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")")
|
||||||
|
|
||||||
if iface, ok := arg.TypeReference.GO.(*types.Interface); ok && iface.Empty() {
|
|
||||||
tmp = fmt.Sprintf(`
|
|
||||||
func () interface{} {
|
|
||||||
if fc.Args["%s"] == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fc.Args["%s"].(interface{})
|
|
||||||
}()`, arg.Name, arg.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
args = append(args, tmp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(args, ", ")
|
return strings.Join(args, ", ")
|
||||||
|
|
|
||||||
73
vendor/github.com/99designs/gqlgen/codegen/field.gotpl
generated
vendored
73
vendor/github.com/99designs/gqlgen/codegen/field.gotpl
generated
vendored
|
|
@ -1,21 +1,34 @@
|
||||||
{{- range $object := .Objects }}{{- range $field := $object.Fields }}
|
{{- range $object := .Objects }}{{- range $field := $object.Fields }}
|
||||||
|
|
||||||
func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Context, field graphql.CollectedField{{ if not $object.Root }}, obj {{$object.Reference | ref}}{{end}}) (ret {{ if $object.Stream }}func(ctx context.Context){{ end }}graphql.Marshaler) {
|
func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Context, field graphql.CollectedField{{ if not $object.Root }}, obj {{$object.Reference | ref}}{{end}}) (ret {{ if $object.Stream }}func(){{ end }}graphql.Marshaler) {
|
||||||
{{- $null := "graphql.Null" }}
|
{{- $null := "graphql.Null" }}
|
||||||
{{- if $object.Stream }}
|
{{- if $object.Stream }}
|
||||||
{{- $null = "nil" }}
|
{{- $null = "nil" }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
fc, err := ec.{{ $field.FieldContextFunc }}(ctx, field)
|
|
||||||
if err != nil {
|
|
||||||
return {{ $null }}
|
|
||||||
}
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
defer func () {
|
defer func () {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
ret = {{ $null }}
|
ret = {{ $null }}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: {{$object.Name|quote}},
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: {{or $field.IsMethod $field.IsResolver}},
|
||||||
|
IsResolver: {{ $field.IsResolver }},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
{{- if $field.Args }}
|
||||||
|
rawArgs := field.ArgumentMap(ec.Variables)
|
||||||
|
args, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return {{ $null }}
|
||||||
|
}
|
||||||
|
fc.Args = args
|
||||||
|
{{- end }}
|
||||||
{{- if $.AllDirectives.LocationDirectives "FIELD" }}
|
{{- if $.AllDirectives.LocationDirectives "FIELD" }}
|
||||||
resTmp := ec._fieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
|
resTmp := ec._fieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
|
||||||
{{ template "field" $field }}
|
{{ template "field" $field }}
|
||||||
|
|
@ -26,9 +39,7 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec.Error(ctx, err)
|
ec.Error(ctx, err)
|
||||||
{{- if not $object.Root }}
|
|
||||||
return {{ $null }}
|
return {{ $null }}
|
||||||
{{- end }}
|
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
if resTmp == nil {
|
if resTmp == nil {
|
||||||
|
|
@ -40,9 +51,8 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
|
||||||
return {{ $null }}
|
return {{ $null }}
|
||||||
}
|
}
|
||||||
{{- if $object.Stream }}
|
{{- if $object.Stream }}
|
||||||
return func(ctx context.Context) graphql.Marshaler {
|
return func() graphql.Marshaler {
|
||||||
select {
|
res, ok := <-resTmp.(<-chan {{$field.TypeReference.GO | ref}})
|
||||||
case res, ok := <-resTmp.(<-chan {{$field.TypeReference.GO | ref}}):
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -53,9 +63,6 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
|
||||||
ec.{{ $field.TypeReference.MarshalFunc }}(ctx, field.Selections, res).MarshalGQL(w)
|
ec.{{ $field.TypeReference.MarshalFunc }}(ctx, field.Selections, res).MarshalGQL(w)
|
||||||
w.Write([]byte{'}'})
|
w.Write([]byte{'}'})
|
||||||
})
|
})
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
res := resTmp.({{$field.TypeReference.GO | ref}})
|
res := resTmp.({{$field.TypeReference.GO | ref}})
|
||||||
|
|
@ -64,44 +71,6 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) {{ $field.FieldContextFunc }}(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
|
||||||
fc = &graphql.FieldContext{
|
|
||||||
Object: {{quote $field.Object.Name}},
|
|
||||||
Field: field,
|
|
||||||
IsMethod: {{or $field.IsMethod $field.IsResolver}},
|
|
||||||
IsResolver: {{ $field.IsResolver }},
|
|
||||||
Child: func (ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
|
||||||
{{- if not $field.TypeReference.Definition.Fields }}
|
|
||||||
return nil, errors.New("field of type {{ $field.TypeReference.Definition.Name }} does not have child fields")
|
|
||||||
{{- else if ne $field.TypeReference.Definition.Kind "OBJECT" }}
|
|
||||||
return nil, errors.New("FieldContext.Child cannot be called on type {{ $field.TypeReference.Definition.Kind }}")
|
|
||||||
{{- else }}
|
|
||||||
switch field.Name {
|
|
||||||
{{- range $f := $field.TypeReference.Definition.Fields }}
|
|
||||||
case "{{ $f.Name }}":
|
|
||||||
return ec.{{ $field.ChildFieldContextFunc $f.Name }}(ctx, field)
|
|
||||||
{{- end }}
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("no field named %q was found under type {{ $field.TypeReference.Definition.Name }}", field.Name)
|
|
||||||
{{- end }}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
{{- if $field.Args }}
|
|
||||||
defer func () {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
err = ec.Recover(ctx, r)
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
if fc.Args, err = ec.{{ $field.ArgsFunc }}(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
{{- end }}
|
|
||||||
return fc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
{{- end }}{{- end}}
|
{{- end }}{{- end}}
|
||||||
|
|
||||||
{{ define "field" }}
|
{{ define "field" }}
|
||||||
|
|
|
||||||
11
vendor/github.com/99designs/gqlgen/codegen/generate.go
generated
vendored
11
vendor/github.com/99designs/gqlgen/codegen/generate.go
generated
vendored
|
|
@ -1,10 +1,9 @@
|
||||||
package codegen
|
package codegen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -14,9 +13,6 @@ import (
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed *.gotpl
|
|
||||||
var codegenTemplates embed.FS
|
|
||||||
|
|
||||||
func GenerateCode(data *Data) error {
|
func GenerateCode(data *Data) error {
|
||||||
if !data.Config.Exec.IsDefined() {
|
if !data.Config.Exec.IsDefined() {
|
||||||
return fmt.Errorf("missing exec config")
|
return fmt.Errorf("missing exec config")
|
||||||
|
|
@ -40,7 +36,6 @@ func generateSingleFile(data *Data) error {
|
||||||
RegionTags: true,
|
RegionTags: true,
|
||||||
GeneratedHeader: true,
|
GeneratedHeader: true,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
TemplateFS: codegenTemplates,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +82,6 @@ func generatePerSchema(data *Data) error {
|
||||||
RegionTags: true,
|
RegionTags: true,
|
||||||
GeneratedHeader: true,
|
GeneratedHeader: true,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
TemplateFS: codegenTemplates,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -137,7 +131,7 @@ func generateRootFile(data *Data) error {
|
||||||
_, thisFile, _, _ := runtime.Caller(0)
|
_, thisFile, _, _ := runtime.Caller(0)
|
||||||
rootDir := filepath.Dir(thisFile)
|
rootDir := filepath.Dir(thisFile)
|
||||||
templatePath := filepath.Join(rootDir, "root_.gotpl")
|
templatePath := filepath.Join(rootDir, "root_.gotpl")
|
||||||
templateBytes, err := os.ReadFile(templatePath)
|
templateBytes, err := ioutil.ReadFile(templatePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +145,6 @@ func generateRootFile(data *Data) error {
|
||||||
RegionTags: false,
|
RegionTags: false,
|
||||||
GeneratedHeader: true,
|
GeneratedHeader: true,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
TemplateFS: codegenTemplates,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
33
vendor/github.com/99designs/gqlgen/codegen/generated!.gotpl
generated
vendored
33
vendor/github.com/99designs/gqlgen/codegen/generated!.gotpl
generated
vendored
|
|
@ -7,7 +7,6 @@
|
||||||
{{ reserveImport "sync/atomic" }}
|
{{ reserveImport "sync/atomic" }}
|
||||||
{{ reserveImport "errors" }}
|
{{ reserveImport "errors" }}
|
||||||
{{ reserveImport "bytes" }}
|
{{ reserveImport "bytes" }}
|
||||||
{{ reserveImport "embed" }}
|
|
||||||
|
|
||||||
{{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }}
|
{{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }}
|
||||||
{{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}
|
{{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}
|
||||||
|
|
@ -51,7 +50,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComplexityRoot struct {
|
type ComplexityRoot struct {
|
||||||
{{- if not .Config.OmitComplexity }}
|
|
||||||
{{ range $object := .Objects }}
|
{{ range $object := .Objects }}
|
||||||
{{ if not $object.IsReserved -}}
|
{{ if not $object.IsReserved -}}
|
||||||
{{ ucFirst $object.Name }} struct {
|
{{ ucFirst $object.Name }} struct {
|
||||||
|
|
@ -64,7 +62,6 @@
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end }}
|
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
@ -106,7 +103,6 @@
|
||||||
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {
|
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {
|
||||||
ec := executionContext{nil, e}
|
ec := executionContext{nil, e}
|
||||||
_ = ec
|
_ = ec
|
||||||
{{ if not .Config.OmitComplexity -}}
|
|
||||||
switch typeName + "." + field {
|
switch typeName + "." + field {
|
||||||
{{ range $object := .Objects }}
|
{{ range $object := .Objects }}
|
||||||
{{ if not $object.IsReserved }}
|
{{ if not $object.IsReserved }}
|
||||||
|
|
@ -133,20 +129,12 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
{{- end }}
|
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||||
rc := graphql.GetOperationContext(ctx)
|
rc := graphql.GetOperationContext(ctx)
|
||||||
ec := executionContext{rc, e}
|
ec := executionContext{rc, e}
|
||||||
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
|
|
||||||
{{- range $input := .Inputs -}}
|
|
||||||
{{ if not $input.HasUnmarshal }}
|
|
||||||
ec.unmarshalInput{{ $input.Name }},
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
)
|
|
||||||
first := true
|
first := true
|
||||||
|
|
||||||
switch rc.Operation.Operation {
|
switch rc.Operation.Operation {
|
||||||
|
|
@ -154,7 +142,6 @@
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
if !first { return nil }
|
if !first { return nil }
|
||||||
first = false
|
first = false
|
||||||
ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap)
|
|
||||||
{{ if .Directives.LocationDirectives "QUERY" -}}
|
{{ if .Directives.LocationDirectives "QUERY" -}}
|
||||||
data := ec._queryMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
data := ec._queryMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
||||||
return ec._{{.QueryRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
return ec._{{.QueryRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
||||||
|
|
@ -175,7 +162,6 @@
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
if !first { return nil }
|
if !first { return nil }
|
||||||
first = false
|
first = false
|
||||||
ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap)
|
|
||||||
{{ if .Directives.LocationDirectives "MUTATION" -}}
|
{{ if .Directives.LocationDirectives "MUTATION" -}}
|
||||||
data := ec._mutationMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
data := ec._mutationMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
||||||
return ec._{{.MutationRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
return ec._{{.MutationRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
||||||
|
|
@ -204,7 +190,7 @@
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
data := next(ctx)
|
data := next()
|
||||||
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -240,22 +226,9 @@
|
||||||
return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil
|
return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
{{if .HasEmbeddableSources }}
|
|
||||||
//go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }}
|
|
||||||
var sourcesFS embed.FS
|
|
||||||
|
|
||||||
func sourceData(filename string) string {
|
|
||||||
data, err := sourcesFS.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("codegen problem: %s not available", filename))
|
|
||||||
}
|
|
||||||
return string(data)
|
|
||||||
}
|
|
||||||
{{- end }}
|
|
||||||
|
|
||||||
var sources = []*ast.Source{
|
var sources = []*ast.Source{
|
||||||
{{- range $source := .AugmentedSources }}
|
{{- range $source := .Config.Sources }}
|
||||||
{Name: {{$source.RelativePath|quote}}, Input: {{if (not $source.Embeddable)}}{{$source.Source|rawQuote}}{{else}}sourceData({{$source.RelativePath|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}},
|
{Name: {{$source.Name|quote}}, Input: {{$source.Input|rawQuote}}, BuiltIn: {{$source.BuiltIn}}},
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
var parsedSchema = gqlparser.MustLoadSchema(sources...)
|
var parsedSchema = gqlparser.MustLoadSchema(sources...)
|
||||||
|
|
|
||||||
27
vendor/github.com/99designs/gqlgen/codegen/input.gotpl
generated
vendored
27
vendor/github.com/99designs/gqlgen/codegen/input.gotpl
generated
vendored
|
|
@ -1,10 +1,6 @@
|
||||||
{{- range $input := .Inputs }}
|
{{- range $input := .Inputs }}
|
||||||
{{- if not .HasUnmarshal }}
|
{{- if not .HasUnmarshal }}
|
||||||
{{- $it := "it" }}
|
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{.Type | ref}}, error) {
|
||||||
{{- if .PointersInUmarshalInput }}
|
|
||||||
{{- $it = "&it" }}
|
|
||||||
{{- end }}
|
|
||||||
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{ if .PointersInUmarshalInput }}*{{ end }}{{.Type | ref}}, error) {
|
|
||||||
var it {{.Type | ref}}
|
var it {{.Type | ref}}
|
||||||
asMap := map[string]interface{}{}
|
asMap := map[string]interface{}{}
|
||||||
for k, v := range obj.(map[string]interface{}) {
|
for k, v := range obj.(map[string]interface{}) {
|
||||||
|
|
@ -18,12 +14,7 @@
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
fieldsInOrder := [...]string{ {{ range .Fields }}{{ quote .Name }},{{ end }} }
|
for k, v := range asMap {
|
||||||
for _, k := range fieldsInOrder {
|
|
||||||
v, ok := asMap[k]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch k {
|
switch k {
|
||||||
{{- range $field := .Fields }}
|
{{- range $field := .Fields }}
|
||||||
case {{$field.Name|quote}}:
|
case {{$field.Name|quote}}:
|
||||||
|
|
@ -35,12 +26,12 @@
|
||||||
{{ template "implDirectives" $field }}
|
{{ template "implDirectives" $field }}
|
||||||
tmp, err := directive{{$field.ImplDirectives|len}}(ctx)
|
tmp, err := directive{{$field.ImplDirectives|len}}(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return {{$it}}, graphql.ErrorOnPath(ctx, err)
|
return it, graphql.ErrorOnPath(ctx, err)
|
||||||
}
|
}
|
||||||
if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
|
if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok {
|
||||||
{{- if $field.IsResolver }}
|
{{- if $field.IsResolver }}
|
||||||
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
||||||
return {{$it}}, err
|
return it, err
|
||||||
}
|
}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
it.{{$field.GoFieldName}} = data
|
it.{{$field.GoFieldName}} = data
|
||||||
|
|
@ -53,21 +44,21 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
} else {
|
} else {
|
||||||
err := fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
|
err := fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp)
|
||||||
return {{$it}}, graphql.ErrorOnPath(ctx, err)
|
return it, graphql.ErrorOnPath(ctx, err)
|
||||||
}
|
}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- if $field.IsResolver }}
|
{{- if $field.IsResolver }}
|
||||||
data, err := ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
data, err := ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return {{$it}}, err
|
return it, err
|
||||||
}
|
}
|
||||||
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
if err = ec.resolvers.{{ $field.ShortInvocation }}; err != nil {
|
||||||
return {{$it}}, err
|
return it, err
|
||||||
}
|
}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
it.{{$field.GoFieldName}}, err = ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
it.{{$field.GoFieldName}}, err = ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return {{$it}}, err
|
return it, err
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
@ -75,7 +66,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {{$it}}, nil
|
return it, nil
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
8
vendor/github.com/99designs/gqlgen/codegen/object.go
generated
vendored
8
vendor/github.com/99designs/gqlgen/codegen/object.go
generated
vendored
|
|
@ -9,8 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/codegen/config"
|
"github.com/99designs/gqlgen/codegen/config"
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
"golang.org/x/text/cases"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GoFieldType int
|
type GoFieldType int
|
||||||
|
|
@ -33,7 +31,6 @@ type Object struct {
|
||||||
DisableConcurrency bool
|
DisableConcurrency bool
|
||||||
Stream bool
|
Stream bool
|
||||||
Directives []*Directive
|
Directives []*Directive
|
||||||
PointersInUmarshalInput bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *builder) buildObject(typ *ast.Definition) (*Object, error) {
|
func (b *builder) buildObject(typ *ast.Definition) (*Object, error) {
|
||||||
|
|
@ -41,16 +38,15 @@ func (b *builder) buildObject(typ *ast.Definition) (*Object, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", typ.Name, err)
|
return nil, fmt.Errorf("%s: %w", typ.Name, err)
|
||||||
}
|
}
|
||||||
caser := cases.Title(language.English, cases.NoLower)
|
|
||||||
obj := &Object{
|
obj := &Object{
|
||||||
Definition: typ,
|
Definition: typ,
|
||||||
Root: b.Schema.Query == typ || b.Schema.Mutation == typ || b.Schema.Subscription == typ,
|
Root: b.Schema.Query == typ || b.Schema.Mutation == typ || b.Schema.Subscription == typ,
|
||||||
DisableConcurrency: typ == b.Schema.Mutation,
|
DisableConcurrency: typ == b.Schema.Mutation,
|
||||||
Stream: typ == b.Schema.Subscription,
|
Stream: typ == b.Schema.Subscription,
|
||||||
Directives: dirs,
|
Directives: dirs,
|
||||||
PointersInUmarshalInput: b.Config.ReturnPointersInUmarshalInput,
|
|
||||||
ResolverInterface: types.NewNamed(
|
ResolverInterface: types.NewNamed(
|
||||||
types.NewTypeName(0, b.Config.Exec.Pkg(), caser.String(typ.Name)+"Resolver", nil),
|
types.NewTypeName(0, b.Config.Exec.Pkg(), strings.Title(typ.Name)+"Resolver", nil),
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
19
vendor/github.com/99designs/gqlgen/codegen/object.gotpl
generated
vendored
19
vendor/github.com/99designs/gqlgen/codegen/object.gotpl
generated
vendored
|
|
@ -3,7 +3,7 @@
|
||||||
var {{ $object.Name|lcFirst}}Implementors = {{$object.Implementors}}
|
var {{ $object.Name|lcFirst}}Implementors = {{$object.Implementors}}
|
||||||
|
|
||||||
{{- if .Stream }}
|
{{- if .Stream }}
|
||||||
func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet) func(ctx context.Context) graphql.Marshaler {
|
func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {
|
||||||
fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors)
|
fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors)
|
||||||
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
|
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
|
||||||
Object: {{$object.Name|quote}},
|
Object: {{$object.Name|quote}},
|
||||||
|
|
@ -31,9 +31,7 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
|
||||||
})
|
})
|
||||||
{{end}}
|
{{end}}
|
||||||
out := graphql.NewFieldSet(fields)
|
out := graphql.NewFieldSet(fields)
|
||||||
{{- if not $object.Root }}
|
|
||||||
var invalids uint32
|
var invalids uint32
|
||||||
{{- end }}
|
|
||||||
for i, field := range fields {
|
for i, field := range fields {
|
||||||
{{- if $object.Root }}
|
{{- if $object.Root }}
|
||||||
innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{
|
innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{
|
||||||
|
|
@ -56,7 +54,6 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
|
res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
|
||||||
{{- if not $object.Root }}
|
|
||||||
{{- if $field.TypeReference.GQL.NonNull }}
|
{{- if $field.TypeReference.GQL.NonNull }}
|
||||||
if res == graphql.Null {
|
if res == graphql.Null {
|
||||||
{{- if $object.IsConcurrent }}
|
{{- if $object.IsConcurrent }}
|
||||||
|
|
@ -66,7 +63,6 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,15 +80,15 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
|
||||||
{{end}}
|
{{end}}
|
||||||
})
|
})
|
||||||
{{- else }}
|
{{- else }}
|
||||||
|
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
|
||||||
|
return ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
|
||||||
|
}
|
||||||
{{if $object.Root}}
|
{{if $object.Root}}
|
||||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, innerFunc)
|
||||||
return ec._{{$object.Name}}_{{$field.Name}}(ctx, field)
|
|
||||||
})
|
|
||||||
{{else}}
|
{{else}}
|
||||||
out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field, obj)
|
out.Values[i] = innerFunc(ctx)
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{- if not $object.Root }}
|
|
||||||
{{- if $field.TypeReference.GQL.NonNull }}
|
{{- if $field.TypeReference.GQL.NonNull }}
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
{{- if $object.IsConcurrent }}
|
{{- if $object.IsConcurrent }}
|
||||||
|
|
@ -104,15 +100,12 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
|
||||||
default:
|
default:
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
panic("unknown field " + strconv.Quote(field.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.Dispatch()
|
out.Dispatch()
|
||||||
{{- if not $object.Root }}
|
|
||||||
if invalids > 0 { return graphql.Null }
|
if invalids > 0 { return graphql.Null }
|
||||||
{{- end }}
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
||||||
39
vendor/github.com/99designs/gqlgen/codegen/root_.gotpl
generated
vendored
39
vendor/github.com/99designs/gqlgen/codegen/root_.gotpl
generated
vendored
|
|
@ -7,7 +7,6 @@
|
||||||
{{ reserveImport "sync/atomic" }}
|
{{ reserveImport "sync/atomic" }}
|
||||||
{{ reserveImport "errors" }}
|
{{ reserveImport "errors" }}
|
||||||
{{ reserveImport "bytes" }}
|
{{ reserveImport "bytes" }}
|
||||||
{{ reserveImport "embed" }}
|
|
||||||
|
|
||||||
{{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }}
|
{{ reserveImport "github.com/vektah/gqlparser/v2" "gqlparser" }}
|
||||||
{{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}
|
{{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}
|
||||||
|
|
@ -35,11 +34,6 @@ type ResolverRoot interface {
|
||||||
{{ucFirst $object.Name}}() {{ucFirst $object.Name}}Resolver
|
{{ucFirst $object.Name}}() {{ucFirst $object.Name}}Resolver
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- range $object := .Inputs -}}
|
|
||||||
{{ if $object.HasResolvers -}}
|
|
||||||
{{ucFirst $object.Name}}() {{ucFirst $object.Name}}Resolver
|
|
||||||
{{ end }}
|
|
||||||
{{- end }}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DirectiveRoot struct {
|
type DirectiveRoot struct {
|
||||||
|
|
@ -49,7 +43,6 @@ type DirectiveRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComplexityRoot struct {
|
type ComplexityRoot struct {
|
||||||
{{- if not .Config.OmitComplexity }}
|
|
||||||
{{ range $object := .Objects }}
|
{{ range $object := .Objects }}
|
||||||
{{ if not $object.IsReserved -}}
|
{{ if not $object.IsReserved -}}
|
||||||
{{ ucFirst $object.Name }} struct {
|
{{ ucFirst $object.Name }} struct {
|
||||||
|
|
@ -62,7 +55,6 @@ type ComplexityRoot struct {
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end }}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type executableSchema struct {
|
type executableSchema struct {
|
||||||
|
|
@ -78,7 +70,6 @@ func (e *executableSchema) Schema() *ast.Schema {
|
||||||
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {
|
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {
|
||||||
ec := executionContext{nil, e}
|
ec := executionContext{nil, e}
|
||||||
_ = ec
|
_ = ec
|
||||||
{{- if not .Config.OmitComplexity }}
|
|
||||||
switch typeName + "." + field {
|
switch typeName + "." + field {
|
||||||
{{ range $object := .Objects }}
|
{{ range $object := .Objects }}
|
||||||
{{ if not $object.IsReserved }}
|
{{ if not $object.IsReserved }}
|
||||||
|
|
@ -105,20 +96,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
{{- end }}
|
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||||
rc := graphql.GetOperationContext(ctx)
|
rc := graphql.GetOperationContext(ctx)
|
||||||
ec := executionContext{rc, e}
|
ec := executionContext{rc, e}
|
||||||
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
|
|
||||||
{{- range $input := .Inputs -}}
|
|
||||||
{{ if not $input.HasUnmarshal }}
|
|
||||||
ec.unmarshalInput{{ $input.Name }},
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
)
|
|
||||||
first := true
|
first := true
|
||||||
|
|
||||||
switch rc.Operation.Operation {
|
switch rc.Operation.Operation {
|
||||||
|
|
@ -126,7 +109,6 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
if !first { return nil }
|
if !first { return nil }
|
||||||
first = false
|
first = false
|
||||||
ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap)
|
|
||||||
{{ if .Directives.LocationDirectives "QUERY" -}}
|
{{ if .Directives.LocationDirectives "QUERY" -}}
|
||||||
data := ec._queryMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
data := ec._queryMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
||||||
return ec._{{.QueryRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
return ec._{{.QueryRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
||||||
|
|
@ -147,7 +129,6 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
if !first { return nil }
|
if !first { return nil }
|
||||||
first = false
|
first = false
|
||||||
ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap)
|
|
||||||
{{ if .Directives.LocationDirectives "MUTATION" -}}
|
{{ if .Directives.LocationDirectives "MUTATION" -}}
|
||||||
data := ec._mutationMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
data := ec._mutationMiddleware(ctx, rc.Operation, func(ctx context.Context) (interface{}, error){
|
||||||
return ec._{{.MutationRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
return ec._{{.MutationRoot.Name}}(ctx, rc.Operation.SelectionSet), nil
|
||||||
|
|
@ -176,7 +157,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
return func(ctx context.Context) *graphql.Response {
|
return func(ctx context.Context) *graphql.Response {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
data := next(ctx)
|
data := next()
|
||||||
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -212,23 +193,9 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er
|
||||||
return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil
|
return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{{if .HasEmbeddableSources }}
|
|
||||||
//go:embed{{- range $source := .AugmentedSources }}{{if $source.Embeddable}} {{$source.RelativePath|quote}}{{end}}{{- end }}
|
|
||||||
var sourcesFS embed.FS
|
|
||||||
|
|
||||||
func sourceData(filename string) string {
|
|
||||||
data, err := sourcesFS.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("codegen problem: %s not available", filename))
|
|
||||||
}
|
|
||||||
return string(data)
|
|
||||||
}
|
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
var sources = []*ast.Source{
|
var sources = []*ast.Source{
|
||||||
{{- range $source := .AugmentedSources }}
|
{{- range $source := .Config.Sources }}
|
||||||
{Name: {{$source.RelativePath|quote}}, Input: {{if (not $source.Embeddable)}}{{$source.Source|rawQuote}}{{else}}sourceData({{$source.RelativePath|quote}}){{end}}, BuiltIn: {{$source.BuiltIn}}},
|
{Name: {{$source.Name|quote}}, Input: {{$source.Input|rawQuote}}, BuiltIn: {{$source.BuiltIn}}},
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
var parsedSchema = gqlparser.MustLoadSchema(sources...)
|
var parsedSchema = gqlparser.MustLoadSchema(sources...)
|
||||||
|
|
|
||||||
4
vendor/github.com/99designs/gqlgen/codegen/templates/import.go
generated
vendored
4
vendor/github.com/99designs/gqlgen/codegen/templates/import.go
generated
vendored
|
|
@ -45,7 +45,7 @@ func (s *Imports) Reserve(path string, aliases ...string) (string, error) {
|
||||||
panic("empty ambient import")
|
panic("empty ambient import")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we are referencing our own package we don't need an import
|
// if we are referencing our own package we dont need an import
|
||||||
if code.ImportPathForDir(s.destDir) == path {
|
if code.ImportPathForDir(s.destDir) == path {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ func (s *Imports) Lookup(path string) string {
|
||||||
|
|
||||||
path = code.NormalizeVendor(path)
|
path = code.NormalizeVendor(path)
|
||||||
|
|
||||||
// if we are referencing our own package we don't need an import
|
// if we are referencing our own package we dont need an import
|
||||||
if code.ImportPathForDir(s.destDir) == path {
|
if code.ImportPathForDir(s.destDir) == path {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
281
vendor/github.com/99designs/gqlgen/codegen/templates/templates.go
generated
vendored
281
vendor/github.com/99designs/gqlgen/codegen/templates/templates.go
generated
vendored
|
|
@ -4,16 +4,14 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io/fs"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
|
@ -38,11 +36,6 @@ type Options struct {
|
||||||
// the plugin processor will look for .gotpl files
|
// the plugin processor will look for .gotpl files
|
||||||
// in the same directory of where you wrote the plugin.
|
// in the same directory of where you wrote the plugin.
|
||||||
Template string
|
Template string
|
||||||
|
|
||||||
// Use the go:embed API to collect all the template files you want to pass into Render
|
|
||||||
// this is an alternative to passing the Template option
|
|
||||||
TemplateFS fs.FS
|
|
||||||
|
|
||||||
// Filename is the name of the file that will be
|
// Filename is the name of the file that will be
|
||||||
// written to the system disk once the template is rendered.
|
// written to the system disk once the template is rendered.
|
||||||
Filename string
|
Filename string
|
||||||
|
|
@ -60,12 +53,6 @@ type Options struct {
|
||||||
Packages *code.Packages
|
Packages *code.Packages
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
modelNamesMu sync.Mutex
|
|
||||||
modelNames = make(map[string]string, 0)
|
|
||||||
goNameRe = regexp.MustCompile("[^a-zA-Z0-9_]")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Render renders a gql plugin template from the given Options. Render is an
|
// Render renders a gql plugin template from the given Options. Render is an
|
||||||
// abstraction of the text/template package that makes it easier to write gqlgen
|
// abstraction of the text/template package that makes it easier to write gqlgen
|
||||||
// plugins. If Options.Template is empty, the Render function will look for `.gotpl`
|
// plugins. If Options.Template is empty, the Render function will look for `.gotpl`
|
||||||
|
|
@ -76,27 +63,55 @@ func Render(cfg Options) error {
|
||||||
}
|
}
|
||||||
CurrentImports = &Imports{packages: cfg.Packages, destDir: filepath.Dir(cfg.Filename)}
|
CurrentImports = &Imports{packages: cfg.Packages, destDir: filepath.Dir(cfg.Filename)}
|
||||||
|
|
||||||
|
// load path relative to calling source file
|
||||||
|
_, callerFile, _, _ := runtime.Caller(1)
|
||||||
|
rootDir := filepath.Dir(callerFile)
|
||||||
|
|
||||||
funcs := Funcs()
|
funcs := Funcs()
|
||||||
for n, f := range cfg.Funcs {
|
for n, f := range cfg.Funcs {
|
||||||
funcs[n] = f
|
funcs[n] = f
|
||||||
}
|
}
|
||||||
|
|
||||||
t := template.New("").Funcs(funcs)
|
t := template.New("").Funcs(funcs)
|
||||||
t, err := parseTemplates(cfg, t)
|
|
||||||
|
var roots []string
|
||||||
|
if cfg.Template != "" {
|
||||||
|
var err error
|
||||||
|
t, err = t.New("template.gotpl").Parse(cfg.Template)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error with provided template: %w", err)
|
||||||
|
}
|
||||||
|
roots = append(roots, "template.gotpl")
|
||||||
|
} else {
|
||||||
|
// load all the templates in the directory
|
||||||
|
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
name := filepath.ToSlash(strings.TrimPrefix(path, rootDir+string(os.PathSeparator)))
|
||||||
|
if !strings.HasSuffix(info.Name(), ".gotpl") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// omit any templates with "_" at the end of their name, which are meant for specific contexts only
|
||||||
|
if strings.HasSuffix(info.Name(), "_.gotpl") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
b, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
roots := make([]string, 0, len(t.Templates()))
|
t, err = t.New(name).Parse(string(b))
|
||||||
for _, template := range t.Templates() {
|
if err != nil {
|
||||||
// templates that end with _.gotpl are special files we don't want to include
|
return fmt.Errorf("%s: %w", cfg.Filename, err)
|
||||||
if strings.HasSuffix(template.Name(), "_.gotpl") ||
|
|
||||||
// filter out templates added with {{ template xxx }} syntax inside the template file
|
|
||||||
!strings.HasSuffix(template.Name(), ".gotpl") {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
roots = append(roots, template.Name())
|
roots = append(roots, name)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("locating templates: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then execute all the important looking ones in order, adding them to the same file
|
// then execute all the important looking ones in order, adding them to the same file
|
||||||
|
|
@ -110,7 +125,6 @@ func Render(cfg Options) error {
|
||||||
}
|
}
|
||||||
return roots[i] < roots[j]
|
return roots[i] < roots[j]
|
||||||
})
|
})
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for _, root := range roots {
|
for _, root := range roots {
|
||||||
if cfg.RegionTags {
|
if cfg.RegionTags {
|
||||||
|
|
@ -142,7 +156,7 @@ func Render(cfg Options) error {
|
||||||
result.WriteString("import (\n")
|
result.WriteString("import (\n")
|
||||||
result.WriteString(CurrentImports.String())
|
result.WriteString(CurrentImports.String())
|
||||||
result.WriteString(")\n")
|
result.WriteString(")\n")
|
||||||
_, err = buf.WriteTo(&result)
|
_, err := buf.WriteTo(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -157,34 +171,6 @@ func Render(cfg Options) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTemplates(cfg Options, t *template.Template) (*template.Template, error) {
|
|
||||||
if cfg.Template != "" {
|
|
||||||
var err error
|
|
||||||
t, err = t.New("template.gotpl").Parse(cfg.Template)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error with provided template: %w", err)
|
|
||||||
}
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileSystem fs.FS
|
|
||||||
if cfg.TemplateFS != nil {
|
|
||||||
fileSystem = cfg.TemplateFS
|
|
||||||
} else {
|
|
||||||
// load path relative to calling source file
|
|
||||||
_, callerFile, _, _ := runtime.Caller(1)
|
|
||||||
rootDir := filepath.Dir(callerFile)
|
|
||||||
fileSystem = os.DirFS(rootDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
t, err := t.ParseFS(fileSystem, "*.gotpl")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("locating templates: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func center(width int, pad string, s string) string {
|
func center(width int, pad string, s string) string {
|
||||||
if len(s)+2 > width {
|
if len(s)+2 > width {
|
||||||
return s
|
return s
|
||||||
|
|
@ -210,8 +196,6 @@ func Funcs() template.FuncMap {
|
||||||
"lookupImport": CurrentImports.Lookup,
|
"lookupImport": CurrentImports.Lookup,
|
||||||
"go": ToGo,
|
"go": ToGo,
|
||||||
"goPrivate": ToGoPrivate,
|
"goPrivate": ToGoPrivate,
|
||||||
"goModelName": ToGoModelName,
|
|
||||||
"goPrivateModelName": ToGoPrivateModelName,
|
|
||||||
"add": func(a, b int) int {
|
"add": func(a, b int) int {
|
||||||
return a + b
|
return a + b
|
||||||
},
|
},
|
||||||
|
|
@ -301,154 +285,25 @@ func Call(p *types.Func) string {
|
||||||
return pkg + p.Name()
|
return pkg + p.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetModelNames() {
|
|
||||||
modelNamesMu.Lock()
|
|
||||||
defer modelNamesMu.Unlock()
|
|
||||||
modelNames = make(map[string]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildGoModelNameKey(parts []string) string {
|
|
||||||
const sep = ":"
|
|
||||||
return strings.Join(parts, sep)
|
|
||||||
}
|
|
||||||
|
|
||||||
func goModelName(primaryToGoFunc func(string) string, parts []string) string {
|
|
||||||
modelNamesMu.Lock()
|
|
||||||
defer modelNamesMu.Unlock()
|
|
||||||
|
|
||||||
var (
|
|
||||||
goNameKey string
|
|
||||||
partLen int
|
|
||||||
|
|
||||||
nameExists = func(n string) bool {
|
|
||||||
for _, v := range modelNames {
|
|
||||||
if n == v {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
applyToGoFunc = func(parts []string) string {
|
|
||||||
var out string
|
|
||||||
switch len(parts) {
|
|
||||||
case 0:
|
|
||||||
return ""
|
|
||||||
case 1:
|
|
||||||
return primaryToGoFunc(parts[0])
|
|
||||||
default:
|
|
||||||
out = primaryToGoFunc(parts[0])
|
|
||||||
}
|
|
||||||
for _, p := range parts[1:] {
|
|
||||||
out = fmt.Sprintf("%s%s", out, ToGo(p))
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
applyValidGoName = func(parts []string) string {
|
|
||||||
var out string
|
|
||||||
for _, p := range parts {
|
|
||||||
out = fmt.Sprintf("%s%s", out, replaceInvalidCharacters(p))
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// build key for this entity
|
|
||||||
goNameKey = buildGoModelNameKey(parts)
|
|
||||||
|
|
||||||
// determine if we've seen this entity before, and reuse if so
|
|
||||||
if goName, ok := modelNames[goNameKey]; ok {
|
|
||||||
return goName
|
|
||||||
}
|
|
||||||
|
|
||||||
// attempt first pass
|
|
||||||
if goName := applyToGoFunc(parts); !nameExists(goName) {
|
|
||||||
modelNames[goNameKey] = goName
|
|
||||||
return goName
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine number of parts
|
|
||||||
partLen = len(parts)
|
|
||||||
|
|
||||||
// if there is only 1 part, append incrementing number until no conflict
|
|
||||||
if partLen == 1 {
|
|
||||||
base := applyToGoFunc(parts)
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
tmp := fmt.Sprintf("%s%d", base, i)
|
|
||||||
if !nameExists(tmp) {
|
|
||||||
modelNames[goNameKey] = tmp
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// best effort "pretty" name
|
|
||||||
for i := partLen - 1; i >= 1; i-- {
|
|
||||||
tmp := fmt.Sprintf("%s%s", applyToGoFunc(parts[0:i]), applyValidGoName(parts[i:]))
|
|
||||||
if !nameExists(tmp) {
|
|
||||||
modelNames[goNameKey] = tmp
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally, fallback to just adding an incrementing number
|
|
||||||
base := applyToGoFunc(parts)
|
|
||||||
for i := 0; ; i++ {
|
|
||||||
tmp := fmt.Sprintf("%s%d", base, i)
|
|
||||||
if !nameExists(tmp) {
|
|
||||||
modelNames[goNameKey] = tmp
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToGoModelName(parts ...string) string {
|
|
||||||
return goModelName(ToGo, parts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToGoPrivateModelName(parts ...string) string {
|
|
||||||
return goModelName(ToGoPrivate, parts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func replaceInvalidCharacters(in string) string {
|
|
||||||
return goNameRe.ReplaceAllLiteralString(in, "_")
|
|
||||||
}
|
|
||||||
|
|
||||||
func wordWalkerFunc(private bool, nameRunes *[]rune) func(*wordInfo) {
|
|
||||||
return func(info *wordInfo) {
|
|
||||||
word := info.Word
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case private && info.WordOffset == 0:
|
|
||||||
if strings.ToUpper(word) == word || strings.ToLower(word) == word {
|
|
||||||
// ID → id, CAMEL → camel
|
|
||||||
word = strings.ToLower(info.Word)
|
|
||||||
} else {
|
|
||||||
// ITicket → iTicket
|
|
||||||
word = LcFirst(info.Word)
|
|
||||||
}
|
|
||||||
|
|
||||||
case info.MatchCommonInitial:
|
|
||||||
word = strings.ToUpper(word)
|
|
||||||
|
|
||||||
case !info.HasCommonInitial && (strings.ToUpper(word) == word || strings.ToLower(word) == word):
|
|
||||||
// FOO or foo → Foo
|
|
||||||
// FOo → FOo
|
|
||||||
word = UcFirst(strings.ToLower(word))
|
|
||||||
}
|
|
||||||
|
|
||||||
*nameRunes = append(*nameRunes, []rune(word)...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToGo(name string) string {
|
func ToGo(name string) string {
|
||||||
if name == "_" {
|
if name == "_" {
|
||||||
return "_"
|
return "_"
|
||||||
}
|
}
|
||||||
runes := make([]rune, 0, len(name))
|
runes := make([]rune, 0, len(name))
|
||||||
|
|
||||||
wordWalker(name, wordWalkerFunc(false, &runes))
|
wordWalker(name, func(info *wordInfo) {
|
||||||
|
word := info.Word
|
||||||
|
if info.MatchCommonInitial {
|
||||||
|
word = strings.ToUpper(word)
|
||||||
|
} else if !info.HasCommonInitial {
|
||||||
|
if strings.ToUpper(word) == word || strings.ToLower(word) == word {
|
||||||
|
// FOO or foo → Foo
|
||||||
|
// FOo → FOo
|
||||||
|
word = UcFirst(strings.ToLower(word))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runes = append(runes, []rune(word)...)
|
||||||
|
})
|
||||||
|
|
||||||
return string(runes)
|
return string(runes)
|
||||||
}
|
}
|
||||||
|
|
@ -459,13 +314,31 @@ func ToGoPrivate(name string) string {
|
||||||
}
|
}
|
||||||
runes := make([]rune, 0, len(name))
|
runes := make([]rune, 0, len(name))
|
||||||
|
|
||||||
wordWalker(name, wordWalkerFunc(true, &runes))
|
first := true
|
||||||
|
wordWalker(name, func(info *wordInfo) {
|
||||||
|
word := info.Word
|
||||||
|
switch {
|
||||||
|
case first:
|
||||||
|
if strings.ToUpper(word) == word || strings.ToLower(word) == word {
|
||||||
|
// ID → id, CAMEL → camel
|
||||||
|
word = strings.ToLower(info.Word)
|
||||||
|
} else {
|
||||||
|
// ITicket → iTicket
|
||||||
|
word = LcFirst(info.Word)
|
||||||
|
}
|
||||||
|
first = false
|
||||||
|
case info.MatchCommonInitial:
|
||||||
|
word = strings.ToUpper(word)
|
||||||
|
case !info.HasCommonInitial:
|
||||||
|
word = UcFirst(strings.ToLower(word))
|
||||||
|
}
|
||||||
|
runes = append(runes, []rune(word)...)
|
||||||
|
})
|
||||||
|
|
||||||
return sanitizeKeywords(string(runes))
|
return sanitizeKeywords(string(runes))
|
||||||
}
|
}
|
||||||
|
|
||||||
type wordInfo struct {
|
type wordInfo struct {
|
||||||
WordOffset int
|
|
||||||
Word string
|
Word string
|
||||||
MatchCommonInitial bool
|
MatchCommonInitial bool
|
||||||
HasCommonInitial bool
|
HasCommonInitial bool
|
||||||
|
|
@ -475,7 +348,7 @@ type wordInfo struct {
|
||||||
// https://github.com/golang/lint/blob/06c8688daad7faa9da5a0c2f163a3d14aac986ca/lint.go#L679
|
// https://github.com/golang/lint/blob/06c8688daad7faa9da5a0c2f163a3d14aac986ca/lint.go#L679
|
||||||
func wordWalker(str string, f func(*wordInfo)) {
|
func wordWalker(str string, f func(*wordInfo)) {
|
||||||
runes := []rune(strings.TrimFunc(str, isDelimiter))
|
runes := []rune(strings.TrimFunc(str, isDelimiter))
|
||||||
w, i, wo := 0, 0, 0 // index of start of word, scan, word offset
|
w, i := 0, 0 // index of start of word, scan
|
||||||
hasCommonInitial := false
|
hasCommonInitial := false
|
||||||
for i+1 <= len(runes) {
|
for i+1 <= len(runes) {
|
||||||
eow := false // whether we hit the end of a word
|
eow := false // whether we hit the end of a word
|
||||||
|
|
@ -523,14 +396,12 @@ func wordWalker(str string, f func(*wordInfo)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f(&wordInfo{
|
f(&wordInfo{
|
||||||
WordOffset: wo,
|
|
||||||
Word: word,
|
Word: word,
|
||||||
MatchCommonInitial: matchCommonInitial,
|
MatchCommonInitial: matchCommonInitial,
|
||||||
HasCommonInitial: hasCommonInitial,
|
HasCommonInitial: hasCommonInitial,
|
||||||
})
|
})
|
||||||
hasCommonInitial = false
|
hasCommonInitial = false
|
||||||
w = i
|
w = i
|
||||||
wo++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -705,7 +576,7 @@ func resolveName(name string, skip int) string {
|
||||||
func render(filename string, tpldata interface{}) (*bytes.Buffer, error) {
|
func render(filename string, tpldata interface{}) (*bytes.Buffer, error) {
|
||||||
t := template.New("").Funcs(Funcs())
|
t := template.New("").Funcs(Funcs())
|
||||||
|
|
||||||
b, err := os.ReadFile(filename)
|
b, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -731,7 +602,7 @@ func write(filename string, b []byte, packages *code.Packages) error {
|
||||||
formatted = b
|
formatted = b
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(filename, formatted, 0o644)
|
err = ioutil.WriteFile(filename, formatted, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write %s: %w", filename, err)
|
return fmt.Errorf("failed to write %s: %w", filename, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
vendor/github.com/99designs/gqlgen/codegen/templates/test.gotpl
generated
vendored
1
vendor/github.com/99designs/gqlgen/codegen/templates/test.gotpl
generated
vendored
|
|
@ -1 +0,0 @@
|
||||||
this is my test package
|
|
||||||
1
vendor/github.com/99designs/gqlgen/codegen/templates/test_.gotpl
generated
vendored
1
vendor/github.com/99designs/gqlgen/codegen/templates/test_.gotpl
generated
vendored
|
|
@ -1 +0,0 @@
|
||||||
this will not be included
|
|
||||||
18
vendor/github.com/99designs/gqlgen/codegen/type.gotpl
generated
vendored
18
vendor/github.com/99designs/gqlgen/codegen/type.gotpl
generated
vendored
|
|
@ -56,10 +56,6 @@
|
||||||
return *res, graphql.ErrorOnPath(ctx, err)
|
return *res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- else if and (not $type.IsTargetNilable) $type.IsNilable }}
|
{{- else if and (not $type.IsTargetNilable) $type.IsNilable }}
|
||||||
return &res, graphql.ErrorOnPath(ctx, err)
|
return &res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- else if or $type.IsUnusualBasic $type.IsUnderlyingUnusualBasic }}
|
|
||||||
return {{ $type.GO | ref }}(res), graphql.ErrorOnPath(ctx, err)
|
|
||||||
{{- else if and $type.IsNamed $type.Definition.BuiltIn (not $type.IsScalarID) }}
|
|
||||||
return {{ $type.GO | ref }}(res), graphql.ErrorOnPath(ctx, err)
|
|
||||||
{{- else}}
|
{{- else}}
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
@ -79,10 +75,8 @@
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- else }}
|
{{- else }}
|
||||||
res, err := ec.unmarshalInput{{ $type.GQL.Name }}(ctx, v)
|
res, err := ec.unmarshalInput{{ $type.GQL.Name }}(ctx, v)
|
||||||
{{- if and $type.IsNilable (not $type.PointersInUmarshalInput) }}
|
{{- if $type.IsNilable }}
|
||||||
return &res, graphql.ErrorOnPath(ctx, err)
|
return &res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- else if and (not $type.IsNilable) $type.PointersInUmarshalInput }}
|
|
||||||
return *res, graphql.ErrorOnPath(ctx, err)
|
|
||||||
{{- else}}
|
{{- else}}
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
@ -157,7 +151,7 @@
|
||||||
if v == nil {
|
if v == nil {
|
||||||
{{- if $type.GQL.NonNull }}
|
{{- if $type.GQL.NonNull }}
|
||||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||||
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
|
ec.Errorf(ctx, "must not be null")
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
|
|
@ -176,17 +170,11 @@
|
||||||
{{- else if and (not $type.IsTargetNilable) $type.IsNilable }}
|
{{- else if and (not $type.IsTargetNilable) $type.IsNilable }}
|
||||||
{{- $v = "*v" }}
|
{{- $v = "*v" }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if or $type.IsUnusualBasic $type.IsUnderlyingUnusualBasic }}
|
|
||||||
res := {{ $type.Marshaler | call }}({{ $type.Target | ref }}({{ $v }}))
|
|
||||||
{{- else if and $type.IsNamed $type.Definition.BuiltIn (not $type.IsScalarID) }}
|
|
||||||
res := {{ $type.Marshaler | call }}({{- if and $type.GO.Underlying $type.IsUnderlyingBasic }}{{ $type.GO.Underlying | ref }}({{ $v }}){{else}}{{ $v }}{{- end }})
|
|
||||||
{{- else }}
|
|
||||||
res := {{ $type.Marshaler | call }}({{- if $type.CastType }}{{ $type.CastType | ref }}({{ $v }}){{else}}{{ $v }}{{- end }})
|
res := {{ $type.Marshaler | call }}({{- if $type.CastType }}{{ $type.CastType | ref }}({{ $v }}){{else}}{{ $v }}{{- end }})
|
||||||
{{- end }}
|
|
||||||
{{- if $type.GQL.NonNull }}
|
{{- if $type.GQL.NonNull }}
|
||||||
if res == graphql.Null {
|
if res == graphql.Null {
|
||||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||||
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
|
ec.Errorf(ctx, "must not be null")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
||||||
1
vendor/github.com/99designs/gqlgen/codegen/util.go
generated
vendored
1
vendor/github.com/99designs/gqlgen/codegen/util.go
generated
vendored
|
|
@ -41,7 +41,6 @@ func findGoInterface(def types.Type) (*types.Interface, error) {
|
||||||
|
|
||||||
func equalFieldName(source, target string) bool {
|
func equalFieldName(source, target string) bool {
|
||||||
source = strings.ReplaceAll(source, "_", "")
|
source = strings.ReplaceAll(source, "_", "")
|
||||||
source = strings.ReplaceAll(source, ",omitempty", "")
|
|
||||||
target = strings.ReplaceAll(target, "_", "")
|
target = strings.ReplaceAll(target, "_", "")
|
||||||
return strings.EqualFold(source, target)
|
return strings.EqualFold(source, target)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
vendor/github.com/99designs/gqlgen/graphql/context_field.go
generated
vendored
19
vendor/github.com/99designs/gqlgen/graphql/context_field.go
generated
vendored
|
|
@ -30,25 +30,6 @@ type FieldContext struct {
|
||||||
IsMethod bool
|
IsMethod bool
|
||||||
// IsResolver indicates if the field has a user-specified resolver
|
// IsResolver indicates if the field has a user-specified resolver
|
||||||
IsResolver bool
|
IsResolver bool
|
||||||
// Child allows getting a child FieldContext by its field collection description.
|
|
||||||
// Note that, the returned child FieldContext represents the context as it was
|
|
||||||
// before the execution of the field resolver. For example:
|
|
||||||
//
|
|
||||||
// srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (interface{}, error) {
|
|
||||||
// fc := graphql.GetFieldContext(ctx)
|
|
||||||
// op := graphql.GetOperationContext(ctx)
|
|
||||||
// collected := graphql.CollectFields(opCtx, fc.Field.Selections, []string{"User"})
|
|
||||||
//
|
|
||||||
// child, err := fc.Child(ctx, collected[0])
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// fmt.Println("child context %q with args: %v", child.Field.Name, child.Args)
|
|
||||||
//
|
|
||||||
// return next(ctx)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
Child func(context.Context, CollectedField) (*FieldContext, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FieldStats struct {
|
type FieldStats struct {
|
||||||
|
|
|
||||||
14
vendor/github.com/99designs/gqlgen/graphql/context_operation.go
generated
vendored
14
vendor/github.com/99designs/gqlgen/graphql/context_operation.go
generated
vendored
|
|
@ -3,10 +3,8 @@ package graphql
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Deprecated: Please update all references to OperationContext instead
|
// Deprecated: Please update all references to OperationContext instead
|
||||||
|
|
@ -17,7 +15,6 @@ type OperationContext struct {
|
||||||
Variables map[string]interface{}
|
Variables map[string]interface{}
|
||||||
OperationName string
|
OperationName string
|
||||||
Doc *ast.QueryDocument
|
Doc *ast.QueryDocument
|
||||||
Headers http.Header
|
|
||||||
|
|
||||||
Operation *ast.OperationDefinition
|
Operation *ast.OperationDefinition
|
||||||
DisableIntrospection bool
|
DisableIntrospection bool
|
||||||
|
|
@ -107,16 +104,9 @@ func (c *OperationContext) Errorf(ctx context.Context, format string, args ...in
|
||||||
AddErrorf(ctx, format, args...)
|
AddErrorf(ctx, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error add error or multiple errors (if underlaying type is gqlerror.List) into the stack.
|
// Error sends an error to the client, passing it through the formatter.
|
||||||
// Then it will be sends to the client, passing it through the formatter.
|
// Deprecated: use graphql.AddError(ctx, err) instead
|
||||||
func (c *OperationContext) Error(ctx context.Context, err error) {
|
func (c *OperationContext) Error(ctx context.Context, err error) {
|
||||||
if errList, ok := err.(gqlerror.List); ok {
|
|
||||||
for _, e := range errList {
|
|
||||||
AddError(ctx, e)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
AddError(ctx, err)
|
AddError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
19
vendor/github.com/99designs/gqlgen/graphql/errcode/codes.go
generated
vendored
19
vendor/github.com/99designs/gqlgen/graphql/errcode/codes.go
generated
vendored
|
|
@ -23,27 +23,18 @@ var codeType = map[string]ErrorKind{
|
||||||
ParseFailed: KindProtocol,
|
ParseFailed: KindProtocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterErrorType should be called by extensions that want to customize the http status codes for
|
// RegisterErrorType should be called by extensions that want to customize the http status codes for errors they return
|
||||||
// errors they return
|
|
||||||
func RegisterErrorType(code string, kind ErrorKind) {
|
func RegisterErrorType(code string, kind ErrorKind) {
|
||||||
codeType[code] = kind
|
codeType[code] = kind
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the error code on a given graphql error extension
|
// Set the error code on a given graphql error extension
|
||||||
func Set(err error, value string) {
|
func Set(err *gqlerror.Error, value string) {
|
||||||
if err == nil {
|
if err.Extensions == nil {
|
||||||
return
|
err.Extensions = map[string]interface{}{}
|
||||||
}
|
|
||||||
gqlErr, ok := err.(*gqlerror.Error)
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gqlErr.Extensions == nil {
|
err.Extensions["code"] = value
|
||||||
gqlErr.Extensions = map[string]interface{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
gqlErr.Extensions["code"] = value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the kind of the first non User error, defaults to User if no errors have a custom extension
|
// get the kind of the first non User error, defaults to User if no errors have a custom extension
|
||||||
|
|
|
||||||
3
vendor/github.com/99designs/gqlgen/graphql/error.go
generated
vendored
3
vendor/github.com/99designs/gqlgen/graphql/error.go
generated
vendored
|
|
@ -26,8 +26,7 @@ func ErrorOnPath(ctx context.Context, err error) error {
|
||||||
if gqlErr.Path == nil {
|
if gqlErr.Path == nil {
|
||||||
gqlErr.Path = GetPath(ctx)
|
gqlErr.Path = GetPath(ctx)
|
||||||
}
|
}
|
||||||
// Return the original error to avoid losing any attached annotation
|
return gqlErr
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return gqlerror.WrapPath(GetPath(ctx), err)
|
return gqlerror.WrapPath(GetPath(ctx), err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
vendor/github.com/99designs/gqlgen/graphql/executable_schema.go
generated
vendored
5
vendor/github.com/99designs/gqlgen/graphql/executable_schema.go
generated
vendored
|
|
@ -118,11 +118,6 @@ func getOrCreateAndAppendField(c *[]CollectedField, name string, alias string, o
|
||||||
return &(*c)[i]
|
return &(*c)[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ifc := range cf.ObjectDefinition.Interfaces {
|
|
||||||
if ifc == objectDefinition.Name {
|
|
||||||
return &(*c)[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
57
vendor/github.com/99designs/gqlgen/graphql/executor/executor.go
generated
vendored
57
vendor/github.com/99designs/gqlgen/graphql/executor/executor.go
generated
vendored
|
|
@ -37,10 +37,7 @@ func New(es graphql.ExecutableSchema) *Executor {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) CreateOperationContext(
|
func (e *Executor) CreateOperationContext(ctx context.Context, params *graphql.RawParams) (*graphql.OperationContext, gqlerror.List) {
|
||||||
ctx context.Context,
|
|
||||||
params *graphql.RawParams,
|
|
||||||
) (*graphql.OperationContext, gqlerror.List) {
|
|
||||||
rc := &graphql.OperationContext{
|
rc := &graphql.OperationContext{
|
||||||
DisableIntrospection: true,
|
DisableIntrospection: true,
|
||||||
RecoverFunc: e.recoverFunc,
|
RecoverFunc: e.recoverFunc,
|
||||||
|
|
@ -61,7 +58,6 @@ func (e *Executor) CreateOperationContext(
|
||||||
|
|
||||||
rc.RawQuery = params.Query
|
rc.RawQuery = params.Query
|
||||||
rc.OperationName = params.OperationName
|
rc.OperationName = params.OperationName
|
||||||
rc.Headers = params.Headers
|
|
||||||
|
|
||||||
var listErr gqlerror.List
|
var listErr gqlerror.List
|
||||||
rc.Doc, listErr = e.parseQuery(ctx, &rc.Stats, params.Query)
|
rc.Doc, listErr = e.parseQuery(ctx, &rc.Stats, params.Query)
|
||||||
|
|
@ -71,21 +67,15 @@ func (e *Executor) CreateOperationContext(
|
||||||
|
|
||||||
rc.Operation = rc.Doc.Operations.ForName(params.OperationName)
|
rc.Operation = rc.Doc.Operations.ForName(params.OperationName)
|
||||||
if rc.Operation == nil {
|
if rc.Operation == nil {
|
||||||
err := gqlerror.Errorf("operation %s not found", params.OperationName)
|
return rc, gqlerror.List{gqlerror.Errorf("operation %s not found", params.OperationName)}
|
||||||
|
}
|
||||||
|
|
||||||
|
var err *gqlerror.Error
|
||||||
|
rc.Variables, err = validator.VariableValues(e.es.Schema(), rc.Operation, params.Variables)
|
||||||
|
if err != nil {
|
||||||
errcode.Set(err, errcode.ValidationFailed)
|
errcode.Set(err, errcode.ValidationFailed)
|
||||||
return rc, gqlerror.List{err}
|
return rc, gqlerror.List{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
|
||||||
rc.Variables, err = validator.VariableValues(e.es.Schema(), rc.Operation, params.Variables)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
gqlErr, ok := err.(*gqlerror.Error)
|
|
||||||
if ok {
|
|
||||||
errcode.Set(gqlErr, errcode.ValidationFailed)
|
|
||||||
return rc, gqlerror.List{gqlErr}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rc.Stats.Validation.End = graphql.Now()
|
rc.Stats.Validation.End = graphql.Now()
|
||||||
|
|
||||||
for _, p := range e.ext.operationContextMutators {
|
for _, p := range e.ext.operationContextMutators {
|
||||||
|
|
@ -97,10 +87,7 @@ func (e *Executor) CreateOperationContext(
|
||||||
return rc, nil
|
return rc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) DispatchOperation(
|
func (e *Executor) DispatchOperation(ctx context.Context, rc *graphql.OperationContext) (graphql.ResponseHandler, context.Context) {
|
||||||
ctx context.Context,
|
|
||||||
rc *graphql.OperationContext,
|
|
||||||
) (graphql.ResponseHandler, context.Context) {
|
|
||||||
ctx = graphql.WithOperationContext(ctx, rc)
|
ctx = graphql.WithOperationContext(ctx, rc)
|
||||||
|
|
||||||
var innerCtx context.Context
|
var innerCtx context.Context
|
||||||
|
|
@ -143,7 +130,7 @@ func (e *Executor) DispatchError(ctx context.Context, list gqlerror.List) *graph
|
||||||
|
|
||||||
resp := e.ext.responseMiddleware(ctx, func(ctx context.Context) *graphql.Response {
|
resp := e.ext.responseMiddleware(ctx, func(ctx context.Context) *graphql.Response {
|
||||||
resp := &graphql.Response{
|
resp := &graphql.Response{
|
||||||
Errors: graphql.GetErrors(ctx),
|
Errors: list,
|
||||||
}
|
}
|
||||||
resp.Extensions = graphql.GetExtensions(ctx)
|
resp.Extensions = graphql.GetExtensions(ctx)
|
||||||
return resp
|
return resp
|
||||||
|
|
@ -152,7 +139,7 @@ func (e *Executor) DispatchError(ctx context.Context, list gqlerror.List) *graph
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) PresentRecoveredError(ctx context.Context, err interface{}) error {
|
func (e *Executor) PresentRecoveredError(ctx context.Context, err interface{}) *gqlerror.Error {
|
||||||
return e.errorPresenter(ctx, e.recoverFunc(ctx, err))
|
return e.errorPresenter(ctx, e.recoverFunc(ctx, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,14 +157,9 @@ func (e *Executor) SetRecoverFunc(f graphql.RecoverFunc) {
|
||||||
|
|
||||||
// parseQuery decodes the incoming query and validates it, pulling from cache if present.
|
// parseQuery decodes the incoming query and validates it, pulling from cache if present.
|
||||||
//
|
//
|
||||||
// NOTE: This should NOT look at variables, they will change per request. It should only parse and
|
// NOTE: This should NOT look at variables, they will change per request. It should only parse and validate
|
||||||
// validate
|
|
||||||
// the raw query string.
|
// the raw query string.
|
||||||
func (e *Executor) parseQuery(
|
func (e *Executor) parseQuery(ctx context.Context, stats *graphql.Stats, query string) (*ast.QueryDocument, gqlerror.List) {
|
||||||
ctx context.Context,
|
|
||||||
stats *graphql.Stats,
|
|
||||||
query string,
|
|
||||||
) (*ast.QueryDocument, gqlerror.List) {
|
|
||||||
stats.Parsing.Start = graphql.Now()
|
stats.Parsing.Start = graphql.Now()
|
||||||
|
|
||||||
if doc, ok := e.queryCache.Get(ctx, query); ok {
|
if doc, ok := e.queryCache.Get(ctx, query); ok {
|
||||||
|
|
@ -190,23 +172,12 @@ func (e *Executor) parseQuery(
|
||||||
|
|
||||||
doc, err := parser.ParseQuery(&ast.Source{Input: query})
|
doc, err := parser.ParseQuery(&ast.Source{Input: query})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gqlErr, ok := err.(*gqlerror.Error)
|
errcode.Set(err, errcode.ParseFailed)
|
||||||
if ok {
|
return nil, gqlerror.List{err}
|
||||||
errcode.Set(gqlErr, errcode.ParseFailed)
|
|
||||||
return nil, gqlerror.List{gqlErr}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
stats.Parsing.End = graphql.Now()
|
stats.Parsing.End = graphql.Now()
|
||||||
|
|
||||||
stats.Validation.Start = graphql.Now()
|
stats.Validation.Start = graphql.Now()
|
||||||
|
|
||||||
if len(doc.Operations) == 0 {
|
|
||||||
err = gqlerror.Errorf("no operation provided")
|
|
||||||
gqlErr, _ := err.(*gqlerror.Error)
|
|
||||||
errcode.Set(err, errcode.ValidationFailed)
|
|
||||||
return nil, gqlerror.List{gqlErr}
|
|
||||||
}
|
|
||||||
|
|
||||||
listErr := validator.Validate(e.es.Schema(), doc)
|
listErr := validator.Validate(e.es.Schema(), doc)
|
||||||
if len(listErr) != 0 {
|
if len(listErr) != 0 {
|
||||||
for _, e := range listErr {
|
for _, e := range listErr {
|
||||||
|
|
|
||||||
1
vendor/github.com/99designs/gqlgen/graphql/handler.go
generated
vendored
1
vendor/github.com/99designs/gqlgen/graphql/handler.go
generated
vendored
|
|
@ -27,7 +27,6 @@ type (
|
||||||
OperationName string `json:"operationName"`
|
OperationName string `json:"operationName"`
|
||||||
Variables map[string]interface{} `json:"variables"`
|
Variables map[string]interface{} `json:"variables"`
|
||||||
Extensions map[string]interface{} `json:"extensions"`
|
Extensions map[string]interface{} `json:"extensions"`
|
||||||
Headers http.Header `json:"headers"`
|
|
||||||
|
|
||||||
ReadTime TraceTiming `json:"-"`
|
ReadTime TraceTiming `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
vendor/github.com/99designs/gqlgen/graphql/handler/server.go
generated
vendored
3
vendor/github.com/99designs/gqlgen/graphql/handler/server.go
generated
vendored
|
|
@ -102,8 +102,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
err := s.exec.PresentRecoveredError(r.Context(), err)
|
err := s.exec.PresentRecoveredError(r.Context(), err)
|
||||||
gqlErr, _ := err.(*gqlerror.Error)
|
resp := &graphql.Response{Errors: []*gqlerror.Error{err}}
|
||||||
resp := &graphql.Response{Errors: []*gqlerror.Error{gqlErr}}
|
|
||||||
b, _ := json.Marshal(resp)
|
b, _ := json.Marshal(resp)
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
|
|
|
||||||
98
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_form.go
generated
vendored
98
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_form.go
generated
vendored
|
|
@ -3,9 +3,11 @@ package transport
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
"github.com/99designs/gqlgen/graphql"
|
||||||
)
|
)
|
||||||
|
|
@ -62,68 +64,63 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.Body = http.MaxBytesReader(w, r.Body, f.maxUploadSize())
|
r.Body = http.MaxBytesReader(w, r.Body, f.maxUploadSize())
|
||||||
defer r.Body.Close()
|
if err = r.ParseMultipartForm(f.maxMemory()); err != nil {
|
||||||
|
|
||||||
mr, err := r.MultipartReader()
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
if strings.Contains(err.Error(), "request body too large") {
|
||||||
|
writeJsonError(w, "failed to parse multipart form, request body too large")
|
||||||
|
return
|
||||||
|
}
|
||||||
writeJsonError(w, "failed to parse multipart form")
|
writeJsonError(w, "failed to parse multipart form")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
part, err := mr.NextPart()
|
|
||||||
if err != nil || part.FormName() != "operations" {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
||||||
writeJsonError(w, "first part must be operations")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var params graphql.RawParams
|
var params graphql.RawParams
|
||||||
if err = jsonDecode(part, ¶ms); err != nil {
|
|
||||||
|
if err = jsonDecode(strings.NewReader(r.Form.Get("operations")), ¶ms); err != nil {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
writeJsonError(w, "operations form field could not be decoded")
|
writeJsonError(w, "operations form field could not be decoded")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
part, err = mr.NextPart()
|
|
||||||
if err != nil || part.FormName() != "map" {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
||||||
writeJsonError(w, "second part must be map")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadsMap := map[string][]string{}
|
uploadsMap := map[string][]string{}
|
||||||
if err = json.NewDecoder(part).Decode(&uploadsMap); err != nil {
|
if err = json.Unmarshal([]byte(r.Form.Get("map")), &uploadsMap); err != nil {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
writeJsonError(w, "map form field could not be decoded")
|
writeJsonError(w, "map form field could not be decoded")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
var upload graphql.Upload
|
||||||
part, err = mr.NextPart()
|
for key, paths := range uploadsMap {
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
} else if err != nil {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
||||||
writeJsonErrorf(w, "failed to parse part")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
key := part.FormName()
|
|
||||||
filename := part.FileName()
|
|
||||||
contentType := part.Header.Get("Content-Type")
|
|
||||||
|
|
||||||
paths := uploadsMap[key]
|
|
||||||
if len(paths) == 0 {
|
if len(paths) == 0 {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
writeJsonErrorf(w, "invalid empty operations paths list for key %s", key)
|
writeJsonErrorf(w, "invalid empty operations paths list for key %s", key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete(uploadsMap, key)
|
file, header, err := r.FormFile(key)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
writeJsonErrorf(w, "failed to get key %s from form", key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
var upload graphql.Upload
|
if len(paths) == 1 {
|
||||||
|
upload = graphql.Upload{
|
||||||
|
File: file,
|
||||||
|
Size: header.Size,
|
||||||
|
Filename: header.Filename,
|
||||||
|
ContentType: header.Header.Get("Content-Type"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := params.AddUpload(upload, key, paths[0]); err != nil {
|
||||||
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
writeJsonGraphqlError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if r.ContentLength < f.maxMemory() {
|
if r.ContentLength < f.maxMemory() {
|
||||||
fileBytes, err := io.ReadAll(part)
|
fileBytes, err := ioutil.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
writeJsonErrorf(w, "failed to read file for key %s", key)
|
writeJsonErrorf(w, "failed to read file for key %s", key)
|
||||||
|
|
@ -131,10 +128,10 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
}
|
}
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
upload = graphql.Upload{
|
upload = graphql.Upload{
|
||||||
File: &bytesReader{s: &fileBytes, i: 0},
|
File: &bytesReader{s: &fileBytes, i: 0, prevRune: -1},
|
||||||
Size: int64(len(fileBytes)),
|
Size: header.Size,
|
||||||
Filename: filename,
|
Filename: header.Filename,
|
||||||
ContentType: contentType,
|
ContentType: header.Header.Get("Content-Type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := params.AddUpload(upload, key, path); err != nil {
|
if err := params.AddUpload(upload, key, path); err != nil {
|
||||||
|
|
@ -144,7 +141,7 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmpFile, err := os.CreateTemp(os.TempDir(), "gqlgen-")
|
tmpFile, err := ioutil.TempFile(os.TempDir(), "gqlgen-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
writeJsonErrorf(w, "failed to create temp file for key %s", key)
|
writeJsonErrorf(w, "failed to create temp file for key %s", key)
|
||||||
|
|
@ -154,7 +151,7 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = os.Remove(tmpName)
|
_ = os.Remove(tmpName)
|
||||||
}()
|
}()
|
||||||
fileSize, err := io.Copy(tmpFile, part)
|
_, err = io.Copy(tmpFile, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
if err := tmpFile.Close(); err != nil {
|
if err := tmpFile.Close(); err != nil {
|
||||||
|
|
@ -179,9 +176,9 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
defer pathTmpFile.Close()
|
defer pathTmpFile.Close()
|
||||||
upload = graphql.Upload{
|
upload = graphql.Upload{
|
||||||
File: pathTmpFile,
|
File: pathTmpFile,
|
||||||
Size: fileSize,
|
Size: header.Size,
|
||||||
Filename: filename,
|
Filename: header.Filename,
|
||||||
ContentType: contentType,
|
ContentType: header.Header.Get("Content-Type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := params.AddUpload(upload, key, path); err != nil {
|
if err := params.AddUpload(upload, key, path); err != nil {
|
||||||
|
|
@ -192,15 +189,8 @@ func (f MultipartForm) Do(w http.ResponseWriter, r *http.Request, exec graphql.G
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for key := range uploadsMap {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
||||||
writeJsonErrorf(w, "failed to get key %s from form", key)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params.Headers = r.Header
|
|
||||||
|
|
||||||
params.ReadTime = graphql.TraceTiming{
|
params.ReadTime = graphql.TraceTiming{
|
||||||
Start: start,
|
Start: start,
|
||||||
End: graphql.Now(),
|
End: graphql.Now(),
|
||||||
|
|
|
||||||
24
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_get.go
generated
vendored
24
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_get.go
generated
vendored
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
|
@ -28,22 +27,15 @@ func (h GET) Supports(r *http.Request) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
||||||
query, err := url.ParseQuery(r.URL.RawQuery)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
writeJsonError(w, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
raw := &graphql.RawParams{
|
raw := &graphql.RawParams{
|
||||||
Query: query.Get("query"),
|
Query: r.URL.Query().Get("query"),
|
||||||
OperationName: query.Get("operationName"),
|
OperationName: r.URL.Query().Get("operationName"),
|
||||||
Headers: r.Header,
|
|
||||||
}
|
}
|
||||||
raw.ReadTime.Start = graphql.Now()
|
raw.ReadTime.Start = graphql.Now()
|
||||||
|
|
||||||
if variables := query.Get("variables"); variables != "" {
|
if variables := r.URL.Query().Get("variables"); variables != "" {
|
||||||
if err := jsonDecode(strings.NewReader(variables), &raw.Variables); err != nil {
|
if err := jsonDecode(strings.NewReader(variables), &raw.Variables); err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
writeJsonError(w, "variables could not be decoded")
|
writeJsonError(w, "variables could not be decoded")
|
||||||
|
|
@ -51,7 +43,7 @@ func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if extensions := query.Get("extensions"); extensions != "" {
|
if extensions := r.URL.Query().Get("extensions"); extensions != "" {
|
||||||
if err := jsonDecode(strings.NewReader(extensions), &raw.Extensions); err != nil {
|
if err := jsonDecode(strings.NewReader(extensions), &raw.Extensions); err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
writeJsonError(w, "extensions could not be decoded")
|
writeJsonError(w, "extensions could not be decoded")
|
||||||
|
|
@ -61,10 +53,10 @@ func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecut
|
||||||
|
|
||||||
raw.ReadTime.End = graphql.Now()
|
raw.ReadTime.End = graphql.Now()
|
||||||
|
|
||||||
rc, gqlError := exec.CreateOperationContext(r.Context(), raw)
|
rc, err := exec.CreateOperationContext(r.Context(), raw)
|
||||||
if gqlError != nil {
|
if err != nil {
|
||||||
w.WriteHeader(statusFor(gqlError))
|
w.WriteHeader(statusFor(err))
|
||||||
resp := exec.DispatchError(graphql.WithOperationContext(r.Context(), rc), gqlError)
|
resp := exec.DispatchError(graphql.WithOperationContext(r.Context(), rc), err)
|
||||||
writeJson(w, resp)
|
writeJson(w, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
59
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_post.go
generated
vendored
59
vendor/github.com/99designs/gqlgen/graphql/handler/transport/http_post.go
generated
vendored
|
|
@ -1,14 +1,8 @@
|
||||||
package transport
|
package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
"github.com/99designs/gqlgen/graphql"
|
||||||
)
|
)
|
||||||
|
|
@ -32,59 +26,28 @@ func (h POST) Supports(r *http.Request) bool {
|
||||||
return r.Method == "POST" && mediaType == "application/json"
|
return r.Method == "POST" && mediaType == "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRequestBody(r *http.Request) (string, error) {
|
|
||||||
if r == nil || r.Body == nil {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
body, err := io.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("unable to get Request Body %w", err)
|
|
||||||
}
|
|
||||||
return string(body), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h POST) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
func (h POST) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
||||||
ctx := r.Context()
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
params := &graphql.RawParams{}
|
|
||||||
|
var params *graphql.RawParams
|
||||||
start := graphql.Now()
|
start := graphql.Now()
|
||||||
params.Headers = r.Header
|
if err := jsonDecode(r.Body, ¶ms); err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
writeJsonErrorf(w, "json body could not be decoded: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
params.ReadTime = graphql.TraceTiming{
|
params.ReadTime = graphql.TraceTiming{
|
||||||
Start: start,
|
Start: start,
|
||||||
End: graphql.Now(),
|
End: graphql.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyString, err := getRequestBody(r)
|
rc, err := exec.CreateOperationContext(r.Context(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gqlErr := gqlerror.Errorf("could not get json request body: %+v", err)
|
w.WriteHeader(statusFor(err))
|
||||||
resp := exec.DispatchError(ctx, gqlerror.List{gqlErr})
|
resp := exec.DispatchError(graphql.WithOperationContext(r.Context(), rc), err)
|
||||||
log.Printf("could not get json request body: %+v", err.Error())
|
|
||||||
writeJson(w, resp)
|
|
||||||
}
|
|
||||||
|
|
||||||
bodyReader := io.NopCloser(strings.NewReader(bodyString))
|
|
||||||
if err = jsonDecode(bodyReader, ¶ms); err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
gqlErr := gqlerror.Errorf(
|
|
||||||
"json request body could not be decoded: %+v body:%s",
|
|
||||||
err,
|
|
||||||
bodyString,
|
|
||||||
)
|
|
||||||
resp := exec.DispatchError(ctx, gqlerror.List{gqlErr})
|
|
||||||
log.Printf("decoding error: %+v body:%s", err.Error(), bodyString)
|
|
||||||
writeJson(w, resp)
|
writeJson(w, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
responses, ctx := exec.DispatchOperation(r.Context(), rc)
|
||||||
rc, OpErr := exec.CreateOperationContext(ctx, params)
|
|
||||||
if OpErr != nil {
|
|
||||||
w.WriteHeader(statusFor(OpErr))
|
|
||||||
resp := exec.DispatchError(graphql.WithOperationContext(ctx, rc), OpErr)
|
|
||||||
writeJson(w, resp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var responses graphql.ResponseHandler
|
|
||||||
responses, ctx = exec.DispatchOperation(ctx, rc)
|
|
||||||
writeJson(w, responses(ctx))
|
writeJson(w, responses(ctx))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
vendor/github.com/99designs/gqlgen/graphql/handler/transport/options.go
generated
vendored
15
vendor/github.com/99designs/gqlgen/graphql/handler/transport/options.go
generated
vendored
|
|
@ -2,16 +2,12 @@ package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
"github.com/99designs/gqlgen/graphql"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options responds to http OPTIONS and HEAD requests
|
// Options responds to http OPTIONS and HEAD requests
|
||||||
type Options struct {
|
type Options struct{}
|
||||||
// AllowedMethods is a list of allowed HTTP methods.
|
|
||||||
AllowedMethods []string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ graphql.Transport = Options{}
|
var _ graphql.Transport = Options{}
|
||||||
|
|
||||||
|
|
@ -22,16 +18,9 @@ func (o Options) Supports(r *http.Request) bool {
|
||||||
func (o Options) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
func (o Options) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodOptions:
|
case http.MethodOptions:
|
||||||
w.Header().Set("Allow", o.allowedMethods())
|
w.Header().Set("Allow", "OPTIONS, GET, POST")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
case http.MethodHead:
|
case http.MethodHead:
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Options) allowedMethods() string {
|
|
||||||
if len(o.AllowedMethods) == 0 {
|
|
||||||
return "OPTIONS, GET, POST"
|
|
||||||
}
|
|
||||||
return strings.Join(o.AllowedMethods, ", ")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
24
vendor/github.com/99designs/gqlgen/graphql/handler/transport/reader.go
generated
vendored
24
vendor/github.com/99designs/gqlgen/graphql/handler/transport/reader.go
generated
vendored
|
|
@ -8,6 +8,7 @@ import (
|
||||||
type bytesReader struct {
|
type bytesReader struct {
|
||||||
s *[]byte
|
s *[]byte
|
||||||
i int64 // current reading index
|
i int64 // current reading index
|
||||||
|
prevRune int // index of previous rune; or < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *bytesReader) Read(b []byte) (n int, err error) {
|
func (r *bytesReader) Read(b []byte) (n int, err error) {
|
||||||
|
|
@ -17,29 +18,8 @@ func (r *bytesReader) Read(b []byte) (n int, err error) {
|
||||||
if r.i >= int64(len(*r.s)) {
|
if r.i >= int64(len(*r.s)) {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
r.prevRune = -1
|
||||||
n = copy(b, (*r.s)[r.i:])
|
n = copy(b, (*r.s)[r.i:])
|
||||||
r.i += int64(n)
|
r.i += int64(n)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *bytesReader) Seek(offset int64, whence int) (int64, error) {
|
|
||||||
if r.s == nil {
|
|
||||||
return 0, errors.New("byte slice pointer is nil")
|
|
||||||
}
|
|
||||||
var abs int64
|
|
||||||
switch whence {
|
|
||||||
case io.SeekStart:
|
|
||||||
abs = offset
|
|
||||||
case io.SeekCurrent:
|
|
||||||
abs = r.i + offset
|
|
||||||
case io.SeekEnd:
|
|
||||||
abs = int64(len(*r.s)) + offset
|
|
||||||
default:
|
|
||||||
return 0, errors.New("invalid whence")
|
|
||||||
}
|
|
||||||
if abs < 0 {
|
|
||||||
return 0, errors.New("negative position")
|
|
||||||
}
|
|
||||||
r.i = abs
|
|
||||||
return abs, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
110
vendor/github.com/99designs/gqlgen/graphql/handler/transport/sse.go
generated
vendored
110
vendor/github.com/99designs/gqlgen/graphql/handler/transport/sse.go
generated
vendored
|
|
@ -1,110 +0,0 @@
|
||||||
package transport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"mime"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SSE struct{}
|
|
||||||
|
|
||||||
var _ graphql.Transport = SSE{}
|
|
||||||
|
|
||||||
func (t SSE) Supports(r *http.Request) bool {
|
|
||||||
if !strings.Contains(r.Header.Get("Accept"), "text/event-stream") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
mediaType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return r.Method == http.MethodPost && mediaType == "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t SSE) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
|
|
||||||
ctx := r.Context()
|
|
||||||
flusher, ok := w.(http.Flusher)
|
|
||||||
if !ok {
|
|
||||||
SendErrorf(w, http.StatusInternalServerError, "streaming unsupported")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer flusher.Flush()
|
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", "no-cache")
|
|
||||||
w.Header().Set("Connection", "keep-alive")
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
params := &graphql.RawParams{}
|
|
||||||
start := graphql.Now()
|
|
||||||
params.Headers = r.Header
|
|
||||||
params.ReadTime = graphql.TraceTiming{
|
|
||||||
Start: start,
|
|
||||||
End: graphql.Now(),
|
|
||||||
}
|
|
||||||
|
|
||||||
bodyString, err := getRequestBody(r)
|
|
||||||
if err != nil {
|
|
||||||
gqlErr := gqlerror.Errorf("could not get json request body: %+v", err)
|
|
||||||
resp := exec.DispatchError(ctx, gqlerror.List{gqlErr})
|
|
||||||
log.Printf("could not get json request body: %+v", err.Error())
|
|
||||||
writeJson(w, resp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
bodyReader := io.NopCloser(strings.NewReader(bodyString))
|
|
||||||
if err = jsonDecode(bodyReader, ¶ms); err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
gqlErr := gqlerror.Errorf(
|
|
||||||
"json request body could not be decoded: %+v body:%s",
|
|
||||||
err,
|
|
||||||
bodyString,
|
|
||||||
)
|
|
||||||
resp := exec.DispatchError(ctx, gqlerror.List{gqlErr})
|
|
||||||
log.Printf("decoding error: %+v body:%s", err.Error(), bodyString)
|
|
||||||
writeJson(w, resp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rc, OpErr := exec.CreateOperationContext(ctx, params)
|
|
||||||
if OpErr != nil {
|
|
||||||
w.WriteHeader(statusFor(OpErr))
|
|
||||||
resp := exec.DispatchError(graphql.WithOperationContext(ctx, rc), OpErr)
|
|
||||||
writeJson(w, resp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithOperationContext(ctx, rc)
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/event-stream")
|
|
||||||
fmt.Fprint(w, ":\n\n")
|
|
||||||
flusher.Flush()
|
|
||||||
|
|
||||||
responses, ctx := exec.DispatchOperation(ctx, rc)
|
|
||||||
|
|
||||||
for {
|
|
||||||
response := responses(ctx)
|
|
||||||
if response == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
writeJsonWithSSE(w, response)
|
|
||||||
flusher.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprint(w, "event: complete\n\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeJsonWithSSE(w io.Writer, response *graphql.Response) {
|
|
||||||
b, err := json.Marshal(response)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "event: next\ndata: %s\n\n", b)
|
|
||||||
}
|
|
||||||
41
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket.go
generated
vendored
41
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket.go
generated
vendored
|
|
@ -49,24 +49,7 @@ type (
|
||||||
|
|
||||||
var errReadTimeout = errors.New("read timeout")
|
var errReadTimeout = errors.New("read timeout")
|
||||||
|
|
||||||
type WebsocketError struct {
|
var _ graphql.Transport = Websocket{}
|
||||||
Err error
|
|
||||||
|
|
||||||
// IsReadError flags whether the error occurred on read or write to the websocket
|
|
||||||
IsReadError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e WebsocketError) Error() string {
|
|
||||||
if e.IsReadError {
|
|
||||||
return fmt.Sprintf("websocket read: %v", e.Err)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("websocket write: %v", e.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
_ graphql.Transport = Websocket{}
|
|
||||||
_ error = WebsocketError{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (t Websocket) Supports(r *http.Request) bool {
|
func (t Websocket) Supports(r *http.Request) bool {
|
||||||
return r.Header.Get("Upgrade") != ""
|
return r.Header.Get("Upgrade") != ""
|
||||||
|
|
@ -111,12 +94,9 @@ func (t Websocket) Do(w http.ResponseWriter, r *http.Request, exec graphql.Graph
|
||||||
conn.run()
|
conn.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *wsConnection) handlePossibleError(err error, isReadError bool) {
|
func (c *wsConnection) handlePossibleError(err error) {
|
||||||
if c.ErrorFunc != nil && err != nil {
|
if c.ErrorFunc != nil && err != nil {
|
||||||
c.ErrorFunc(c.ctx, WebsocketError{
|
c.ErrorFunc(c.ctx, err)
|
||||||
Err: err,
|
|
||||||
IsReadError: isReadError,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +181,7 @@ func (c *wsConnection) init() bool {
|
||||||
|
|
||||||
func (c *wsConnection) write(msg *message) {
|
func (c *wsConnection) write(msg *message) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.handlePossibleError(c.me.Send(msg), false)
|
c.handlePossibleError(c.me.Send(msg))
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,7 +227,7 @@ func (c *wsConnection) run() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the connection got closed by us, don't report the error
|
// If the connection got closed by us, don't report the error
|
||||||
if !errors.Is(err, net.ErrClosed) {
|
if !errors.Is(err, net.ErrClosed) {
|
||||||
c.handlePossibleError(err, true)
|
c.handlePossibleError(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -350,7 +330,6 @@ func (c *wsConnection) subscribe(start time.Time, msg *message) {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ctx = withSubscriptionErrorContext(ctx)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
err := rc.Recover(ctx, r)
|
err := rc.Recover(ctx, r)
|
||||||
|
|
@ -363,11 +342,7 @@ func (c *wsConnection) subscribe(start time.Time, msg *message) {
|
||||||
}
|
}
|
||||||
c.sendError(msg.id, gqlerr)
|
c.sendError(msg.id, gqlerr)
|
||||||
}
|
}
|
||||||
if errs := getSubscriptionError(ctx); len(errs) != 0 {
|
|
||||||
c.sendError(msg.id, errs...)
|
|
||||||
} else {
|
|
||||||
c.complete(msg.id)
|
c.complete(msg.id)
|
||||||
}
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
delete(c.active, msg.id)
|
delete(c.active, msg.id)
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
@ -383,8 +358,12 @@ func (c *wsConnection) subscribe(start time.Time, msg *message) {
|
||||||
|
|
||||||
c.sendResponse(msg.id, response)
|
c.sendResponse(msg.id, response)
|
||||||
}
|
}
|
||||||
|
c.complete(msg.id)
|
||||||
|
|
||||||
// complete and context cancel comes from the defer
|
c.mu.Lock()
|
||||||
|
delete(c.active, msg.id)
|
||||||
|
c.mu.Unlock()
|
||||||
|
cancel()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
|
// https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
|
||||||
const (
|
const (
|
||||||
graphqltransportwsSubprotocol = "graphql-transport-ws"
|
graphqltransportwsSubprotocol = "graphql-transport-ws"
|
||||||
|
|
||||||
|
|
|
||||||
2
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket_graphqlws.go
generated
vendored
2
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket_graphqlws.go
generated
vendored
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
|
// https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
|
||||||
const (
|
const (
|
||||||
graphqlwsSubprotocol = "graphql-ws"
|
graphqlwsSubprotocol = "graphql-ws"
|
||||||
|
|
||||||
|
|
|
||||||
69
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket_resolver_error.go
generated
vendored
69
vendor/github.com/99designs/gqlgen/graphql/handler/transport/websocket_resolver_error.go
generated
vendored
|
|
@ -1,69 +0,0 @@
|
||||||
package transport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A private key for context that only this package can access. This is important
|
|
||||||
// to prevent collisions between different context uses
|
|
||||||
var wsSubscriptionErrorCtxKey = &wsSubscriptionErrorContextKey{"subscription-error"}
|
|
||||||
|
|
||||||
type wsSubscriptionErrorContextKey struct {
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
type subscriptionError struct {
|
|
||||||
errs []*gqlerror.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddSubscriptionError is used to let websocket return an error message after subscription resolver returns a channel.
|
|
||||||
// for example:
|
|
||||||
//
|
|
||||||
// func (r *subscriptionResolver) Method(ctx context.Context) (<-chan *model.Message, error) {
|
|
||||||
// ch := make(chan *model.Message)
|
|
||||||
// go func() {
|
|
||||||
// defer func() {
|
|
||||||
// close(ch)
|
|
||||||
// }
|
|
||||||
// // some kind of block processing (e.g.: gRPC client streaming)
|
|
||||||
// stream, err := gRPCClientStreamRequest(ctx)
|
|
||||||
// if err != nil {
|
|
||||||
// transport.AddSubscriptionError(ctx, err)
|
|
||||||
// return // must return and close channel so websocket can send error back
|
|
||||||
// }
|
|
||||||
// for {
|
|
||||||
// m, err := stream.Recv()
|
|
||||||
// if err == io.EOF {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if err != nil {
|
|
||||||
// transport.AddSubscriptionError(ctx, err)
|
|
||||||
// return // must return and close channel so websocket can send error back
|
|
||||||
// }
|
|
||||||
// ch <- m
|
|
||||||
// }
|
|
||||||
// }()
|
|
||||||
//
|
|
||||||
// return ch, nil
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// see https://github.com/99designs/gqlgen/pull/2506 for more details
|
|
||||||
func AddSubscriptionError(ctx context.Context, err *gqlerror.Error) {
|
|
||||||
subscriptionErrStruct := getSubscriptionErrorStruct(ctx)
|
|
||||||
subscriptionErrStruct.errs = append(subscriptionErrStruct.errs, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func withSubscriptionErrorContext(ctx context.Context) context.Context {
|
|
||||||
return context.WithValue(ctx, wsSubscriptionErrorCtxKey, &subscriptionError{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSubscriptionErrorStruct(ctx context.Context) *subscriptionError {
|
|
||||||
v, _ := ctx.Value(wsSubscriptionErrorCtxKey).(*subscriptionError)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSubscriptionError(ctx context.Context) []*gqlerror.Error {
|
|
||||||
return getSubscriptionErrorStruct(ctx).errs
|
|
||||||
}
|
|
||||||
55
vendor/github.com/99designs/gqlgen/graphql/input.go
generated
vendored
55
vendor/github.com/99designs/gqlgen/graphql/input.go
generated
vendored
|
|
@ -1,55 +0,0 @@
|
||||||
package graphql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
const unmarshalInputCtx key = "unmarshal_input_context"
|
|
||||||
|
|
||||||
// BuildUnmarshalerMap returns a map of unmarshal functions of the ExecutableContext
|
|
||||||
// to use with the WithUnmarshalerMap function.
|
|
||||||
func BuildUnmarshalerMap(unmarshaler ...interface{}) map[reflect.Type]reflect.Value {
|
|
||||||
maps := make(map[reflect.Type]reflect.Value)
|
|
||||||
for _, v := range unmarshaler {
|
|
||||||
ft := reflect.TypeOf(v)
|
|
||||||
if ft.Kind() == reflect.Func {
|
|
||||||
maps[ft.Out(0)] = reflect.ValueOf(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return maps
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithUnmarshalerMap returns a new context with a map from input types to their unmarshaler functions.
|
|
||||||
func WithUnmarshalerMap(ctx context.Context, maps map[reflect.Type]reflect.Value) context.Context {
|
|
||||||
return context.WithValue(ctx, unmarshalInputCtx, maps)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalInputFromContext allows unmarshaling input object from a context.
|
|
||||||
func UnmarshalInputFromContext(ctx context.Context, raw, v interface{}) error {
|
|
||||||
m, ok := ctx.Value(unmarshalInputCtx).(map[reflect.Type]reflect.Value)
|
|
||||||
if m == nil || !ok {
|
|
||||||
return errors.New("graphql: the input context is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
|
||||||
return errors.New("graphql: input must be a non-nil pointer")
|
|
||||||
}
|
|
||||||
if fn, ok := m[rv.Elem().Type()]; ok {
|
|
||||||
res := fn.Call([]reflect.Value{
|
|
||||||
reflect.ValueOf(ctx),
|
|
||||||
reflect.ValueOf(raw),
|
|
||||||
})
|
|
||||||
if err := res[1].Interface(); err != nil {
|
|
||||||
return err.(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
rv.Elem().Set(res[0])
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.New("graphql: no unmarshal function found")
|
|
||||||
}
|
|
||||||
84
vendor/github.com/99designs/gqlgen/graphql/playground/altair_playground.go
generated
vendored
84
vendor/github.com/99designs/gqlgen/graphql/playground/altair_playground.go
generated
vendored
|
|
@ -1,84 +0,0 @@
|
||||||
package playground
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
var altairPage = template.Must(template.New("altair").Parse(`<!doctype html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>{{.title}}</title>
|
|
||||||
<base href="https://cdn.jsdelivr.net/npm/altair-static@{{.version}}/build/dist/">
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
||||||
<link href="styles.css" rel="stylesheet" crossorigin="anonymous" integrity="{{.cssSRI}}"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<app-root>
|
|
||||||
<style>
|
|
||||||
.loading-screen {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class="loading-screen styled">
|
|
||||||
<div class="loading-screen-inner">
|
|
||||||
<div class="loading-screen-logo-container">
|
|
||||||
<img src="assets/img/logo_350.svg" alt="Altair">
|
|
||||||
</div>
|
|
||||||
<div class="loading-screen-loading-indicator">
|
|
||||||
<span class="loading-indicator-dot"></span>
|
|
||||||
<span class="loading-indicator-dot"></span>
|
|
||||||
<span class="loading-indicator-dot"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</app-root>
|
|
||||||
|
|
||||||
<script rel="preload" as="script" type="text/javascript" crossorigin="anonymous" integrity="{{.mainSRI}}" src="main.js"></script>
|
|
||||||
<script rel="preload" as="script" type="text/javascript" crossorigin="anonymous" integrity="{{.polyfillsSRI}}" src="polyfills.js"></script>
|
|
||||||
<script rel="preload" as="script" type="text/javascript" crossorigin="anonymous" integrity="{{.runtimeSRI}}" src="runtime.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
{{- if .endpointIsAbsolute}}
|
|
||||||
const url = {{.endpoint}};
|
|
||||||
const subscriptionUrl = {{.subscriptionEndpoint}};
|
|
||||||
{{- else}}
|
|
||||||
const url = location.protocol + '//' + location.host + {{.endpoint}};
|
|
||||||
const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:';
|
|
||||||
const subscriptionUrl = wsProto + '//' + location.host + {{.endpoint}};
|
|
||||||
{{- end}}
|
|
||||||
var altairOptions = {
|
|
||||||
endpointURL: url,
|
|
||||||
subscriptionsEndpoint: subscriptionUrl,
|
|
||||||
};
|
|
||||||
window.addEventListener("load", function() {
|
|
||||||
AltairGraphQL.init(altairOptions);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>`))
|
|
||||||
|
|
||||||
// AltairHandler responsible for setting up the altair playground
|
|
||||||
func AltairHandler(title, endpoint string) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
err := altairPage.Execute(w, map[string]interface{}{
|
|
||||||
"title": title,
|
|
||||||
"endpoint": endpoint,
|
|
||||||
"endpointIsAbsolute": endpointHasScheme(endpoint),
|
|
||||||
"subscriptionEndpoint": getSubscriptionEndpoint(endpoint),
|
|
||||||
"version": "5.0.5",
|
|
||||||
"cssSRI": "sha256-kZ35e5mdMYN5ALEbnsrA2CLn85Oe4hBodfsih9BqNxs=",
|
|
||||||
"mainSRI": "sha256-nWdVTcGTlBDV1L04UQnqod+AJedzBCnKHv6Ct65liHE=",
|
|
||||||
"polyfillsSRI": "sha256-1aVEg2sROcCQ/RxU3AlcPaRZhZdIWA92q2M+mdd/R4c=",
|
|
||||||
"runtimeSRI": "sha256-cK2XhXqQr0WS1Z5eKNdac0rJxTD6miC3ubd+aEVMQDk=",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
80
vendor/github.com/99designs/gqlgen/graphql/playground/playground.go
generated
vendored
80
vendor/github.com/99designs/gqlgen/graphql/playground/playground.go
generated
vendored
|
|
@ -3,26 +3,22 @@ package playground
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
|
var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>{{.title}}</title>
|
<title>{{.title}}</title>
|
||||||
<style>
|
<link
|
||||||
body {
|
rel="stylesheet"
|
||||||
height: 100%;
|
href="https://cdn.jsdelivr.net/npm/graphiql@{{.version}}/graphiql.min.css"
|
||||||
margin: 0;
|
integrity="{{.cssSRI}}"
|
||||||
width: 100%;
|
crossorigin="anonymous"
|
||||||
overflow: hidden;
|
/>
|
||||||
}
|
</head>
|
||||||
|
<body style="margin: 0;">
|
||||||
|
<div id="graphiql" style="height: 100vh;"></div>
|
||||||
|
|
||||||
#graphiql {
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script
|
<script
|
||||||
src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js"
|
src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js"
|
||||||
integrity="{{.reactSRI}}"
|
integrity="{{.reactSRI}}"
|
||||||
|
|
@ -33,16 +29,6 @@ var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
|
||||||
integrity="{{.reactDOMSRI}}"
|
integrity="{{.reactDOMSRI}}"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
></script>
|
></script>
|
||||||
<link
|
|
||||||
rel="stylesheet"
|
|
||||||
href="https://cdn.jsdelivr.net/npm/graphiql@{{.version}}/graphiql.min.css"
|
|
||||||
integrity="{{.cssSRI}}"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="graphiql">Loading...</div>
|
|
||||||
|
|
||||||
<script
|
<script
|
||||||
src="https://cdn.jsdelivr.net/npm/graphiql@{{.version}}/graphiql.min.js"
|
src="https://cdn.jsdelivr.net/npm/graphiql@{{.version}}/graphiql.min.js"
|
||||||
integrity="{{.jsSRI}}"
|
integrity="{{.jsSRI}}"
|
||||||
|
|
@ -50,20 +36,15 @@ var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
|
||||||
></script>
|
></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
{{- if .endpointIsAbsolute}}
|
const url = location.protocol + '//' + location.host + '{{.endpoint}}';
|
||||||
const url = {{.endpoint}};
|
|
||||||
const subscriptionUrl = {{.subscriptionEndpoint}};
|
|
||||||
{{- else}}
|
|
||||||
const url = location.protocol + '//' + location.host + {{.endpoint}};
|
|
||||||
const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:';
|
const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:';
|
||||||
const subscriptionUrl = wsProto + '//' + location.host + {{.endpoint}};
|
const subscriptionUrl = wsProto + '//' + location.host + '{{.endpoint}}';
|
||||||
{{- end}}
|
|
||||||
|
|
||||||
const fetcher = GraphiQL.createFetcher({ url, subscriptionUrl });
|
const fetcher = GraphiQL.createFetcher({ url, subscriptionUrl });
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
React.createElement(GraphiQL, {
|
React.createElement(GraphiQL, {
|
||||||
fetcher: fetcher,
|
fetcher: fetcher,
|
||||||
isHeadersEditorEnabled: true,
|
headerEditorEnabled: true,
|
||||||
shouldPersistHeaders: true
|
shouldPersistHeaders: true
|
||||||
}),
|
}),
|
||||||
document.getElementById('graphiql'),
|
document.getElementById('graphiql'),
|
||||||
|
|
@ -73,18 +54,15 @@ var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>
|
||||||
</html>
|
</html>
|
||||||
`))
|
`))
|
||||||
|
|
||||||
// Handler responsible for setting up the playground
|
|
||||||
func Handler(title string, endpoint string) http.HandlerFunc {
|
func Handler(title string, endpoint string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "text/html; charset=UTF-8")
|
w.Header().Add("Content-Type", "text/html")
|
||||||
err := page.Execute(w, map[string]interface{}{
|
err := page.Execute(w, map[string]string{
|
||||||
"title": title,
|
"title": title,
|
||||||
"endpoint": endpoint,
|
"endpoint": endpoint,
|
||||||
"endpointIsAbsolute": endpointHasScheme(endpoint),
|
"version": "1.5.16",
|
||||||
"subscriptionEndpoint": getSubscriptionEndpoint(endpoint),
|
"cssSRI": "sha256-HADQowUuFum02+Ckkv5Yu5ygRoLllHZqg0TFZXY7NHI=",
|
||||||
"version": "2.0.7",
|
"jsSRI": "sha256-uHp12yvpXC4PC9+6JmITxKuLYwjlW9crq9ywPE5Rxco=",
|
||||||
"cssSRI": "sha256-gQryfbGYeYFxnJYnfPStPYFt0+uv8RP8Dm++eh00G9c=",
|
|
||||||
"jsSRI": "sha256-qQ6pw7LwTLC+GfzN+cJsYXfVWRKH9O5o7+5H96gTJhQ=",
|
|
||||||
"reactSRI": "sha256-Ipu/TQ50iCCVZBUsZyNJfxrDk0E2yhaEIz0vqI+kFG8=",
|
"reactSRI": "sha256-Ipu/TQ50iCCVZBUsZyNJfxrDk0E2yhaEIz0vqI+kFG8=",
|
||||||
"reactDOMSRI": "sha256-nbMykgB6tsOFJ7OdVmPpdqMFVk4ZsqWocT6issAPUF0=",
|
"reactDOMSRI": "sha256-nbMykgB6tsOFJ7OdVmPpdqMFVk4ZsqWocT6issAPUF0=",
|
||||||
})
|
})
|
||||||
|
|
@ -93,27 +71,3 @@ func Handler(title string, endpoint string) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// endpointHasScheme checks if the endpoint has a scheme.
|
|
||||||
func endpointHasScheme(endpoint string) bool {
|
|
||||||
u, err := url.Parse(endpoint)
|
|
||||||
return err == nil && u.Scheme != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// getSubscriptionEndpoint returns the subscription endpoint for the given
|
|
||||||
// endpoint if it is parsable as a URL, or an empty string.
|
|
||||||
func getSubscriptionEndpoint(endpoint string) string {
|
|
||||||
u, err := url.Parse(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
switch u.Scheme {
|
|
||||||
case "https":
|
|
||||||
u.Scheme = "wss"
|
|
||||||
default:
|
|
||||||
u.Scheme = "ws"
|
|
||||||
}
|
|
||||||
|
|
||||||
return u.String()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
4
vendor/github.com/99designs/gqlgen/graphql/stats.go
generated
vendored
4
vendor/github.com/99designs/gqlgen/graphql/stats.go
generated
vendored
|
|
@ -12,7 +12,7 @@ type Stats struct {
|
||||||
Parsing TraceTiming
|
Parsing TraceTiming
|
||||||
Validation TraceTiming
|
Validation TraceTiming
|
||||||
|
|
||||||
// Stats collected by handler extensions. Don't use directly, the extension should provide a type safe way to
|
// Stats collected by handler extensions. Dont use directly, the extension should provide a type safe way to
|
||||||
// access this.
|
// access this.
|
||||||
extension map[string]interface{}
|
extension map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ var ctxTraceStart key = "trace_start"
|
||||||
|
|
||||||
// StartOperationTrace captures the current time and stores it in context. This will eventually be added to request
|
// StartOperationTrace captures the current time and stores it in context. This will eventually be added to request
|
||||||
// context but we want to grab it as soon as possible. For transports that can only handle a single graphql query
|
// context but we want to grab it as soon as possible. For transports that can only handle a single graphql query
|
||||||
// per http requests you don't need to call this at all, the server will do it for you. For transports that handle
|
// per http requests you dont need to call this at all, the server will do it for you. For transports that handle
|
||||||
// multiple (eg batching, subscriptions) this should be called before decoding each request.
|
// multiple (eg batching, subscriptions) this should be called before decoding each request.
|
||||||
func StartOperationTrace(ctx context.Context) context.Context {
|
func StartOperationTrace(ctx context.Context) context.Context {
|
||||||
return context.WithValue(ctx, ctxTraceStart, Now())
|
return context.WithValue(ctx, ctxTraceStart, Now())
|
||||||
|
|
|
||||||
5
vendor/github.com/99designs/gqlgen/graphql/string.go
generated
vendored
5
vendor/github.com/99designs/gqlgen/graphql/string.go
generated
vendored
|
|
@ -1,7 +1,6 @@
|
||||||
package graphql
|
package graphql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -56,9 +55,7 @@ func UnmarshalString(v interface{}) (string, error) {
|
||||||
case int64:
|
case int64:
|
||||||
return strconv.FormatInt(v, 10), nil
|
return strconv.FormatInt(v, 10), nil
|
||||||
case float64:
|
case float64:
|
||||||
return strconv.FormatFloat(v, 'f', -1, 64), nil
|
return fmt.Sprintf("%f", v), nil
|
||||||
case json.Number:
|
|
||||||
return string(v), nil
|
|
||||||
case bool:
|
case bool:
|
||||||
if v {
|
if v {
|
||||||
return "true", nil
|
return "true", nil
|
||||||
|
|
|
||||||
2
vendor/github.com/99designs/gqlgen/graphql/upload.go
generated
vendored
2
vendor/github.com/99designs/gqlgen/graphql/upload.go
generated
vendored
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Upload struct {
|
type Upload struct {
|
||||||
File io.ReadSeeker
|
File io.Reader
|
||||||
Filename string
|
Filename string
|
||||||
Size int64
|
Size int64
|
||||||
ContentType string
|
ContentType string
|
||||||
|
|
|
||||||
2
vendor/github.com/99designs/gqlgen/graphql/version.go
generated
vendored
2
vendor/github.com/99designs/gqlgen/graphql/version.go
generated
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
package graphql
|
package graphql
|
||||||
|
|
||||||
const Version = "v0.17.24"
|
const Version = "v0.17.2"
|
||||||
|
|
|
||||||
15
vendor/github.com/99designs/gqlgen/init-templates/gqlgen.yml.gotmpl
generated
vendored
15
vendor/github.com/99designs/gqlgen/init-templates/gqlgen.yml.gotmpl
generated
vendored
|
|
@ -4,13 +4,13 @@ schema:
|
||||||
|
|
||||||
# Where should the generated server code go?
|
# Where should the generated server code go?
|
||||||
exec:
|
exec:
|
||||||
filename: graph/generated.go
|
filename: graph/generated/generated.go
|
||||||
package: graph
|
package: generated
|
||||||
|
|
||||||
# Uncomment to enable federation
|
# Uncomment to enable federation
|
||||||
# federation:
|
# federation:
|
||||||
# filename: graph/federation.go
|
# filename: graph/generated/federation.go
|
||||||
# package: graph
|
# package: generated
|
||||||
|
|
||||||
# Where should any generated models go?
|
# Where should any generated models go?
|
||||||
model:
|
model:
|
||||||
|
|
@ -29,13 +29,6 @@ resolver:
|
||||||
# Optional: turn on to use []Thing instead of []*Thing
|
# Optional: turn on to use []Thing instead of []*Thing
|
||||||
# omit_slice_element_pointers: false
|
# omit_slice_element_pointers: 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: set to speed up generation time by not performing a final validation pass.
|
# Optional: set to speed up generation time by not performing a final validation pass.
|
||||||
# skip_validation: true
|
# skip_validation: true
|
||||||
|
|
||||||
|
|
|
||||||
21
vendor/github.com/99designs/gqlgen/internal/code/compare.go
generated
vendored
21
vendor/github.com/99designs/gqlgen/internal/code/compare.go
generated
vendored
|
|
@ -39,16 +39,12 @@ func CompatibleTypes(expected types.Type, actual types.Type) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *types.Basic:
|
case *types.Basic:
|
||||||
if actualBasic, ok := actual.(*types.Basic); ok {
|
if actual, ok := actual.(*types.Basic); ok {
|
||||||
if similarBasicKind(actualBasic.Kind()) != expected.Kind() {
|
if actual.Kind() != expected.Kind() {
|
||||||
return fmt.Errorf("basic kind differs, %s != %s", expected.Name(), actualBasic.Name())
|
return fmt.Errorf("basic kind differs, %s != %s", expected.Name(), actual.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
} else if actual, ok := actual.(*types.Named); ok {
|
|
||||||
if underlyingBasic, ok := actual.Underlying().(*types.Basic); ok {
|
|
||||||
return CompatibleTypes(expected, underlyingBasic)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
|
|
@ -163,14 +159,3 @@ func CompatibleTypes(expected types.Type, actual types.Type) error {
|
||||||
|
|
||||||
return fmt.Errorf("type mismatch %T != %T", expected, actual)
|
return fmt.Errorf("type mismatch %T != %T", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func similarBasicKind(kind types.BasicKind) types.BasicKind {
|
|
||||||
switch kind {
|
|
||||||
case types.Int8, types.Int16:
|
|
||||||
return types.Int64
|
|
||||||
case types.Uint, types.Uint8, types.Uint16, types.Uint32: // exclude Uint64: it still needs scalar with custom marshalling/unmarshalling because it is bigger then int64
|
|
||||||
return types.Int64
|
|
||||||
default:
|
|
||||||
return kind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
31
vendor/github.com/99designs/gqlgen/internal/code/imports.go
generated
vendored
31
vendor/github.com/99designs/gqlgen/internal/code/imports.go
generated
vendored
|
|
@ -1,12 +1,10 @@
|
||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"go/build"
|
"go/build"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -28,7 +26,7 @@ func NameForDir(dir string) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SanitizePackageName(filepath.Base(dir))
|
return SanitizePackageName(filepath.Base(dir))
|
||||||
}
|
}
|
||||||
files, err := os.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SanitizePackageName(filepath.Base(dir))
|
return SanitizePackageName(filepath.Base(dir))
|
||||||
}
|
}
|
||||||
|
|
@ -75,8 +73,8 @@ func goModuleRoot(dir string) (string, bool) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if content, err := os.ReadFile(filepath.Join(modDir, "go.mod")); err == nil {
|
if content, err := ioutil.ReadFile(filepath.Join(modDir, "go.mod")); err == nil {
|
||||||
moduleName := extractModuleName(content)
|
moduleName := string(modregex.FindSubmatch(content)[1])
|
||||||
result = goModuleSearchResult{
|
result = goModuleSearchResult{
|
||||||
path: moduleName,
|
path: moduleName,
|
||||||
goModPath: modDir,
|
goModPath: modDir,
|
||||||
|
|
@ -128,27 +126,6 @@ func goModuleRoot(dir string) (string, bool) {
|
||||||
return res.path, true
|
return res.path, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractModuleName(content []byte) string {
|
|
||||||
for {
|
|
||||||
advance, tkn, err := bufio.ScanLines(content, false)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("error parsing mod file: %w", err))
|
|
||||||
}
|
|
||||||
if advance == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
s := strings.Trim(string(tkn), " \t")
|
|
||||||
if len(s) != 0 && !strings.HasPrefix(s, "//") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if advance <= len(content) {
|
|
||||||
content = content[advance:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
moduleName := string(modregex.FindSubmatch(content)[1])
|
|
||||||
return moduleName
|
|
||||||
}
|
|
||||||
|
|
||||||
// ImportPathForDir takes a path and returns a golang import path for the package
|
// ImportPathForDir takes a path and returns a golang import path for the package
|
||||||
func ImportPathForDir(dir string) (res string) {
|
func ImportPathForDir(dir string) (res string) {
|
||||||
dir, err := filepath.Abs(dir)
|
dir, err := filepath.Abs(dir)
|
||||||
|
|
|
||||||
2
vendor/github.com/99designs/gqlgen/internal/code/packages.go
generated
vendored
2
vendor/github.com/99designs/gqlgen/internal/code/packages.go
generated
vendored
|
|
@ -151,7 +151,7 @@ func (p *Packages) NameForPackage(importPath string) string {
|
||||||
pkg := p.packages[importPath]
|
pkg := p.packages[importPath]
|
||||||
|
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
// otherwise do a name only lookup for it but don't put it in the package cache.
|
// otherwise do a name only lookup for it but dont put it in the package cache.
|
||||||
p.numNameCalls++
|
p.numNameCalls++
|
||||||
pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName}, importPath)
|
pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName}, importPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
26
vendor/github.com/99designs/gqlgen/internal/rewrite/rewriter.go
generated
vendored
26
vendor/github.com/99designs/gqlgen/internal/rewrite/rewriter.go
generated
vendored
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -56,7 +56,7 @@ func (r *Rewriter) getSource(start, end token.Pos) string {
|
||||||
|
|
||||||
func (r *Rewriter) getFile(filename string) string {
|
func (r *Rewriter) getFile(filename string) string {
|
||||||
if _, ok := r.files[filename]; !ok {
|
if _, ok := r.files[filename]; !ok {
|
||||||
b, err := os.ReadFile(filename)
|
b, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("unable to load file, already exists: %w", err))
|
panic(fmt.Errorf("unable to load file, already exists: %w", err))
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ func (r *Rewriter) getFile(filename string) string {
|
||||||
return r.files[filename]
|
return r.files[filename]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rewriter) GetPrevDecl(structname string, methodname string) *ast.FuncDecl {
|
func (r *Rewriter) GetMethodBody(structname string, methodname string) string {
|
||||||
for _, f := range r.pkg.Syntax {
|
for _, f := range r.pkg.Syntax {
|
||||||
for _, d := range f.Decls {
|
for _, d := range f.Decls {
|
||||||
d, isFunc := d.(*ast.FuncDecl)
|
d, isFunc := d.(*ast.FuncDecl)
|
||||||
|
|
@ -89,29 +89,17 @@ func (r *Rewriter) GetPrevDecl(structname string, methodname string) *ast.FuncDe
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ident.Name != structname {
|
if ident.Name != structname {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
r.copied[d] = true
|
r.copied[d] = true
|
||||||
return d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rewriter) GetMethodComment(structname string, methodname string) string {
|
|
||||||
d := r.GetPrevDecl(structname, methodname)
|
|
||||||
if d != nil {
|
|
||||||
return d.Doc.Text()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rewriter) GetMethodBody(structname string, methodname string) string {
|
|
||||||
d := r.GetPrevDecl(structname, methodname)
|
|
||||||
if d != nil {
|
|
||||||
return r.getSource(d.Body.Pos()+1, d.Body.End()-1)
|
return r.getSource(d.Body.Pos()+1, d.Body.End()-1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
57
vendor/github.com/99designs/gqlgen/main.go
generated
vendored
57
vendor/github.com/99designs/gqlgen/main.go
generated
vendored
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -39,33 +39,11 @@ func fileExists(filename string) bool {
|
||||||
return !errors.Is(err, fs.ErrNotExist)
|
return !errors.Is(err, fs.ErrNotExist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// see Go source code:
|
|
||||||
// https://github.com/golang/go/blob/f57ebed35132d02e5cf016f324853217fb545e91/src/cmd/go/internal/modload/init.go#L1283
|
|
||||||
func findModuleRoot(dir string) (roots string) {
|
|
||||||
if dir == "" {
|
|
||||||
panic("dir not set")
|
|
||||||
}
|
|
||||||
dir = filepath.Clean(dir)
|
|
||||||
|
|
||||||
// Look for enclosing go.mod.
|
|
||||||
for {
|
|
||||||
if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
|
|
||||||
return dir
|
|
||||||
}
|
|
||||||
d := filepath.Dir(dir)
|
|
||||||
if d == dir { // the parent of the root is itself, so we can go no further
|
|
||||||
break
|
|
||||||
}
|
|
||||||
dir = d
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func initFile(filename, contents string) error {
|
func initFile(filename, contents string) error {
|
||||||
if err := os.MkdirAll(filepath.Dir(filename), 0o755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(filename), 0o755); err != nil {
|
||||||
return fmt.Errorf("unable to create directory for file '%s': %w\n", filename, err)
|
return fmt.Errorf("unable to create directory for file '%s': %w\n", filename, err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(filename, []byte(contents), 0o644); err != nil {
|
if err := ioutil.WriteFile(filename, []byte(contents), 0o644); err != nil {
|
||||||
return fmt.Errorf("unable to write file '%s': %w\n", filename, err)
|
return fmt.Errorf("unable to write file '%s': %w\n", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,36 +56,17 @@ var initCmd = &cli.Command{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{Name: "verbose, v", Usage: "show logs"},
|
&cli.BoolFlag{Name: "verbose, v", Usage: "show logs"},
|
||||||
&cli.StringFlag{Name: "config, c", Usage: "the config filename", Value: "gqlgen.yml"},
|
&cli.StringFlag{Name: "config, c", Usage: "the config filename", Value: "gqlgen.yml"},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{Name: "server", Usage: "where to write the server stub to", Value: "server.go"},
|
||||||
Name: "server",
|
&cli.StringFlag{Name: "schema", Usage: "where to write the schema stub to", Value: "graph/schema.graphqls"},
|
||||||
Usage: "where to write the server stub to",
|
|
||||||
Value: "server.go",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "schema",
|
|
||||||
Usage: "where to write the schema stub to",
|
|
||||||
Value: "graph/schema.graphqls",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
configFilename := ctx.String("config")
|
configFilename := ctx.String("config")
|
||||||
serverFilename := ctx.String("server")
|
serverFilename := ctx.String("server")
|
||||||
schemaFilename := ctx.String("schema")
|
schemaFilename := ctx.String("schema")
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
pkgName := code.ImportPathForDir(".")
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return fmt.Errorf("unable to determine current directory:%w", err)
|
|
||||||
}
|
|
||||||
pkgName := code.ImportPathForDir(cwd)
|
|
||||||
if pkgName == "" {
|
if pkgName == "" {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf("unable to determine import path for current directory, you probably need to run 'go mod init' first")
|
||||||
"unable to determine import path for current directory, you probably need to run 'go mod init' first",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
modRoot := findModuleRoot(cwd)
|
|
||||||
if modRoot == "" {
|
|
||||||
return fmt.Errorf("go.mod is missing. Please, do 'go mod init' first\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check schema and config don't already exist
|
// check schema and config don't already exist
|
||||||
|
|
@ -116,7 +75,7 @@ var initCmd = &cli.Command{
|
||||||
return fmt.Errorf("%s already exists", filename)
|
return fmt.Errorf("%s already exists", filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = config.LoadConfigFromDefaultLocations()
|
_, err := config.LoadConfigFromDefaultLocations()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("gqlgen.yml already exists in a parent directory\n")
|
return fmt.Errorf("gqlgen.yml already exists in a parent directory\n")
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +171,7 @@ func main() {
|
||||||
if context.Bool("verbose") {
|
if context.Bool("verbose") {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
} else {
|
} else {
|
||||||
log.SetOutput(io.Discard)
|
log.SetOutput(ioutil.Discard)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
109
vendor/github.com/99designs/gqlgen/plugin/federation/entity.go
generated
vendored
109
vendor/github.com/99designs/gqlgen/plugin/federation/entity.go
generated
vendored
|
|
@ -1,109 +0,0 @@
|
||||||
package federation
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/99designs/gqlgen/codegen/config"
|
|
||||||
"github.com/99designs/gqlgen/plugin/federation/fieldset"
|
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Entity represents a federated type
|
|
||||||
// that was declared in the GQL schema.
|
|
||||||
type Entity struct {
|
|
||||||
Name string // The same name as the type declaration
|
|
||||||
Def *ast.Definition
|
|
||||||
Resolvers []*EntityResolver
|
|
||||||
Requires []*Requires
|
|
||||||
Multi bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type EntityResolver struct {
|
|
||||||
ResolverName string // The resolver name, such as FindUserByID
|
|
||||||
KeyFields []*KeyField // The fields declared in @key.
|
|
||||||
InputType string // The Go generated input type for multi entity resolvers
|
|
||||||
}
|
|
||||||
|
|
||||||
type KeyField struct {
|
|
||||||
Definition *ast.FieldDefinition
|
|
||||||
Field fieldset.Field // len > 1 for nested fields
|
|
||||||
Type *config.TypeReference // The Go representation of that field type
|
|
||||||
}
|
|
||||||
|
|
||||||
// Requires represents an @requires clause
|
|
||||||
type Requires struct {
|
|
||||||
Name string // the name of the field
|
|
||||||
Field fieldset.Field // source Field, len > 1 for nested fields
|
|
||||||
Type *config.TypeReference // The Go representation of that field type
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Entity) allFieldsAreExternal(federationVersion int) bool {
|
|
||||||
for _, field := range e.Def.Fields {
|
|
||||||
if !e.isFieldImplicitlyExternal(field, federationVersion) && field.Directives.ForName("external") == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// In federation v2, key fields are implicitly external.
|
|
||||||
func (e *Entity) isFieldImplicitlyExternal(field *ast.FieldDefinition, federationVersion int) bool {
|
|
||||||
// Key fields are only implicitly external in Federation 2
|
|
||||||
if federationVersion != 2 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// TODO: From the spec, it seems like if an entity is not resolvable then it should not only not have a resolver, but should not appear in the _Entitiy union.
|
|
||||||
// The current implementation is a less drastic departure from the previous behavior, but should probably be reviewed.
|
|
||||||
// See https://www.apollographql.com/docs/federation/subgraph-spec/
|
|
||||||
if e.isResolvable() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// If the field is a key field, it is implicitly external
|
|
||||||
if e.isKeyField(field) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if the entity is resolvable.
|
|
||||||
func (e *Entity) isResolvable() bool {
|
|
||||||
key := e.Def.Directives.ForName("key")
|
|
||||||
if key == nil {
|
|
||||||
// If there is no key directive, the entity is resolvable.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
resolvable := key.Arguments.ForName("resolvable")
|
|
||||||
if resolvable == nil {
|
|
||||||
// If there is no resolvable argument, the entity is resolvable.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// only if resolvable: false has been set on the @key directive do we consider the entity non-resolvable.
|
|
||||||
return resolvable.Value.Raw != "false"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if a field is part of the entities key.
|
|
||||||
func (e *Entity) isKeyField(field *ast.FieldDefinition) bool {
|
|
||||||
for _, keyField := range e.keyFields() {
|
|
||||||
if keyField == field.Name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the key fields for this entity.
|
|
||||||
func (e *Entity) keyFields() []string {
|
|
||||||
key := e.Def.Directives.ForName("key")
|
|
||||||
if key == nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
fields := key.Arguments.ForName("fields")
|
|
||||||
if fields == nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
fieldSet := fieldset.New(fields.Value.Raw, nil)
|
|
||||||
keyFields := make([]string, len(fieldSet))
|
|
||||||
for i, field := range fieldSet {
|
|
||||||
keyFields[i] = field[0]
|
|
||||||
}
|
|
||||||
return keyFields
|
|
||||||
}
|
|
||||||
106
vendor/github.com/99designs/gqlgen/plugin/federation/federation.go
generated
vendored
106
vendor/github.com/99designs/gqlgen/plugin/federation/federation.go
generated
vendored
|
|
@ -1,7 +1,6 @@
|
||||||
package federation
|
package federation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -15,22 +14,14 @@ import (
|
||||||
"github.com/99designs/gqlgen/plugin/federation/fieldset"
|
"github.com/99designs/gqlgen/plugin/federation/fieldset"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed federation.gotpl
|
|
||||||
var federationTemplate string
|
|
||||||
|
|
||||||
type federation struct {
|
type federation struct {
|
||||||
Entities []*Entity
|
Entities []*Entity
|
||||||
Version int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a federation plugin that injects
|
// New returns a federation plugin that injects
|
||||||
// federated directives and types into the schema
|
// federated directives and types into the schema
|
||||||
func New(version int) plugin.Plugin {
|
func New() plugin.Plugin {
|
||||||
if version == 0 {
|
return &federation{}
|
||||||
version = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return &federation{Version: version}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the plugin name
|
// Name returns the plugin name
|
||||||
|
|
@ -60,7 +51,6 @@ func (f *federation) MutateConfig(cfg *config.Config) error {
|
||||||
Model: config.StringList{"github.com/99designs/gqlgen/graphql.Map"},
|
Model: config.StringList{"github.com/99designs/gqlgen/graphql.Map"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for typeName, entry := range builtins {
|
for typeName, entry := range builtins {
|
||||||
if cfg.Models.Exists(typeName) {
|
if cfg.Models.Exists(typeName) {
|
||||||
return fmt.Errorf("%v already exists which must be reserved when Federation is enabled", typeName)
|
return fmt.Errorf("%v already exists which must be reserved when Federation is enabled", typeName)
|
||||||
|
|
@ -73,46 +63,22 @@ func (f *federation) MutateConfig(cfg *config.Config) error {
|
||||||
cfg.Directives["key"] = config.DirectiveConfig{SkipRuntime: true}
|
cfg.Directives["key"] = config.DirectiveConfig{SkipRuntime: true}
|
||||||
cfg.Directives["extends"] = config.DirectiveConfig{SkipRuntime: true}
|
cfg.Directives["extends"] = config.DirectiveConfig{SkipRuntime: true}
|
||||||
|
|
||||||
// Federation 2 specific directives
|
|
||||||
if f.Version == 2 {
|
|
||||||
cfg.Directives["shareable"] = config.DirectiveConfig{SkipRuntime: true}
|
|
||||||
cfg.Directives["link"] = config.DirectiveConfig{SkipRuntime: true}
|
|
||||||
cfg.Directives["tag"] = config.DirectiveConfig{SkipRuntime: true}
|
|
||||||
cfg.Directives["override"] = config.DirectiveConfig{SkipRuntime: true}
|
|
||||||
cfg.Directives["inaccessible"] = config.DirectiveConfig{SkipRuntime: true}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *federation) InjectSourceEarly() *ast.Source {
|
func (f *federation) InjectSourceEarly() *ast.Source {
|
||||||
input := `
|
return &ast.Source{
|
||||||
|
Name: "federation/directives.graphql",
|
||||||
|
Input: `
|
||||||
scalar _Any
|
scalar _Any
|
||||||
scalar _FieldSet
|
scalar _FieldSet
|
||||||
|
|
||||||
directive @external on FIELD_DEFINITION
|
directive @external on FIELD_DEFINITION
|
||||||
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
|
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
|
||||||
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
|
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
|
||||||
directive @extends on OBJECT | INTERFACE
|
|
||||||
`
|
|
||||||
// add version-specific changes on key directive, as well as adding the new directives for federation 2
|
|
||||||
if f.Version == 1 {
|
|
||||||
input += `
|
|
||||||
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
|
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
|
||||||
`
|
directive @extends on OBJECT | INTERFACE
|
||||||
} else if f.Version == 2 {
|
`,
|
||||||
input += `
|
|
||||||
directive @key(fields: _FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
|
|
||||||
directive @link(import: [String!], url: String!) repeatable on SCHEMA
|
|
||||||
directive @shareable on OBJECT | FIELD_DEFINITION
|
|
||||||
directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
||||||
directive @override(from: String!) on FIELD_DEFINITION
|
|
||||||
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
||||||
`
|
|
||||||
}
|
|
||||||
return &ast.Source{
|
|
||||||
Name: "federation/directives.graphql",
|
|
||||||
Input: input,
|
|
||||||
BuiltIn: true,
|
BuiltIn: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -198,6 +164,44 @@ type Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Entity represents a federated type
|
||||||
|
// that was declared in the GQL schema.
|
||||||
|
type Entity struct {
|
||||||
|
Name string // The same name as the type declaration
|
||||||
|
Def *ast.Definition
|
||||||
|
Resolvers []*EntityResolver
|
||||||
|
Requires []*Requires
|
||||||
|
Multi bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type EntityResolver struct {
|
||||||
|
ResolverName string // The resolver name, such as FindUserByID
|
||||||
|
KeyFields []*KeyField // The fields declared in @key.
|
||||||
|
InputType string // The Go generated input type for multi entity resolvers
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyField struct {
|
||||||
|
Definition *ast.FieldDefinition
|
||||||
|
Field fieldset.Field // len > 1 for nested fields
|
||||||
|
Type *config.TypeReference // The Go representation of that field type
|
||||||
|
}
|
||||||
|
|
||||||
|
// Requires represents an @requires clause
|
||||||
|
type Requires struct {
|
||||||
|
Name string // the name of the field
|
||||||
|
Field fieldset.Field // source Field, len > 1 for nested fields
|
||||||
|
Type *config.TypeReference // The Go representation of that field type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Entity) allFieldsAreExternal() bool {
|
||||||
|
for _, field := range e.Def.Fields {
|
||||||
|
if field.Directives.ForName("external") == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (f *federation) GenerateCode(data *codegen.Data) error {
|
func (f *federation) GenerateCode(data *codegen.Data) error {
|
||||||
if len(f.Entities) > 0 {
|
if len(f.Entities) > 0 {
|
||||||
if data.Objects.ByName("Entity") != nil {
|
if data.Objects.ByName("Entity") != nil {
|
||||||
|
|
@ -240,7 +244,6 @@ func (f *federation) GenerateCode(data *codegen.Data) error {
|
||||||
Data: f,
|
Data: f,
|
||||||
GeneratedHeader: true,
|
GeneratedHeader: true,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
Template: federationTemplate,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,23 +288,12 @@ func (f *federation) setEntities(schema *ast.Schema) {
|
||||||
// extend TypeDefinedInOtherService @key(fields: "id") {
|
// extend TypeDefinedInOtherService @key(fields: "id") {
|
||||||
// id: ID @external
|
// id: ID @external
|
||||||
// }
|
// }
|
||||||
if !e.allFieldsAreExternal(f.Version) {
|
if !e.allFieldsAreExternal() {
|
||||||
for _, dir := range keys {
|
for _, dir := range keys {
|
||||||
if len(dir.Arguments) > 2 {
|
if len(dir.Arguments) != 1 || dir.Arguments[0].Name != "fields" {
|
||||||
panic("More than two arguments provided for @key declaration.")
|
panic("Exactly one `fields` argument needed for @key declaration.")
|
||||||
}
|
}
|
||||||
var arg *ast.Argument
|
arg := dir.Arguments[0]
|
||||||
|
|
||||||
// since keys are able to now have multiple arguments, we need to check both possible for a possible @key(fields="" fields="")
|
|
||||||
for _, a := range dir.Arguments {
|
|
||||||
if a.Name == "fields" {
|
|
||||||
if arg != nil {
|
|
||||||
panic("More than one `fields` provided for @key declaration.")
|
|
||||||
}
|
|
||||||
arg = a
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyFieldSet := fieldset.New(arg.Value.Raw, nil)
|
keyFieldSet := fieldset.New(arg.Value.Raw, nil)
|
||||||
|
|
||||||
keyFields := make([]*KeyField, len(keyFieldSet))
|
keyFields := make([]*KeyField, len(keyFieldSet))
|
||||||
|
|
|
||||||
12
vendor/github.com/99designs/gqlgen/plugin/federation/fieldset/fieldset.go
generated
vendored
12
vendor/github.com/99designs/gqlgen/plugin/federation/fieldset/fieldset.go
generated
vendored
|
|
@ -11,12 +11,15 @@ import (
|
||||||
|
|
||||||
// Set represents a FieldSet that is used in federation directives @key and @requires.
|
// Set represents a FieldSet that is used in federation directives @key and @requires.
|
||||||
// Would be happier to reuse FieldSet parsing from gqlparser, but this suits for now.
|
// Would be happier to reuse FieldSet parsing from gqlparser, but this suits for now.
|
||||||
|
//
|
||||||
type Set []Field
|
type Set []Field
|
||||||
|
|
||||||
// Field represents a single field in a FieldSet
|
// Field represents a single field in a FieldSet
|
||||||
|
//
|
||||||
type Field []string
|
type Field []string
|
||||||
|
|
||||||
// New parses a FieldSet string into a TinyFieldSet.
|
// New parses a FieldSet string into a TinyFieldSet.
|
||||||
|
//
|
||||||
func New(raw string, prefix []string) Set {
|
func New(raw string, prefix []string) Set {
|
||||||
if !strings.Contains(raw, "{") {
|
if !strings.Contains(raw, "{") {
|
||||||
return parseUnnestedKeyFieldSet(raw, prefix)
|
return parseUnnestedKeyFieldSet(raw, prefix)
|
||||||
|
|
@ -45,6 +48,7 @@ func New(raw string, prefix []string) Set {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FieldDefinition looks up a field in the type.
|
// FieldDefinition looks up a field in the type.
|
||||||
|
//
|
||||||
func (f Field) FieldDefinition(schemaType *ast.Definition, schema *ast.Schema) *ast.FieldDefinition {
|
func (f Field) FieldDefinition(schemaType *ast.Definition, schema *ast.Schema) *ast.FieldDefinition {
|
||||||
objType := schemaType
|
objType := schemaType
|
||||||
def := objType.Fields.ForName(f[0])
|
def := objType.Fields.ForName(f[0])
|
||||||
|
|
@ -70,6 +74,7 @@ func (f Field) FieldDefinition(schemaType *ast.Definition, schema *ast.Schema) *
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeReference looks up the type of a field.
|
// TypeReference looks up the type of a field.
|
||||||
|
//
|
||||||
func (f Field) TypeReference(obj *codegen.Object, objects codegen.Objects) *codegen.Field {
|
func (f Field) TypeReference(obj *codegen.Object, objects codegen.Objects) *codegen.Field {
|
||||||
var def *codegen.Field
|
var def *codegen.Field
|
||||||
|
|
||||||
|
|
@ -84,6 +89,7 @@ func (f Field) TypeReference(obj *codegen.Object, objects codegen.Objects) *code
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToGo converts a (possibly nested) field into a proper public Go name.
|
// ToGo converts a (possibly nested) field into a proper public Go name.
|
||||||
|
//
|
||||||
func (f Field) ToGo() string {
|
func (f Field) ToGo() string {
|
||||||
var ret string
|
var ret string
|
||||||
|
|
||||||
|
|
@ -94,6 +100,7 @@ func (f Field) ToGo() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToGoPrivate converts a (possibly nested) field into a proper private Go name.
|
// ToGoPrivate converts a (possibly nested) field into a proper private Go name.
|
||||||
|
//
|
||||||
func (f Field) ToGoPrivate() string {
|
func (f Field) ToGoPrivate() string {
|
||||||
var ret string
|
var ret string
|
||||||
|
|
||||||
|
|
@ -108,11 +115,13 @@ func (f Field) ToGoPrivate() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join concatenates the field parts with a string separator between. Useful in templates.
|
// Join concatenates the field parts with a string separator between. Useful in templates.
|
||||||
|
//
|
||||||
func (f Field) Join(str string) string {
|
func (f Field) Join(str string) string {
|
||||||
return strings.Join(f, str)
|
return strings.Join(f, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// JoinGo concatenates the Go name of field parts with a string separator between. Useful in templates.
|
// JoinGo concatenates the Go name of field parts with a string separator between. Useful in templates.
|
||||||
|
//
|
||||||
func (f Field) JoinGo(str string) string {
|
func (f Field) JoinGo(str string) string {
|
||||||
strs := []string{}
|
strs := []string{}
|
||||||
|
|
||||||
|
|
@ -129,6 +138,7 @@ func (f Field) LastIndex() int {
|
||||||
// local functions
|
// local functions
|
||||||
|
|
||||||
// parseUnnestedKeyFieldSet // handles simple case where none of the fields are nested.
|
// parseUnnestedKeyFieldSet // handles simple case where none of the fields are nested.
|
||||||
|
//
|
||||||
func parseUnnestedKeyFieldSet(raw string, prefix []string) Set {
|
func parseUnnestedKeyFieldSet(raw string, prefix []string) Set {
|
||||||
ret := Set{}
|
ret := Set{}
|
||||||
|
|
||||||
|
|
@ -140,6 +150,7 @@ func parseUnnestedKeyFieldSet(raw string, prefix []string) Set {
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractSubs splits out and trims sub-expressions from before, inside, and after "{}".
|
// extractSubs splits out and trims sub-expressions from before, inside, and after "{}".
|
||||||
|
//
|
||||||
func extractSubs(str string) (string, string, string) {
|
func extractSubs(str string) (string, string, string) {
|
||||||
start := strings.Index(str, "{")
|
start := strings.Index(str, "{")
|
||||||
end := matchingBracketIndex(str, start)
|
end := matchingBracketIndex(str, start)
|
||||||
|
|
@ -151,6 +162,7 @@ func extractSubs(str string) (string, string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchingBracketIndex returns the index of the closing bracket, assuming an open bracket at start.
|
// matchingBracketIndex returns the index of the closing bracket, assuming an open bracket at start.
|
||||||
|
//
|
||||||
func matchingBracketIndex(str string, start int) int {
|
func matchingBracketIndex(str string, start int) int {
|
||||||
if start < 0 || len(str) <= start+1 {
|
if start < 0 || len(str) <= start+1 {
|
||||||
return -1
|
return -1
|
||||||
|
|
|
||||||
333
vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go
generated
vendored
333
vendor/github.com/99designs/gqlgen/plugin/modelgen/models.go
generated
vendored
|
|
@ -1,12 +1,10 @@
|
||||||
package modelgen
|
package modelgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/types"
|
"go/types"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/codegen/config"
|
"github.com/99designs/gqlgen/codegen/config"
|
||||||
"github.com/99designs/gqlgen/codegen/templates"
|
"github.com/99designs/gqlgen/codegen/templates"
|
||||||
|
|
@ -14,26 +12,16 @@ import (
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
"github.com/vektah/gqlparser/v2/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed models.gotpl
|
type BuildMutateHook = func(b *ModelBuild) *ModelBuild
|
||||||
var modelTemplate string
|
|
||||||
|
|
||||||
type (
|
type FieldMutateHook = func(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Field, error)
|
||||||
BuildMutateHook = func(b *ModelBuild) *ModelBuild
|
|
||||||
FieldMutateHook = func(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Field, error)
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultFieldMutateHook is the default hook for the Plugin which applies the GoFieldHook and GoTagFieldHook.
|
// defaultFieldMutateHook is the default hook for the Plugin which applies the GoTagFieldHook.
|
||||||
func DefaultFieldMutateHook(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Field, error) {
|
func defaultFieldMutateHook(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Field, error) {
|
||||||
var err error
|
|
||||||
f, err = GoFieldHook(td, fd, f)
|
|
||||||
if err != nil {
|
|
||||||
return f, err
|
|
||||||
}
|
|
||||||
return GoTagFieldHook(td, fd, f)
|
return GoTagFieldHook(td, fd, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBuildMutateHook is the default hook for the Plugin which mutate ModelBuild.
|
func defaultBuildMutateHook(b *ModelBuild) *ModelBuild {
|
||||||
func DefaultBuildMutateHook(b *ModelBuild) *ModelBuild {
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +36,6 @@ type ModelBuild struct {
|
||||||
type Interface struct {
|
type Interface struct {
|
||||||
Description string
|
Description string
|
||||||
Name string
|
Name string
|
||||||
Fields []*Field
|
|
||||||
Implements []string
|
Implements []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,10 +48,7 @@ type Object struct {
|
||||||
|
|
||||||
type Field struct {
|
type Field struct {
|
||||||
Description string
|
Description string
|
||||||
// Name is the field's name as it appears in the schema
|
|
||||||
Name string
|
Name string
|
||||||
// GoName is the field's name as it appears in the generated Go code
|
|
||||||
GoName string
|
|
||||||
Type types.Type
|
Type types.Type
|
||||||
Tag string
|
Tag string
|
||||||
}
|
}
|
||||||
|
|
@ -82,8 +66,8 @@ type EnumValue struct {
|
||||||
|
|
||||||
func New() plugin.Plugin {
|
func New() plugin.Plugin {
|
||||||
return &Plugin{
|
return &Plugin{
|
||||||
MutateHook: DefaultBuildMutateHook,
|
MutateHook: defaultBuildMutateHook,
|
||||||
FieldHook: DefaultFieldMutateHook,
|
FieldHook: defaultFieldMutateHook,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,6 +83,8 @@ func (m *Plugin) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Plugin) MutateConfig(cfg *config.Config) error {
|
func (m *Plugin) MutateConfig(cfg *config.Config) error {
|
||||||
|
binder := cfg.NewBinder()
|
||||||
|
|
||||||
b := &ModelBuild{
|
b := &ModelBuild{
|
||||||
PackageName: cfg.Model.Package,
|
PackageName: cfg.Model.Package,
|
||||||
}
|
}
|
||||||
|
|
@ -109,20 +95,10 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
|
||||||
}
|
}
|
||||||
switch schemaType.Kind {
|
switch schemaType.Kind {
|
||||||
case ast.Interface, ast.Union:
|
case ast.Interface, ast.Union:
|
||||||
var fields []*Field
|
|
||||||
var err error
|
|
||||||
if !cfg.OmitGetters {
|
|
||||||
fields, err = m.generateFields(cfg, schemaType)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it := &Interface{
|
it := &Interface{
|
||||||
Description: schemaType.Description,
|
Description: schemaType.Description,
|
||||||
Name: schemaType.Name,
|
Name: schemaType.Name,
|
||||||
Implements: schemaType.Interfaces,
|
Implements: schemaType.Interfaces,
|
||||||
Fields: fields,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Interfaces = append(b.Interfaces, it)
|
b.Interfaces = append(b.Interfaces, it)
|
||||||
|
|
@ -130,16 +106,9 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
|
||||||
if schemaType == cfg.Schema.Query || schemaType == cfg.Schema.Mutation || schemaType == cfg.Schema.Subscription {
|
if schemaType == cfg.Schema.Query || schemaType == cfg.Schema.Mutation || schemaType == cfg.Schema.Subscription {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fields, err := m.generateFields(cfg, schemaType)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
it := &Object{
|
it := &Object{
|
||||||
Description: schemaType.Description,
|
Description: schemaType.Description,
|
||||||
Name: schemaType.Name,
|
Name: schemaType.Name,
|
||||||
Fields: fields,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If Interface A implements interface B, and Interface C also implements interface B
|
// If Interface A implements interface B, and Interface C also implements interface B
|
||||||
|
|
@ -160,150 +129,6 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Models = append(b.Models, it)
|
|
||||||
case ast.Enum:
|
|
||||||
it := &Enum{
|
|
||||||
Name: schemaType.Name,
|
|
||||||
Description: schemaType.Description,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range schemaType.EnumValues {
|
|
||||||
it.Values = append(it.Values, &EnumValue{
|
|
||||||
Name: v.Name,
|
|
||||||
Description: v.Description,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Enums = append(b.Enums, it)
|
|
||||||
case ast.Scalar:
|
|
||||||
b.Scalars = append(b.Scalars, schemaType.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Slice(b.Enums, func(i, j int) bool { return b.Enums[i].Name < b.Enums[j].Name })
|
|
||||||
sort.Slice(b.Models, func(i, j int) bool { return b.Models[i].Name < b.Models[j].Name })
|
|
||||||
sort.Slice(b.Interfaces, func(i, j int) bool { return b.Interfaces[i].Name < b.Interfaces[j].Name })
|
|
||||||
|
|
||||||
// if we are not just turning all struct-type fields in generated structs into pointers, we need to at least
|
|
||||||
// check for cyclical relationships and recursive structs
|
|
||||||
if !cfg.StructFieldsAlwaysPointers {
|
|
||||||
findAndHandleCyclicalRelationships(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, it := range b.Enums {
|
|
||||||
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
|
||||||
}
|
|
||||||
for _, it := range b.Models {
|
|
||||||
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
|
||||||
}
|
|
||||||
for _, it := range b.Interfaces {
|
|
||||||
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
|
||||||
}
|
|
||||||
for _, it := range b.Scalars {
|
|
||||||
cfg.Models.Add(it, "github.com/99designs/gqlgen/graphql.String")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(b.Models) == 0 && len(b.Enums) == 0 && len(b.Interfaces) == 0 && len(b.Scalars) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if m.MutateHook != nil {
|
|
||||||
b = m.MutateHook(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
getInterfaceByName := func(name string) *Interface {
|
|
||||||
// Allow looking up interfaces, so template can generate getters for each field
|
|
||||||
for _, i := range b.Interfaces {
|
|
||||||
if i.Name == name {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
gettersGenerated := make(map[string]map[string]struct{})
|
|
||||||
generateGetter := func(model *Object, field *Field) string {
|
|
||||||
if model == nil || field == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let templates check if a given getter has been generated already
|
|
||||||
typeGetters, exists := gettersGenerated[model.Name]
|
|
||||||
if !exists {
|
|
||||||
typeGetters = make(map[string]struct{})
|
|
||||||
gettersGenerated[model.Name] = typeGetters
|
|
||||||
}
|
|
||||||
|
|
||||||
_, exists = typeGetters[field.GoName]
|
|
||||||
typeGetters[field.GoName] = struct{}{}
|
|
||||||
if exists {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
_, interfaceFieldTypeIsPointer := field.Type.(*types.Pointer)
|
|
||||||
var structFieldTypeIsPointer bool
|
|
||||||
for _, f := range model.Fields {
|
|
||||||
if f.GoName == field.GoName {
|
|
||||||
_, structFieldTypeIsPointer = f.Type.(*types.Pointer)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goType := templates.CurrentImports.LookupType(field.Type)
|
|
||||||
if strings.HasPrefix(goType, "[]") {
|
|
||||||
getter := fmt.Sprintf("func (this %s) Get%s() %s {\n", templates.ToGo(model.Name), field.GoName, goType)
|
|
||||||
getter += fmt.Sprintf("\tif this.%s == nil { return nil }\n", field.GoName)
|
|
||||||
getter += fmt.Sprintf("\tinterfaceSlice := make(%s, 0, len(this.%s))\n", goType, field.GoName)
|
|
||||||
getter += fmt.Sprintf("\tfor _, concrete := range this.%s { interfaceSlice = append(interfaceSlice, ", field.GoName)
|
|
||||||
if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer {
|
|
||||||
getter += "&"
|
|
||||||
} else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer {
|
|
||||||
getter += "*"
|
|
||||||
}
|
|
||||||
getter += "concrete) }\n"
|
|
||||||
getter += "\treturn interfaceSlice\n"
|
|
||||||
getter += "}"
|
|
||||||
return getter
|
|
||||||
} else {
|
|
||||||
getter := fmt.Sprintf("func (this %s) Get%s() %s { return ", templates.ToGo(model.Name), field.GoName, goType)
|
|
||||||
|
|
||||||
if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer {
|
|
||||||
getter += "&"
|
|
||||||
} else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer {
|
|
||||||
getter += "*"
|
|
||||||
}
|
|
||||||
|
|
||||||
getter += fmt.Sprintf("this.%s }", field.GoName)
|
|
||||||
return getter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
funcMap := template.FuncMap{
|
|
||||||
"getInterfaceByName": getInterfaceByName,
|
|
||||||
"generateGetter": generateGetter,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := templates.Render(templates.Options{
|
|
||||||
PackageName: cfg.Model.Package,
|
|
||||||
Filename: cfg.Model.Filename,
|
|
||||||
Data: b,
|
|
||||||
GeneratedHeader: true,
|
|
||||||
Packages: cfg.Packages,
|
|
||||||
Template: modelTemplate,
|
|
||||||
Funcs: funcMap,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// We may have generated code in a package we already loaded, so we reload all packages
|
|
||||||
// to allow packages to be compared correctly
|
|
||||||
cfg.ReloadAllPackages()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition) ([]*Field, error) {
|
|
||||||
binder := cfg.NewBinder()
|
|
||||||
fields := make([]*Field, 0)
|
|
||||||
|
|
||||||
for _, field := range schemaType.Fields {
|
for _, field := range schemaType.Fields {
|
||||||
var typ types.Type
|
var typ types.Type
|
||||||
fieldDef := cfg.Schema.Types[field.Type.Name()]
|
fieldDef := cfg.Schema.Types[field.Type.Name()]
|
||||||
|
|
@ -312,7 +137,7 @@ func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition)
|
||||||
var err error
|
var err error
|
||||||
typ, err = binder.FindTypeFromName(cfg.Models[field.Type.Name()].Model[0])
|
typ, err = binder.FindTypeFromName(cfg.Models[field.Type.Name()].Model[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch fieldDef.Kind {
|
switch fieldDef.Kind {
|
||||||
|
|
@ -353,22 +178,19 @@ func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
name := templates.ToGo(field.Name)
|
name := field.Name
|
||||||
if nameOveride := cfg.Models[schemaType.Name].Fields[field.Name].FieldName; nameOveride != "" {
|
if nameOveride := cfg.Models[schemaType.Name].Fields[field.Name].FieldName; nameOveride != "" {
|
||||||
name = nameOveride
|
name = nameOveride
|
||||||
}
|
}
|
||||||
|
|
||||||
typ = binder.CopyModifiersFromAst(field.Type, typ)
|
typ = binder.CopyModifiersFromAst(field.Type, typ)
|
||||||
|
|
||||||
if cfg.StructFieldsAlwaysPointers {
|
|
||||||
if isStruct(typ) && (fieldDef.Kind == ast.Object || fieldDef.Kind == ast.InputObject) {
|
if isStruct(typ) && (fieldDef.Kind == ast.Object || fieldDef.Kind == ast.InputObject) {
|
||||||
typ = types.NewPointer(typ)
|
typ = types.NewPointer(typ)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
f := &Field{
|
f := &Field{
|
||||||
Name: field.Name,
|
Name: name,
|
||||||
GoName: name,
|
|
||||||
Type: typ,
|
Type: typ,
|
||||||
Description: field.Description,
|
Description: field.Description,
|
||||||
Tag: `json:"` + field.Name + `"`,
|
Tag: `json:"` + field.Name + `"`,
|
||||||
|
|
@ -377,15 +199,74 @@ func (m *Plugin) generateFields(cfg *config.Config, schemaType *ast.Definition)
|
||||||
if m.FieldHook != nil {
|
if m.FieldHook != nil {
|
||||||
mf, err := m.FieldHook(schemaType, field, f)
|
mf, err := m.FieldHook(schemaType, field, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("generror: field %v.%v: %w", schemaType.Name, field.Name, err)
|
return fmt.Errorf("generror: field %v.%v: %w", it.Name, field.Name, err)
|
||||||
}
|
}
|
||||||
f = mf
|
f = mf
|
||||||
}
|
}
|
||||||
|
|
||||||
fields = append(fields, f)
|
it.Fields = append(it.Fields, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields, nil
|
b.Models = append(b.Models, it)
|
||||||
|
case ast.Enum:
|
||||||
|
it := &Enum{
|
||||||
|
Name: schemaType.Name,
|
||||||
|
Description: schemaType.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range schemaType.EnumValues {
|
||||||
|
it.Values = append(it.Values, &EnumValue{
|
||||||
|
Name: v.Name,
|
||||||
|
Description: v.Description,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Enums = append(b.Enums, it)
|
||||||
|
case ast.Scalar:
|
||||||
|
b.Scalars = append(b.Scalars, schemaType.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Slice(b.Enums, func(i, j int) bool { return b.Enums[i].Name < b.Enums[j].Name })
|
||||||
|
sort.Slice(b.Models, func(i, j int) bool { return b.Models[i].Name < b.Models[j].Name })
|
||||||
|
sort.Slice(b.Interfaces, func(i, j int) bool { return b.Interfaces[i].Name < b.Interfaces[j].Name })
|
||||||
|
|
||||||
|
for _, it := range b.Enums {
|
||||||
|
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
||||||
|
}
|
||||||
|
for _, it := range b.Models {
|
||||||
|
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
||||||
|
}
|
||||||
|
for _, it := range b.Interfaces {
|
||||||
|
cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name))
|
||||||
|
}
|
||||||
|
for _, it := range b.Scalars {
|
||||||
|
cfg.Models.Add(it, "github.com/99designs/gqlgen/graphql.String")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.Models) == 0 && len(b.Enums) == 0 && len(b.Interfaces) == 0 && len(b.Scalars) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.MutateHook != nil {
|
||||||
|
b = m.MutateHook(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := templates.Render(templates.Options{
|
||||||
|
PackageName: cfg.Model.Package,
|
||||||
|
Filename: cfg.Model.Filename,
|
||||||
|
Data: b,
|
||||||
|
GeneratedHeader: true,
|
||||||
|
Packages: cfg.Packages,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// We may have generated code in a package we already loaded, so we reload all packages
|
||||||
|
// to allow packages to be compared correctly
|
||||||
|
cfg.ReloadAllPackages()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoTagFieldHook applies the goTag directive to the generated Field f. When applying the Tag to the field, the field
|
// GoTagFieldHook applies the goTag directive to the generated Field f. When applying the Tag to the field, the field
|
||||||
|
|
@ -418,73 +299,7 @@ func GoTagFieldHook(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Fie
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoFieldHook applies the goField directive to the generated Field f.
|
|
||||||
func GoFieldHook(td *ast.Definition, fd *ast.FieldDefinition, f *Field) (*Field, error) {
|
|
||||||
args := make([]string, 0)
|
|
||||||
_ = args
|
|
||||||
for _, goField := range fd.Directives.ForNames("goField") {
|
|
||||||
if arg := goField.Arguments.ForName("name"); arg != nil {
|
|
||||||
if k, err := arg.Value.Value(nil); err == nil {
|
|
||||||
f.GoName = k.(string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return f, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isStruct(t types.Type) bool {
|
func isStruct(t types.Type) bool {
|
||||||
_, is := t.Underlying().(*types.Struct)
|
_, is := t.Underlying().(*types.Struct)
|
||||||
return is
|
return is
|
||||||
}
|
}
|
||||||
|
|
||||||
// findAndHandleCyclicalRelationships checks for cyclical relationships between generated structs and replaces them
|
|
||||||
// with pointers. These relationships will produce compilation errors if they are not pointers.
|
|
||||||
// Also handles recursive structs.
|
|
||||||
func findAndHandleCyclicalRelationships(b *ModelBuild) {
|
|
||||||
for ii, structA := range b.Models {
|
|
||||||
for _, fieldA := range structA.Fields {
|
|
||||||
if strings.Contains(fieldA.Type.String(), "NotCyclicalA") {
|
|
||||||
fmt.Print()
|
|
||||||
}
|
|
||||||
if !isStruct(fieldA.Type) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// the field Type string will be in the form "github.com/99designs/gqlgen/codegen/testserver/followschema.LoopA"
|
|
||||||
// we only want the part after the last dot: "LoopA"
|
|
||||||
// this could lead to false positives, as we are only checking the name of the struct type, but these
|
|
||||||
// should be extremely rare, if it is even possible at all.
|
|
||||||
fieldAStructNameParts := strings.Split(fieldA.Type.String(), ".")
|
|
||||||
fieldAStructName := fieldAStructNameParts[len(fieldAStructNameParts)-1]
|
|
||||||
|
|
||||||
// find this struct type amongst the generated structs
|
|
||||||
for jj, structB := range b.Models {
|
|
||||||
if structB.Name != fieldAStructName {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if structB contains a cyclical reference back to structA
|
|
||||||
var cyclicalReferenceFound bool
|
|
||||||
for _, fieldB := range structB.Fields {
|
|
||||||
if !isStruct(fieldB.Type) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldBStructNameParts := strings.Split(fieldB.Type.String(), ".")
|
|
||||||
fieldBStructName := fieldBStructNameParts[len(fieldBStructNameParts)-1]
|
|
||||||
if fieldBStructName == structA.Name {
|
|
||||||
cyclicalReferenceFound = true
|
|
||||||
fieldB.Type = types.NewPointer(fieldB.Type)
|
|
||||||
// keep looping in case this struct has additional fields of this type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if this is a recursive struct (i.e. structA == structB), ensure that we only change this field to a pointer once
|
|
||||||
if cyclicalReferenceFound && ii != jj {
|
|
||||||
fieldA.Type = types.NewPointer(fieldA.Type)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
48
vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl
generated
vendored
48
vendor/github.com/99designs/gqlgen/plugin/modelgen/models.gotpl
generated
vendored
|
|
@ -14,88 +14,74 @@
|
||||||
|
|
||||||
{{- range $model := .Interfaces }}
|
{{- range $model := .Interfaces }}
|
||||||
{{ with .Description }} {{.|prefixLines "// "}} {{ end }}
|
{{ with .Description }} {{.|prefixLines "// "}} {{ end }}
|
||||||
type {{ goModelName .Name }} interface {
|
type {{.Name|go }} interface {
|
||||||
{{- range $impl := .Implements }}
|
{{- range $impl := .Implements }}
|
||||||
Is{{ goModelName $impl }}()
|
{{ $impl|go }}
|
||||||
{{- end }}
|
|
||||||
Is{{ goModelName .Name }}()
|
|
||||||
{{- range $field := .Fields }}
|
|
||||||
{{- with .Description }}
|
|
||||||
{{.|prefixLines "// "}}
|
|
||||||
{{- end}}
|
|
||||||
Get{{ $field.GoName }}() {{ $field.Type | ref }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
Is{{.Name|go }}()
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{ range $model := .Models }}
|
{{ range $model := .Models }}
|
||||||
{{with .Description }} {{.|prefixLines "// "}} {{end}}
|
{{with .Description }} {{.|prefixLines "// "}} {{end}}
|
||||||
type {{ goModelName .Name }} struct {
|
type {{ .Name|go }} struct {
|
||||||
{{- range $field := .Fields }}
|
{{- range $field := .Fields }}
|
||||||
{{- with .Description }}
|
{{- with .Description }}
|
||||||
{{.|prefixLines "// "}}
|
{{.|prefixLines "// "}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{ $field.GoName }} {{$field.Type | ref}} `{{$field.Tag}}`
|
{{ $field.Name|go }} {{$field.Type | ref}} `{{$field.Tag}}`
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ range .Implements }}
|
{{- range $iface := .Implements }}
|
||||||
func ({{ goModelName $model.Name }}) Is{{ goModelName . }}() {}
|
func ({{ $model.Name|go }}) Is{{ $iface|go }}() {}
|
||||||
{{- with getInterfaceByName . }}
|
|
||||||
{{- range .Fields }}
|
|
||||||
{{- with .Description }}
|
|
||||||
{{.|prefixLines "// "}}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ generateGetter $model . }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
{{ end }}
|
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
{{ range $enum := .Enums }}
|
{{ range $enum := .Enums }}
|
||||||
{{ with .Description }} {{.|prefixLines "// "}} {{end}}
|
{{ with .Description }} {{.|prefixLines "// "}} {{end}}
|
||||||
type {{ goModelName .Name }} string
|
type {{.Name|go }} string
|
||||||
const (
|
const (
|
||||||
{{- range $value := .Values}}
|
{{- range $value := .Values}}
|
||||||
{{- with .Description}}
|
{{- with .Description}}
|
||||||
{{.|prefixLines "// "}}
|
{{.|prefixLines "// "}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{ goModelName $enum.Name .Name }} {{ goModelName $enum.Name }} = {{ .Name|quote }}
|
{{ $enum.Name|go }}{{ .Name|go }} {{$enum.Name|go }} = {{.Name|quote}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
)
|
)
|
||||||
|
|
||||||
var All{{ goModelName .Name }} = []{{ goModelName .Name }}{
|
var All{{.Name|go }} = []{{ .Name|go }}{
|
||||||
{{- range $value := .Values}}
|
{{- range $value := .Values}}
|
||||||
{{ goModelName $enum.Name .Name }},
|
{{$enum.Name|go }}{{ .Name|go }},
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e {{ goModelName .Name }}) IsValid() bool {
|
func (e {{.Name|go }}) IsValid() bool {
|
||||||
switch e {
|
switch e {
|
||||||
case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ goModelName $enum.Name $element.Name }}{{end}}:
|
case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.Name|go }}{{ $element.Name|go }}{{end}}:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e {{ goModelName .Name }}) String() string {
|
func (e {{.Name|go }}) String() string {
|
||||||
return string(e)
|
return string(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{ goModelName .Name }}) UnmarshalGQL(v interface{}) error {
|
func (e *{{.Name|go }}) UnmarshalGQL(v interface{}) error {
|
||||||
str, ok := v.(string)
|
str, ok := v.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("enums must be strings")
|
return fmt.Errorf("enums must be strings")
|
||||||
}
|
}
|
||||||
|
|
||||||
*e = {{ goModelName .Name }}(str)
|
*e = {{ .Name|go }}(str)
|
||||||
if !e.IsValid() {
|
if !e.IsValid() {
|
||||||
return fmt.Errorf("%s is not a valid {{ .Name }}", str)
|
return fmt.Errorf("%s is not a valid {{ .Name }}", str)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e {{ goModelName .Name }}) MarshalGQL(w io.Writer) {
|
func (e {{.Name|go }}) MarshalGQL(w io.Writer) {
|
||||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
32
vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go
generated
vendored
32
vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.go
generated
vendored
|
|
@ -1,29 +1,19 @@
|
||||||
package resolvergen
|
package resolvergen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"go/ast"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/text/cases"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/codegen"
|
"github.com/99designs/gqlgen/codegen"
|
||||||
"github.com/99designs/gqlgen/codegen/config"
|
"github.com/99designs/gqlgen/codegen/config"
|
||||||
"github.com/99designs/gqlgen/codegen/templates"
|
"github.com/99designs/gqlgen/codegen/templates"
|
||||||
"github.com/99designs/gqlgen/graphql"
|
|
||||||
"github.com/99designs/gqlgen/internal/rewrite"
|
"github.com/99designs/gqlgen/internal/rewrite"
|
||||||
"github.com/99designs/gqlgen/plugin"
|
"github.com/99designs/gqlgen/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed resolver.gotpl
|
|
||||||
var resolverTemplate string
|
|
||||||
|
|
||||||
func New() plugin.Plugin {
|
func New() plugin.Plugin {
|
||||||
return &Plugin{}
|
return &Plugin{}
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +45,7 @@ func (m *Plugin) generateSingleFile(data *codegen.Data) error {
|
||||||
file := File{}
|
file := File{}
|
||||||
|
|
||||||
if _, err := os.Stat(data.Config.Resolver.Filename); err == nil {
|
if _, err := os.Stat(data.Config.Resolver.Filename); err == nil {
|
||||||
// file already exists and we do not support updating resolvers with layout = single so just return
|
// file already exists and we dont support updating resolvers with layout = single so just return
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,7 +58,7 @@ func (m *Plugin) generateSingleFile(data *codegen.Data) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver := Resolver{o, f, nil, "// foo", `panic("not implemented")`}
|
resolver := Resolver{o, f, `panic("not implemented")`}
|
||||||
file.Resolvers = append(file.Resolvers, &resolver)
|
file.Resolvers = append(file.Resolvers, &resolver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +76,6 @@ func (m *Plugin) generateSingleFile(data *codegen.Data) error {
|
||||||
Filename: data.Config.Resolver.Filename,
|
Filename: data.Config.Resolver.Filename,
|
||||||
Data: resolverBuild,
|
Data: resolverBuild,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
Template: resolverTemplate,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,9 +98,8 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {
|
||||||
files[fn] = &File{}
|
files[fn] = &File{}
|
||||||
}
|
}
|
||||||
|
|
||||||
caser := cases.Title(language.English, cases.NoLower)
|
|
||||||
rewriter.MarkStructCopied(templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type))
|
rewriter.MarkStructCopied(templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type))
|
||||||
rewriter.GetMethodBody(data.Config.Resolver.Type, caser.String(o.Name))
|
rewriter.GetMethodBody(data.Config.Resolver.Type, strings.Title(o.Name))
|
||||||
files[fn].Objects = append(files[fn].Objects, o)
|
files[fn].Objects = append(files[fn].Objects, o)
|
||||||
}
|
}
|
||||||
for _, f := range o.Fields {
|
for _, f := range o.Fields {
|
||||||
|
|
@ -120,16 +108,12 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
structName := templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type)
|
structName := templates.LcFirst(o.Name) + templates.UcFirst(data.Config.Resolver.Type)
|
||||||
comment := strings.TrimSpace(strings.TrimLeft(rewriter.GetMethodComment(structName, f.GoFieldName), `\`))
|
|
||||||
if comment == "" {
|
|
||||||
comment = fmt.Sprintf("%v is the resolver for the %v field.", f.GoFieldName, f.Name)
|
|
||||||
}
|
|
||||||
implementation := strings.TrimSpace(rewriter.GetMethodBody(structName, f.GoFieldName))
|
implementation := strings.TrimSpace(rewriter.GetMethodBody(structName, f.GoFieldName))
|
||||||
if implementation == "" {
|
if implementation == "" {
|
||||||
implementation = fmt.Sprintf("panic(fmt.Errorf(\"not implemented: %v - %v\"))", f.GoFieldName, f.Name)
|
implementation = `panic(fmt.Errorf("not implemented"))`
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver := Resolver{o, f, rewriter.GetPrevDecl(structName, f.GoFieldName), comment, implementation}
|
resolver := Resolver{o, f, implementation}
|
||||||
fn := gqlToResolverName(data.Config.Resolver.Dir(), f.Position.Src.Name, data.Config.Resolver.FilenameTemplate)
|
fn := gqlToResolverName(data.Config.Resolver.Dir(), f.Position.Src.Name, data.Config.Resolver.FilenameTemplate)
|
||||||
if files[fn] == nil {
|
if files[fn] == nil {
|
||||||
files[fn] = &File{}
|
files[fn] = &File{}
|
||||||
|
|
@ -155,12 +139,10 @@ func (m *Plugin) generatePerSchema(data *codegen.Data) error {
|
||||||
PackageName: data.Config.Resolver.Package,
|
PackageName: data.Config.Resolver.Package,
|
||||||
FileNotice: `
|
FileNotice: `
|
||||||
// This file will be automatically regenerated based on the schema, any resolver implementations
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||||
// will be copied through when generating and any unknown code will be moved to the end.
|
// will be copied through when generating and any unknown code will be moved to the end.`,
|
||||||
// Code generated by github.com/99designs/gqlgen version ` + graphql.Version,
|
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
Data: resolverBuild,
|
Data: resolverBuild,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
Template: resolverTemplate,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -216,8 +198,6 @@ func (f *File) Imports() string {
|
||||||
type Resolver struct {
|
type Resolver struct {
|
||||||
Object *codegen.Object
|
Object *codegen.Object
|
||||||
Field *codegen.Field
|
Field *codegen.Field
|
||||||
PrevDecl *ast.FuncDecl
|
|
||||||
Comment string
|
|
||||||
Implementation string
|
Implementation string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl
generated
vendored
3
vendor/github.com/99designs/gqlgen/plugin/resolvergen/resolver.gotpl
generated
vendored
|
|
@ -19,8 +19,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ range $resolver := .Resolvers -}}
|
{{ range $resolver := .Resolvers -}}
|
||||||
// {{ $resolver.Comment }}
|
func (r *{{lcFirst $resolver.Object.Name}}{{ucFirst $.ResolverType}}) {{$resolver.Field.GoFieldName}}{{ $resolver.Field.ShortResolverDeclaration }} {
|
||||||
func (r *{{lcFirst $resolver.Object.Name}}{{ucFirst $.ResolverType}}) {{$resolver.Field.GoFieldName}}{{ with $resolver.PrevDecl }}{{ $resolver.Field.ShortResolverSignature .Type }}{{ else }}{{ $resolver.Field.ShortResolverDeclaration }}{{ end }}{
|
|
||||||
{{ $resolver.Implementation }}
|
{{ $resolver.Implementation }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
5
vendor/github.com/99designs/gqlgen/plugin/servergen/server.go
generated
vendored
5
vendor/github.com/99designs/gqlgen/plugin/servergen/server.go
generated
vendored
|
|
@ -1,7 +1,6 @@
|
||||||
package servergen
|
package servergen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -12,9 +11,6 @@ import (
|
||||||
"github.com/99designs/gqlgen/plugin"
|
"github.com/99designs/gqlgen/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed server.gotpl
|
|
||||||
var serverTemplate string
|
|
||||||
|
|
||||||
func New(filename string) plugin.Plugin {
|
func New(filename string) plugin.Plugin {
|
||||||
return &Plugin{filename}
|
return &Plugin{filename}
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +37,6 @@ func (m *Plugin) GenerateCode(data *codegen.Data) error {
|
||||||
Filename: m.filename,
|
Filename: m.filename,
|
||||||
Data: serverBuild,
|
Data: serverBuild,
|
||||||
Packages: data.Config.Packages,
|
Packages: data.Config.Packages,
|
||||||
Template: serverTemplate,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
8
vendor/github.com/99designs/gqlgen/tools.go
generated
vendored
Normal file
8
vendor/github.com/99designs/gqlgen/tools.go
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
//go:build tools
|
||||||
|
// +build tools
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/matryer/moq"
|
||||||
|
)
|
||||||
29
vendor/github.com/matryer/moq/.gitignore
generated
vendored
Normal file
29
vendor/github.com/matryer/moq/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Folders
|
||||||
|
_obj
|
||||||
|
_test
|
||||||
|
|
||||||
|
# Architecture specific extensions/prefixes
|
||||||
|
*.[568vq]
|
||||||
|
[568vq].out
|
||||||
|
|
||||||
|
*.cgo1.go
|
||||||
|
*.cgo2.c
|
||||||
|
_cgo_defun.c
|
||||||
|
_cgo_gotypes.go
|
||||||
|
_cgo_export.*
|
||||||
|
|
||||||
|
_testmain.go
|
||||||
|
|
||||||
|
*.exe
|
||||||
|
*.test
|
||||||
|
*.prof
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
.playground
|
||||||
|
|
||||||
|
dist/
|
||||||
32
vendor/github.com/matryer/moq/.goreleaser.yml
generated
vendored
Normal file
32
vendor/github.com/matryer/moq/.goreleaser.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# This is an example goreleaser.yaml file with some sane defaults.
|
||||||
|
# Make sure to check the documentation at http://goreleaser.com
|
||||||
|
builds:
|
||||||
|
- env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- darwin
|
||||||
|
- windows
|
||||||
|
- linux
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
ldflags:
|
||||||
|
- -X main.Version={{.Version}}
|
||||||
|
archives:
|
||||||
|
- replacements:
|
||||||
|
darwin: macOS
|
||||||
|
linux: Linux
|
||||||
|
windows: Windows
|
||||||
|
386: i386
|
||||||
|
amd64: x86_64
|
||||||
|
checksum:
|
||||||
|
name_template: 'checksums.txt'
|
||||||
|
snapshot:
|
||||||
|
name_template: "{{ .Tag }}"
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- '^docs:'
|
||||||
|
- '^test:'
|
||||||
21
vendor/github.com/matryer/moq/LICENSE
generated
vendored
Normal file
21
vendor/github.com/matryer/moq/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2016 Mat Ryer and David Hernandez
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
135
vendor/github.com/matryer/moq/README.md
generated
vendored
Normal file
135
vendor/github.com/matryer/moq/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
 [](https://github.com/matryer/moq/actions?query=branch%3Amaster) [](https://goreportcard.com/report/github.com/matryer/moq)
|
||||||
|
|
||||||
|
Interface mocking tool for go generate.
|
||||||
|
|
||||||
|
### What is Moq?
|
||||||
|
|
||||||
|
Moq is a tool that generates a struct from any interface. The struct can be used in test code as a mock of the interface.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
above: Moq generates the code on the right.
|
||||||
|
|
||||||
|
You can read more in the [Meet Moq blog post](http://bit.ly/meetmoq).
|
||||||
|
|
||||||
|
### Installing
|
||||||
|
|
||||||
|
To start using latest released version of Moq, just run:
|
||||||
|
|
||||||
|
#### Go version < 1.16
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go get github.com/matryer/moq
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Go 1.16+
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go install github.com/matryer/moq@latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
moq [flags] source-dir interface [interface2 [interface3 [...]]]
|
||||||
|
-fmt string
|
||||||
|
go pretty-printer: gofmt, goimports or noop (default gofmt)
|
||||||
|
-out string
|
||||||
|
output file (default stdout)
|
||||||
|
-pkg string
|
||||||
|
package name (default will infer)
|
||||||
|
-stub
|
||||||
|
return zero values when no mock implementation is provided, do not panic
|
||||||
|
-skip-ensure
|
||||||
|
suppress mock implementation check, avoid import cycle if mocks
|
||||||
|
generated outside of the tested package
|
||||||
|
|
||||||
|
Specifying an alias for the mock is also supported with the format 'interface:alias'
|
||||||
|
|
||||||
|
Example: moq -pkg different . MyInterface:MyMock
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE:** `source-dir` is the directory where the source code (definition) of the target interface is located.
|
||||||
|
It needs to be a path to a directory and not the import statement for a Go package.
|
||||||
|
|
||||||
|
In a command line:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ moq -out mocks_test.go . MyInterface
|
||||||
|
```
|
||||||
|
|
||||||
|
In code (for go generate):
|
||||||
|
|
||||||
|
```go
|
||||||
|
package my
|
||||||
|
|
||||||
|
//go:generate moq -out myinterface_moq_test.go . MyInterface
|
||||||
|
|
||||||
|
type MyInterface interface {
|
||||||
|
Method1() error
|
||||||
|
Method2(i int)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run `go generate` for your package.
|
||||||
|
|
||||||
|
### How to use it
|
||||||
|
|
||||||
|
Mocking interfaces is a nice way to write unit tests where you can easily control the behaviour of the mocked object.
|
||||||
|
|
||||||
|
Moq creates a struct that has a function field for each method, which you can declare in your test code.
|
||||||
|
|
||||||
|
In this example, Moq generated the `EmailSenderMock` type:
|
||||||
|
|
||||||
|
```go
|
||||||
|
func TestCompleteSignup(t *testing.T) {
|
||||||
|
|
||||||
|
var sentTo string
|
||||||
|
|
||||||
|
mockedEmailSender = &EmailSenderMock{
|
||||||
|
SendFunc: func(to, subject, body string) error {
|
||||||
|
sentTo = to
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
CompleteSignUp("me@email.com", mockedEmailSender)
|
||||||
|
|
||||||
|
callsToSend := len(mockedEmailSender.SendCalls())
|
||||||
|
if callsToSend != 1 {
|
||||||
|
t.Errorf("Send was called %d times", callsToSend)
|
||||||
|
}
|
||||||
|
if sentTo != "me@email.com" {
|
||||||
|
t.Errorf("unexpected recipient: %s", sentTo)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func CompleteSignUp(to string, sender EmailSender) {
|
||||||
|
// TODO: this
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The mocked structure implements the interface, where each method calls the associated function field.
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
* Keep mocked logic inside the test that is using it
|
||||||
|
* Only mock the fields you need
|
||||||
|
* It will panic if a nil function gets called
|
||||||
|
* Name arguments in the interface for a better experience
|
||||||
|
* Use closured variables inside your test function to capture details about the calls to the methods
|
||||||
|
* Use `.MethodCalls()` to track the calls
|
||||||
|
* Use `go:generate` to invoke the `moq` command
|
||||||
|
* If Moq fails with a `go/format` error, it indicates the generated code was not valid.
|
||||||
|
You can run the same command with `-fmt noop` to print the generated source code without attempting to format it.
|
||||||
|
This can aid in debugging the root cause.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The Moq project (and all code) is licensed under the [MIT License](LICENSE).
|
||||||
|
|
||||||
|
Moq was created by [Mat Ryer](https://twitter.com/matryer) and [David Hernandez](https://github.com/dahernan), with ideas lovingly stolen from [Ernesto Jimenez](https://github.com/ernesto-jimenez). Featuring a major refactor by @sudo-suhas, as well as lots of other contributors.
|
||||||
|
|
||||||
|
The Moq logo was created by [Chris Ryer](http://chrisryer.co.uk) and is licensed under the [Creative Commons Attribution 3.0 License](https://creativecommons.org/licenses/by/3.0/).
|
||||||
|
|
||||||
135
vendor/github.com/matryer/moq/internal/registry/method_scope.go
generated
vendored
Normal file
135
vendor/github.com/matryer/moq/internal/registry/method_scope.go
generated
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
package registry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/types"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MethodScope is the sub-registry for allocating variables present in
|
||||||
|
// the method scope.
|
||||||
|
//
|
||||||
|
// It should be created using a registry instance.
|
||||||
|
type MethodScope struct {
|
||||||
|
registry *Registry
|
||||||
|
moqPkgPath string
|
||||||
|
|
||||||
|
vars []*Var
|
||||||
|
conflicted map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddVar allocates a variable instance and adds it to the method scope.
|
||||||
|
//
|
||||||
|
// Variables names are generated if required and are ensured to be
|
||||||
|
// without conflict with other variables and imported packages. It also
|
||||||
|
// adds the relevant imports to the registry for each added variable.
|
||||||
|
func (m *MethodScope) AddVar(vr *types.Var, suffix string) *Var {
|
||||||
|
imports := make(map[string]*Package)
|
||||||
|
m.populateImports(vr.Type(), imports)
|
||||||
|
m.resolveImportVarConflicts(imports)
|
||||||
|
|
||||||
|
name := varName(vr, suffix)
|
||||||
|
// Ensure that the var name does not conflict with a package import.
|
||||||
|
if _, ok := m.registry.searchImport(name); ok {
|
||||||
|
name += "MoqParam"
|
||||||
|
}
|
||||||
|
if _, ok := m.searchVar(name); ok || m.conflicted[name] {
|
||||||
|
name = m.resolveVarNameConflict(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := Var{
|
||||||
|
vr: vr,
|
||||||
|
imports: imports,
|
||||||
|
moqPkgPath: m.moqPkgPath,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
m.vars = append(m.vars, &v)
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MethodScope) resolveVarNameConflict(suggested string) string {
|
||||||
|
for n := 1; ; n++ {
|
||||||
|
_, ok := m.searchVar(suggested + strconv.Itoa(n))
|
||||||
|
if ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == 1 {
|
||||||
|
conflict, _ := m.searchVar(suggested)
|
||||||
|
conflict.Name += "1"
|
||||||
|
m.conflicted[suggested] = true
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
return suggested + strconv.Itoa(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m MethodScope) searchVar(name string) (*Var, bool) {
|
||||||
|
for _, v := range m.vars {
|
||||||
|
if v.Name == name {
|
||||||
|
return v, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// populateImports extracts all the package imports for a given type
|
||||||
|
// recursively. The imported packages by a single type can be more than
|
||||||
|
// one (ex: map[a.Type]b.Type).
|
||||||
|
func (m MethodScope) populateImports(t types.Type, imports map[string]*Package) {
|
||||||
|
switch t := t.(type) {
|
||||||
|
case *types.Named:
|
||||||
|
if pkg := t.Obj().Pkg(); pkg != nil {
|
||||||
|
imports[stripVendorPath(pkg.Path())] = m.registry.AddImport(pkg)
|
||||||
|
}
|
||||||
|
|
||||||
|
case *types.Array:
|
||||||
|
m.populateImports(t.Elem(), imports)
|
||||||
|
|
||||||
|
case *types.Slice:
|
||||||
|
m.populateImports(t.Elem(), imports)
|
||||||
|
|
||||||
|
case *types.Signature:
|
||||||
|
for i := 0; i < t.Params().Len(); i++ {
|
||||||
|
m.populateImports(t.Params().At(i).Type(), imports)
|
||||||
|
}
|
||||||
|
for i := 0; i < t.Results().Len(); i++ {
|
||||||
|
m.populateImports(t.Results().At(i).Type(), imports)
|
||||||
|
}
|
||||||
|
|
||||||
|
case *types.Map:
|
||||||
|
m.populateImports(t.Key(), imports)
|
||||||
|
m.populateImports(t.Elem(), imports)
|
||||||
|
|
||||||
|
case *types.Chan:
|
||||||
|
m.populateImports(t.Elem(), imports)
|
||||||
|
|
||||||
|
case *types.Pointer:
|
||||||
|
m.populateImports(t.Elem(), imports)
|
||||||
|
|
||||||
|
case *types.Struct: // anonymous struct
|
||||||
|
for i := 0; i < t.NumFields(); i++ {
|
||||||
|
m.populateImports(t.Field(i).Type(), imports)
|
||||||
|
}
|
||||||
|
|
||||||
|
case *types.Interface: // anonymous interface
|
||||||
|
for i := 0; i < t.NumExplicitMethods(); i++ {
|
||||||
|
m.populateImports(t.ExplicitMethod(i).Type(), imports)
|
||||||
|
}
|
||||||
|
for i := 0; i < t.NumEmbeddeds(); i++ {
|
||||||
|
m.populateImports(t.EmbeddedType(i), imports)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveImportVarConflicts ensures that all the newly added imports do not
|
||||||
|
// conflict with any of the existing vars.
|
||||||
|
func (m MethodScope) resolveImportVarConflicts(imports map[string]*Package) {
|
||||||
|
// Ensure that all the newly added imports do not conflict with any of the
|
||||||
|
// existing vars.
|
||||||
|
for _, imprt := range imports {
|
||||||
|
if v, ok := m.searchVar(imprt.Qualifier()); ok {
|
||||||
|
v.Name += "MoqParam"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
93
vendor/github.com/matryer/moq/internal/registry/package.go
generated
vendored
Normal file
93
vendor/github.com/matryer/moq/internal/registry/package.go
generated
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
package registry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/types"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Package represents an imported package.
|
||||||
|
type Package struct {
|
||||||
|
pkg *types.Package
|
||||||
|
|
||||||
|
Alias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPackage creates a new instance of Package.
|
||||||
|
func NewPackage(pkg *types.Package) *Package { return &Package{pkg: pkg} }
|
||||||
|
|
||||||
|
// Qualifier returns the qualifier which must be used to refer to types
|
||||||
|
// declared in the package.
|
||||||
|
func (p *Package) Qualifier() string {
|
||||||
|
if p == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Alias != "" {
|
||||||
|
return p.Alias
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.pkg.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Path is the full package import path (without vendor).
|
||||||
|
func (p *Package) Path() string {
|
||||||
|
if p == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return stripVendorPath(p.pkg.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
var replacer = strings.NewReplacer(
|
||||||
|
"go-", "",
|
||||||
|
"-go", "",
|
||||||
|
"-", "",
|
||||||
|
"_", "",
|
||||||
|
".", "",
|
||||||
|
"@", "",
|
||||||
|
"+", "",
|
||||||
|
"~", "",
|
||||||
|
)
|
||||||
|
|
||||||
|
// uniqueName generates a unique name for a package by concatenating
|
||||||
|
// path components. The generated name is guaranteed to unique with an
|
||||||
|
// appropriate level because the full package import paths themselves
|
||||||
|
// are unique.
|
||||||
|
func (p Package) uniqueName(lvl int) string {
|
||||||
|
pp := strings.Split(p.Path(), "/")
|
||||||
|
reverse(pp)
|
||||||
|
|
||||||
|
var name string
|
||||||
|
for i := 0; i < min(len(pp), lvl+1); i++ {
|
||||||
|
name = strings.ToLower(replacer.Replace(pp[i])) + name
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
// stripVendorPath strips the vendor dir prefix from a package path.
|
||||||
|
// For example we might encounter an absolute path like
|
||||||
|
// github.com/foo/bar/vendor/github.com/pkg/errors which is resolved
|
||||||
|
// to github.com/pkg/errors.
|
||||||
|
func stripVendorPath(p string) string {
|
||||||
|
parts := strings.Split(p, "/vendor/")
|
||||||
|
if len(parts) == 1 {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
return strings.TrimLeft(path.Join(parts[1:]...), "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func reverse(a []string) {
|
||||||
|
for i := len(a)/2 - 1; i >= 0; i-- {
|
||||||
|
opp := len(a) - 1 - i
|
||||||
|
a[i], a[opp] = a[opp], a[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
190
vendor/github.com/matryer/moq/internal/registry/registry.go
generated
vendored
Normal file
190
vendor/github.com/matryer/moq/internal/registry/registry.go
generated
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
package registry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"go/types"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/tools/go/packages"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Registry encapsulates types information for the source and mock
|
||||||
|
// destination package. For the mock package, it tracks the list of
|
||||||
|
// imports and ensures there are no conflicts in the imported package
|
||||||
|
// qualifiers.
|
||||||
|
type Registry struct {
|
||||||
|
srcPkg *packages.Package
|
||||||
|
moqPkgPath string
|
||||||
|
aliases map[string]string
|
||||||
|
imports map[string]*Package
|
||||||
|
}
|
||||||
|
|
||||||
|
// New loads the source package info and returns a new instance of
|
||||||
|
// Registry.
|
||||||
|
func New(srcDir, moqPkg string) (*Registry, error) {
|
||||||
|
srcPkg, err := pkgInfoFromPath(
|
||||||
|
srcDir, packages.NeedName|packages.NeedSyntax|packages.NeedTypes|packages.NeedTypesInfo,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("couldn't load source package: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Registry{
|
||||||
|
srcPkg: srcPkg,
|
||||||
|
moqPkgPath: findPkgPath(moqPkg, srcPkg),
|
||||||
|
aliases: parseImportsAliases(srcPkg),
|
||||||
|
imports: make(map[string]*Package),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SrcPkg returns the types info for the source package.
|
||||||
|
func (r Registry) SrcPkg() *types.Package {
|
||||||
|
return r.srcPkg.Types
|
||||||
|
}
|
||||||
|
|
||||||
|
// SrcPkgName returns the name of the source package.
|
||||||
|
func (r Registry) SrcPkgName() string {
|
||||||
|
return r.srcPkg.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// LookupInterface returns the underlying interface definition of the
|
||||||
|
// given interface name.
|
||||||
|
func (r Registry) LookupInterface(name string) (*types.Interface, error) {
|
||||||
|
obj := r.SrcPkg().Scope().Lookup(name)
|
||||||
|
if obj == nil {
|
||||||
|
return nil, fmt.Errorf("interface not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !types.IsInterface(obj.Type()) {
|
||||||
|
return nil, fmt.Errorf("%s (%s) is not an interface", name, obj.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj.Type().Underlying().(*types.Interface).Complete(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MethodScope returns a new MethodScope.
|
||||||
|
func (r *Registry) MethodScope() *MethodScope {
|
||||||
|
return &MethodScope{
|
||||||
|
registry: r,
|
||||||
|
moqPkgPath: r.moqPkgPath,
|
||||||
|
conflicted: map[string]bool{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddImport adds the given package to the set of imports. It generates a
|
||||||
|
// suitable alias if there are any conflicts with previously imported
|
||||||
|
// packages.
|
||||||
|
func (r *Registry) AddImport(pkg *types.Package) *Package {
|
||||||
|
path := stripVendorPath(pkg.Path())
|
||||||
|
if path == r.moqPkgPath {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if imprt, ok := r.imports[path]; ok {
|
||||||
|
return imprt
|
||||||
|
}
|
||||||
|
|
||||||
|
imprt := Package{pkg: pkg, Alias: r.aliases[path]}
|
||||||
|
|
||||||
|
if conflict, ok := r.searchImport(imprt.Qualifier()); ok {
|
||||||
|
resolveImportConflict(&imprt, conflict, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.imports[path] = &imprt
|
||||||
|
return &imprt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imports returns the list of imported packages. The list is sorted by
|
||||||
|
// path.
|
||||||
|
func (r Registry) Imports() []*Package {
|
||||||
|
imports := make([]*Package, 0, len(r.imports))
|
||||||
|
for _, imprt := range r.imports {
|
||||||
|
imports = append(imports, imprt)
|
||||||
|
}
|
||||||
|
sort.Slice(imports, func(i, j int) bool {
|
||||||
|
return imports[i].Path() < imports[j].Path()
|
||||||
|
})
|
||||||
|
return imports
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Registry) searchImport(name string) (*Package, bool) {
|
||||||
|
for _, imprt := range r.imports {
|
||||||
|
if imprt.Qualifier() == name {
|
||||||
|
return imprt, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func pkgInfoFromPath(srcDir string, mode packages.LoadMode) (*packages.Package, error) {
|
||||||
|
pkgs, err := packages.Load(&packages.Config{
|
||||||
|
Mode: mode,
|
||||||
|
Dir: srcDir,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(pkgs) == 0 {
|
||||||
|
return nil, errors.New("package not found")
|
||||||
|
}
|
||||||
|
if len(pkgs) > 1 {
|
||||||
|
return nil, errors.New("found more than one package")
|
||||||
|
}
|
||||||
|
if errs := pkgs[0].Errors; len(errs) != 0 {
|
||||||
|
if len(errs) == 1 {
|
||||||
|
return nil, errs[0]
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("%s (and %d more errors)", errs[0], len(errs)-1)
|
||||||
|
}
|
||||||
|
return pkgs[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findPkgPath(pkgInputVal string, srcPkg *packages.Package) string {
|
||||||
|
if pkgInputVal == "" {
|
||||||
|
return srcPkg.PkgPath
|
||||||
|
}
|
||||||
|
if pkgInDir(srcPkg.PkgPath, pkgInputVal) {
|
||||||
|
return srcPkg.PkgPath
|
||||||
|
}
|
||||||
|
subdirectoryPath := filepath.Join(srcPkg.PkgPath, pkgInputVal)
|
||||||
|
if pkgInDir(subdirectoryPath, pkgInputVal) {
|
||||||
|
return subdirectoryPath
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func pkgInDir(pkgName, dir string) bool {
|
||||||
|
currentPkg, err := pkgInfoFromPath(dir, packages.NeedName)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return currentPkg.Name == pkgName || currentPkg.Name+"_test" == pkgName
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseImportsAliases(pkg *packages.Package) map[string]string {
|
||||||
|
aliases := make(map[string]string)
|
||||||
|
for _, syntax := range pkg.Syntax {
|
||||||
|
for _, imprt := range syntax.Imports {
|
||||||
|
if imprt.Name != nil && imprt.Name.Name != "." && imprt.Name.Name != "_" {
|
||||||
|
aliases[strings.Trim(imprt.Path.Value, `"`)] = imprt.Name.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveImportConflict generates and assigns a unique alias for
|
||||||
|
// packages with conflicting qualifiers.
|
||||||
|
func resolveImportConflict(a, b *Package, lvl int) {
|
||||||
|
u1, u2 := a.uniqueName(lvl), b.uniqueName(lvl)
|
||||||
|
if u1 != u2 {
|
||||||
|
a.Alias, b.Alias = u1, u2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveImportConflict(a, b, lvl+1)
|
||||||
|
}
|
||||||
141
vendor/github.com/matryer/moq/internal/registry/var.go
generated
vendored
Normal file
141
vendor/github.com/matryer/moq/internal/registry/var.go
generated
vendored
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
package registry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/types"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Var represents a method variable/parameter.
|
||||||
|
//
|
||||||
|
// It should be created using a method scope instance.
|
||||||
|
type Var struct {
|
||||||
|
vr *types.Var
|
||||||
|
imports map[string]*Package
|
||||||
|
moqPkgPath string
|
||||||
|
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSlice returns whether the type (or the underlying type) is a slice.
|
||||||
|
func (v Var) IsSlice() bool {
|
||||||
|
_, ok := v.vr.Type().Underlying().(*types.Slice)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeString returns the variable type with the package qualifier in the
|
||||||
|
// format 'pkg.Type'.
|
||||||
|
func (v Var) TypeString() string {
|
||||||
|
return types.TypeString(v.vr.Type(), v.packageQualifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
// packageQualifier is a types.Qualifier.
|
||||||
|
func (v Var) packageQualifier(pkg *types.Package) string {
|
||||||
|
path := stripVendorPath(pkg.Path())
|
||||||
|
if v.moqPkgPath != "" && v.moqPkgPath == path {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.imports[path].Qualifier()
|
||||||
|
}
|
||||||
|
|
||||||
|
func varName(vr *types.Var, suffix string) string {
|
||||||
|
name := vr.Name()
|
||||||
|
if name != "" && name != "_" {
|
||||||
|
return name + suffix
|
||||||
|
}
|
||||||
|
|
||||||
|
name = varNameForType(vr.Type()) + suffix
|
||||||
|
|
||||||
|
switch name {
|
||||||
|
case "mock", "callInfo", "break", "default", "func", "interface", "select", "case", "defer", "go", "map", "struct",
|
||||||
|
"chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", "continue", "for",
|
||||||
|
"import", "return", "var":
|
||||||
|
name += "MoqParam"
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
// varNameForType generates a name for the variable using the type
|
||||||
|
// information.
|
||||||
|
//
|
||||||
|
// Examples:
|
||||||
|
// - string -> s
|
||||||
|
// - int -> n
|
||||||
|
// - chan int -> intCh
|
||||||
|
// - []a.MyType -> myTypes
|
||||||
|
// - map[string]int -> stringToInt
|
||||||
|
// - error -> err
|
||||||
|
// - a.MyType -> myType
|
||||||
|
func varNameForType(t types.Type) string {
|
||||||
|
nestedType := func(t types.Type) string {
|
||||||
|
if t, ok := t.(*types.Basic); ok {
|
||||||
|
return deCapitalise(t.String())
|
||||||
|
}
|
||||||
|
return varNameForType(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t := t.(type) {
|
||||||
|
case *types.Named:
|
||||||
|
if t.Obj().Name() == "error" {
|
||||||
|
return "err"
|
||||||
|
}
|
||||||
|
|
||||||
|
name := deCapitalise(t.Obj().Name())
|
||||||
|
if name == t.Obj().Name() {
|
||||||
|
name += "MoqParam"
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
|
case *types.Basic:
|
||||||
|
return basicTypeVarName(t)
|
||||||
|
|
||||||
|
case *types.Array:
|
||||||
|
return nestedType(t.Elem()) + "s"
|
||||||
|
|
||||||
|
case *types.Slice:
|
||||||
|
return nestedType(t.Elem()) + "s"
|
||||||
|
|
||||||
|
case *types.Struct: // anonymous struct
|
||||||
|
return "val"
|
||||||
|
|
||||||
|
case *types.Pointer:
|
||||||
|
return varNameForType(t.Elem())
|
||||||
|
|
||||||
|
case *types.Signature:
|
||||||
|
return "fn"
|
||||||
|
|
||||||
|
case *types.Interface: // anonymous interface
|
||||||
|
return "ifaceVal"
|
||||||
|
|
||||||
|
case *types.Map:
|
||||||
|
return nestedType(t.Key()) + "To" + capitalise(nestedType(t.Elem()))
|
||||||
|
|
||||||
|
case *types.Chan:
|
||||||
|
return nestedType(t.Elem()) + "Ch"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "v"
|
||||||
|
}
|
||||||
|
|
||||||
|
func basicTypeVarName(b *types.Basic) string {
|
||||||
|
switch b.Info() {
|
||||||
|
case types.IsBoolean:
|
||||||
|
return "b"
|
||||||
|
|
||||||
|
case types.IsInteger:
|
||||||
|
return "n"
|
||||||
|
|
||||||
|
case types.IsFloat:
|
||||||
|
return "f"
|
||||||
|
|
||||||
|
case types.IsString:
|
||||||
|
return "s"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "v"
|
||||||
|
}
|
||||||
|
|
||||||
|
func capitalise(s string) string { return strings.ToUpper(s[:1]) + s[1:] }
|
||||||
|
func deCapitalise(s string) string { return strings.ToLower(s[:1]) + s[1:] }
|
||||||
190
vendor/github.com/matryer/moq/internal/template/template.go
generated
vendored
Normal file
190
vendor/github.com/matryer/moq/internal/template/template.go
generated
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
package template
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/matryer/moq/internal/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Template is the Moq template. It is capable of generating the Moq
|
||||||
|
// implementation for the given template.Data.
|
||||||
|
type Template struct {
|
||||||
|
tmpl *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
// New returns a new instance of Template.
|
||||||
|
func New() (Template, error) {
|
||||||
|
tmpl, err := template.New("moq").Funcs(templateFuncs).Parse(moqTemplate)
|
||||||
|
if err != nil {
|
||||||
|
return Template{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return Template{tmpl: tmpl}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute generates and writes the Moq implementation for the given
|
||||||
|
// data.
|
||||||
|
func (t Template) Execute(w io.Writer, data Data) error {
|
||||||
|
return t.tmpl.Execute(w, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// moqTemplate is the template for mocked code.
|
||||||
|
// language=GoTemplate
|
||||||
|
var moqTemplate = `// Code generated by moq; DO NOT EDIT.
|
||||||
|
// github.com/matryer/moq
|
||||||
|
|
||||||
|
package {{.PkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
{{- range .Imports}}
|
||||||
|
{{. | ImportStatement}}
|
||||||
|
{{- end}}
|
||||||
|
)
|
||||||
|
|
||||||
|
{{range $i, $mock := .Mocks -}}
|
||||||
|
|
||||||
|
{{- if not $.SkipEnsure -}}
|
||||||
|
// Ensure, that {{.MockName}} does implement {{$.SrcPkgQualifier}}{{.InterfaceName}}.
|
||||||
|
// If this is not the case, regenerate this file with moq.
|
||||||
|
var _ {{$.SrcPkgQualifier}}{{.InterfaceName}} = &{{.MockName}}{}
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
|
// {{.MockName}} is a mock implementation of {{$.SrcPkgQualifier}}{{.InterfaceName}}.
|
||||||
|
//
|
||||||
|
// func TestSomethingThatUses{{.InterfaceName}}(t *testing.T) {
|
||||||
|
//
|
||||||
|
// // make and configure a mocked {{$.SrcPkgQualifier}}{{.InterfaceName}}
|
||||||
|
// mocked{{.InterfaceName}} := &{{.MockName}}{
|
||||||
|
{{- range .Methods}}
|
||||||
|
// {{.Name}}Func: func({{.ArgList}}) {{.ReturnArgTypeList}} {
|
||||||
|
// panic("mock out the {{.Name}} method")
|
||||||
|
// },
|
||||||
|
{{- end}}
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // use mocked{{.InterfaceName}} in code that requires {{$.SrcPkgQualifier}}{{.InterfaceName}}
|
||||||
|
// // and then make assertions.
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
type {{.MockName}} struct {
|
||||||
|
{{- range .Methods}}
|
||||||
|
// {{.Name}}Func mocks the {{.Name}} method.
|
||||||
|
{{.Name}}Func func({{.ArgList}}) {{.ReturnArgTypeList}}
|
||||||
|
{{end}}
|
||||||
|
// calls tracks calls to the methods.
|
||||||
|
calls struct {
|
||||||
|
{{- range .Methods}}
|
||||||
|
// {{.Name}} holds details about calls to the {{.Name}} method.
|
||||||
|
{{.Name}} []struct {
|
||||||
|
{{- range .Params}}
|
||||||
|
// {{.Name | Exported}} is the {{.Name}} argument value.
|
||||||
|
{{.Name | Exported}} {{.TypeString}}
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
{{- range .Methods}}
|
||||||
|
lock{{.Name}} {{$.Imports | SyncPkgQualifier}}.RWMutex
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
{{range .Methods}}
|
||||||
|
// {{.Name}} calls {{.Name}}Func.
|
||||||
|
func (mock *{{$mock.MockName}}) {{.Name}}({{.ArgList}}) {{.ReturnArgTypeList}} {
|
||||||
|
{{- if not $.StubImpl}}
|
||||||
|
if mock.{{.Name}}Func == nil {
|
||||||
|
panic("{{$mock.MockName}}.{{.Name}}Func: method is nil but {{$mock.InterfaceName}}.{{.Name}} was just called")
|
||||||
|
}
|
||||||
|
{{- end}}
|
||||||
|
callInfo := struct {
|
||||||
|
{{- range .Params}}
|
||||||
|
{{.Name | Exported}} {{.TypeString}}
|
||||||
|
{{- end}}
|
||||||
|
}{
|
||||||
|
{{- range .Params}}
|
||||||
|
{{.Name | Exported}}: {{.Name}},
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
mock.lock{{.Name}}.Lock()
|
||||||
|
mock.calls.{{.Name}} = append(mock.calls.{{.Name}}, callInfo)
|
||||||
|
mock.lock{{.Name}}.Unlock()
|
||||||
|
{{- if .Returns}}
|
||||||
|
{{- if $.StubImpl}}
|
||||||
|
if mock.{{.Name}}Func == nil {
|
||||||
|
var (
|
||||||
|
{{- range .Returns}}
|
||||||
|
{{.Name}} {{.TypeString}}
|
||||||
|
{{- end}}
|
||||||
|
)
|
||||||
|
return {{.ReturnArgNameList}}
|
||||||
|
}
|
||||||
|
{{- end}}
|
||||||
|
return mock.{{.Name}}Func({{.ArgCallList}})
|
||||||
|
{{- else}}
|
||||||
|
{{- if $.StubImpl}}
|
||||||
|
if mock.{{.Name}}Func == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
{{- end}}
|
||||||
|
mock.{{.Name}}Func({{.ArgCallList}})
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// {{.Name}}Calls gets all the calls that were made to {{.Name}}.
|
||||||
|
// Check the length with:
|
||||||
|
// len(mocked{{$mock.InterfaceName}}.{{.Name}}Calls())
|
||||||
|
func (mock *{{$mock.MockName}}) {{.Name}}Calls() []struct {
|
||||||
|
{{- range .Params}}
|
||||||
|
{{.Name | Exported}} {{.TypeString}}
|
||||||
|
{{- end}}
|
||||||
|
} {
|
||||||
|
var calls []struct {
|
||||||
|
{{- range .Params}}
|
||||||
|
{{.Name | Exported}} {{.TypeString}}
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
mock.lock{{.Name}}.RLock()
|
||||||
|
calls = mock.calls.{{.Name}}
|
||||||
|
mock.lock{{.Name}}.RUnlock()
|
||||||
|
return calls
|
||||||
|
}
|
||||||
|
{{end -}}
|
||||||
|
{{end -}}`
|
||||||
|
|
||||||
|
// This list comes from the golint codebase. Golint will complain about any of
|
||||||
|
// these being mixed-case, like "Id" instead of "ID".
|
||||||
|
var golintInitialisms = []string{
|
||||||
|
"ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "LHS",
|
||||||
|
"QPS", "RAM", "RHS", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "UID", "UUID", "URI",
|
||||||
|
"URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS",
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateFuncs = template.FuncMap{
|
||||||
|
"ImportStatement": func(imprt *registry.Package) string {
|
||||||
|
if imprt.Alias == "" {
|
||||||
|
return `"` + imprt.Path() + `"`
|
||||||
|
}
|
||||||
|
return imprt.Alias + ` "` + imprt.Path() + `"`
|
||||||
|
},
|
||||||
|
"SyncPkgQualifier": func(imports []*registry.Package) string {
|
||||||
|
for _, imprt := range imports {
|
||||||
|
if imprt.Path() == "sync" {
|
||||||
|
return imprt.Qualifier()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "sync"
|
||||||
|
},
|
||||||
|
"Exported": func(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
for _, initialism := range golintInitialisms {
|
||||||
|
if strings.ToUpper(s) == initialism {
|
||||||
|
return initialism
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.ToUpper(s[0:1]) + s[1:]
|
||||||
|
},
|
||||||
|
}
|
||||||
125
vendor/github.com/matryer/moq/internal/template/template_data.go
generated
vendored
Normal file
125
vendor/github.com/matryer/moq/internal/template/template_data.go
generated
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
package template
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/matryer/moq/internal/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Data is the template data used to render the Moq template.
|
||||||
|
type Data struct {
|
||||||
|
PkgName string
|
||||||
|
SrcPkgQualifier string
|
||||||
|
Imports []*registry.Package
|
||||||
|
Mocks []MockData
|
||||||
|
StubImpl bool
|
||||||
|
SkipEnsure bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MocksSomeMethod returns true of any one of the Mocks has at least 1
|
||||||
|
// method.
|
||||||
|
func (d Data) MocksSomeMethod() bool {
|
||||||
|
for _, m := range d.Mocks {
|
||||||
|
if len(m.Methods) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockData is the data used to generate a mock for some interface.
|
||||||
|
type MockData struct {
|
||||||
|
InterfaceName string
|
||||||
|
MockName string
|
||||||
|
Methods []MethodData
|
||||||
|
}
|
||||||
|
|
||||||
|
// MethodData is the data which represents a method on some interface.
|
||||||
|
type MethodData struct {
|
||||||
|
Name string
|
||||||
|
Params []ParamData
|
||||||
|
Returns []ParamData
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArgList is the string representation of method parameters, ex:
|
||||||
|
// 's string, n int, foo bar.Baz'.
|
||||||
|
func (m MethodData) ArgList() string {
|
||||||
|
params := make([]string, len(m.Params))
|
||||||
|
for i, p := range m.Params {
|
||||||
|
params[i] = p.MethodArg()
|
||||||
|
}
|
||||||
|
return strings.Join(params, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArgCallList is the string representation of method call parameters,
|
||||||
|
// ex: 's, n, foo'. In case of a last variadic parameter, it will be of
|
||||||
|
// the format 's, n, foos...'
|
||||||
|
func (m MethodData) ArgCallList() string {
|
||||||
|
params := make([]string, len(m.Params))
|
||||||
|
for i, p := range m.Params {
|
||||||
|
params[i] = p.CallName()
|
||||||
|
}
|
||||||
|
return strings.Join(params, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReturnArgTypeList is the string representation of method return
|
||||||
|
// types, ex: 'bar.Baz', '(string, error)'.
|
||||||
|
func (m MethodData) ReturnArgTypeList() string {
|
||||||
|
params := make([]string, len(m.Returns))
|
||||||
|
for i, p := range m.Returns {
|
||||||
|
params[i] = p.TypeString()
|
||||||
|
}
|
||||||
|
if len(m.Returns) > 1 {
|
||||||
|
return fmt.Sprintf("(%s)", strings.Join(params, ", "))
|
||||||
|
}
|
||||||
|
return strings.Join(params, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReturnArgNameList is the string representation of values being
|
||||||
|
// returned from the method, ex: 'foo', 's, err'.
|
||||||
|
func (m MethodData) ReturnArgNameList() string {
|
||||||
|
params := make([]string, len(m.Returns))
|
||||||
|
for i, p := range m.Returns {
|
||||||
|
params[i] = p.Name()
|
||||||
|
}
|
||||||
|
return strings.Join(params, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamData is the data which represents a parameter to some method of
|
||||||
|
// an interface.
|
||||||
|
type ParamData struct {
|
||||||
|
Var *registry.Var
|
||||||
|
Variadic bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the parameter.
|
||||||
|
func (p ParamData) Name() string {
|
||||||
|
return p.Var.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// MethodArg is the representation of the parameter in the function
|
||||||
|
// signature, ex: 'name a.Type'.
|
||||||
|
func (p ParamData) MethodArg() string {
|
||||||
|
if p.Variadic {
|
||||||
|
return fmt.Sprintf("%s ...%s", p.Name(), p.TypeString()[2:])
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s %s", p.Name(), p.TypeString())
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallName returns the string representation of the parameter to be
|
||||||
|
// used for a method call. For a variadic paramter, it will be of the
|
||||||
|
// format 'foos...'.
|
||||||
|
func (p ParamData) CallName() string {
|
||||||
|
if p.Variadic {
|
||||||
|
return p.Name() + "..."
|
||||||
|
}
|
||||||
|
return p.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeString returns the string representation of the type of the
|
||||||
|
// parameter.
|
||||||
|
func (p ParamData) TypeString() string {
|
||||||
|
return p.Var.TypeString()
|
||||||
|
}
|
||||||
109
vendor/github.com/matryer/moq/main.go
generated
vendored
Normal file
109
vendor/github.com/matryer/moq/main.go
generated
vendored
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/matryer/moq/pkg/moq"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Version is the command version, injected at build time.
|
||||||
|
var Version string = "dev"
|
||||||
|
|
||||||
|
type userFlags struct {
|
||||||
|
outFile string
|
||||||
|
pkgName string
|
||||||
|
formatter string
|
||||||
|
stubImpl bool
|
||||||
|
skipEnsure bool
|
||||||
|
remove bool
|
||||||
|
args []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var flags userFlags
|
||||||
|
flag.StringVar(&flags.outFile, "out", "", "output file (default stdout)")
|
||||||
|
flag.StringVar(&flags.pkgName, "pkg", "", "package name (default will infer)")
|
||||||
|
flag.StringVar(&flags.formatter, "fmt", "", "go pretty-printer: gofmt, goimports or noop (default gofmt)")
|
||||||
|
flag.BoolVar(&flags.stubImpl, "stub", false,
|
||||||
|
"return zero values when no mock implementation is provided, do not panic")
|
||||||
|
printVersion := flag.Bool("version", false, "show the version for moq")
|
||||||
|
flag.BoolVar(&flags.skipEnsure, "skip-ensure", false,
|
||||||
|
"suppress mock implementation check, avoid import cycle if mocks generated outside of the tested package")
|
||||||
|
flag.BoolVar(&flags.remove, "rm", false, "first remove output file, if it exists")
|
||||||
|
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`)
|
||||||
|
flag.PrintDefaults()
|
||||||
|
fmt.Println(`Specifying an alias for the mock is also supported with the format 'interface:alias'`)
|
||||||
|
fmt.Println(`Ex: moq -pkg different . MyInterface:MyMock`)
|
||||||
|
}
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
flags.args = flag.Args()
|
||||||
|
|
||||||
|
if *printVersion {
|
||||||
|
fmt.Printf("moq version %s\n", Version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := run(flags); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(flags userFlags) error {
|
||||||
|
if len(flags.args) < 2 {
|
||||||
|
return errors.New("not enough arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.remove && flags.outFile != "" {
|
||||||
|
if err := os.Remove(flags.outFile); err != nil {
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
var out io.Writer = os.Stdout
|
||||||
|
if flags.outFile != "" {
|
||||||
|
out = &buf
|
||||||
|
}
|
||||||
|
|
||||||
|
srcDir, args := flags.args[0], flags.args[1:]
|
||||||
|
m, err := moq.New(moq.Config{
|
||||||
|
SrcDir: srcDir,
|
||||||
|
PkgName: flags.pkgName,
|
||||||
|
Formatter: flags.formatter,
|
||||||
|
StubImpl: flags.stubImpl,
|
||||||
|
SkipEnsure: flags.skipEnsure,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = m.Mock(out, args...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.outFile == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the file
|
||||||
|
err = os.MkdirAll(filepath.Dir(flags.outFile), 0750)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ioutil.WriteFile(flags.outFile, buf.Bytes(), 0600)
|
||||||
|
}
|
||||||
BIN
vendor/github.com/matryer/moq/moq-logo-small.png
generated
vendored
Normal file
BIN
vendor/github.com/matryer/moq/moq-logo-small.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
BIN
vendor/github.com/matryer/moq/moq-logo.png
generated
vendored
Normal file
BIN
vendor/github.com/matryer/moq/moq-logo.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
31
vendor/github.com/matryer/moq/pkg/moq/formatter.go
generated
vendored
Normal file
31
vendor/github.com/matryer/moq/pkg/moq/formatter.go
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package moq
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go/format"
|
||||||
|
|
||||||
|
"golang.org/x/tools/imports"
|
||||||
|
)
|
||||||
|
|
||||||
|
func goimports(src []byte) ([]byte, error) {
|
||||||
|
formatted, err := imports.Process("filename", src, &imports.Options{
|
||||||
|
TabWidth: 8,
|
||||||
|
TabIndent: true,
|
||||||
|
Comments: true,
|
||||||
|
Fragment: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("goimports: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func gofmt(src []byte) ([]byte, error) {
|
||||||
|
formatted, err := format.Source(src)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("go/format: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted, nil
|
||||||
|
}
|
||||||
171
vendor/github.com/matryer/moq/pkg/moq/moq.go
generated
vendored
Normal file
171
vendor/github.com/matryer/moq/pkg/moq/moq.go
generated
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
package moq
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"go/types"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/matryer/moq/internal/registry"
|
||||||
|
"github.com/matryer/moq/internal/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Mocker can generate mock structs.
|
||||||
|
type Mocker struct {
|
||||||
|
cfg Config
|
||||||
|
|
||||||
|
registry *registry.Registry
|
||||||
|
tmpl template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config specifies details about how interfaces should be mocked.
|
||||||
|
// SrcDir is the only field which needs be specified.
|
||||||
|
type Config struct {
|
||||||
|
SrcDir string
|
||||||
|
PkgName string
|
||||||
|
Formatter string
|
||||||
|
StubImpl bool
|
||||||
|
SkipEnsure bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// New makes a new Mocker for the specified package directory.
|
||||||
|
func New(cfg Config) (*Mocker, error) {
|
||||||
|
reg, err := registry.New(cfg.SrcDir, cfg.PkgName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.New()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Mocker{
|
||||||
|
cfg: cfg,
|
||||||
|
registry: reg,
|
||||||
|
tmpl: tmpl,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock generates a mock for the specified interface name.
|
||||||
|
func (m *Mocker) Mock(w io.Writer, namePairs ...string) error {
|
||||||
|
if len(namePairs) == 0 {
|
||||||
|
return errors.New("must specify one interface")
|
||||||
|
}
|
||||||
|
|
||||||
|
mocks := make([]template.MockData, len(namePairs))
|
||||||
|
for i, np := range namePairs {
|
||||||
|
name, mockName := parseInterfaceName(np)
|
||||||
|
iface, err := m.registry.LookupInterface(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
methods := make([]template.MethodData, iface.NumMethods())
|
||||||
|
for j := 0; j < iface.NumMethods(); j++ {
|
||||||
|
methods[j] = m.methodData(iface.Method(j))
|
||||||
|
}
|
||||||
|
|
||||||
|
mocks[i] = template.MockData{
|
||||||
|
InterfaceName: name,
|
||||||
|
MockName: mockName,
|
||||||
|
Methods: methods,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data := template.Data{
|
||||||
|
PkgName: m.mockPkgName(),
|
||||||
|
Mocks: mocks,
|
||||||
|
StubImpl: m.cfg.StubImpl,
|
||||||
|
SkipEnsure: m.cfg.SkipEnsure,
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.MocksSomeMethod() {
|
||||||
|
m.registry.AddImport(types.NewPackage("sync", "sync"))
|
||||||
|
}
|
||||||
|
if m.registry.SrcPkgName() != m.mockPkgName() {
|
||||||
|
data.SrcPkgQualifier = m.registry.SrcPkgName() + "."
|
||||||
|
if !m.cfg.SkipEnsure {
|
||||||
|
imprt := m.registry.AddImport(m.registry.SrcPkg())
|
||||||
|
data.SrcPkgQualifier = imprt.Qualifier() + "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Imports = m.registry.Imports()
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := m.tmpl.Execute(&buf, data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
formatted, err := m.format(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := w.Write(formatted); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mocker) methodData(f *types.Func) template.MethodData {
|
||||||
|
sig := f.Type().(*types.Signature)
|
||||||
|
|
||||||
|
scope := m.registry.MethodScope()
|
||||||
|
n := sig.Params().Len()
|
||||||
|
params := make([]template.ParamData, n)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
p := template.ParamData{
|
||||||
|
Var: scope.AddVar(sig.Params().At(i), ""),
|
||||||
|
}
|
||||||
|
p.Variadic = sig.Variadic() && i == n-1 && p.Var.IsSlice() // check for final variadic argument
|
||||||
|
|
||||||
|
params[i] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
n = sig.Results().Len()
|
||||||
|
results := make([]template.ParamData, n)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
results[i] = template.ParamData{
|
||||||
|
Var: scope.AddVar(sig.Results().At(i), "Out"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return template.MethodData{
|
||||||
|
Name: f.Name(),
|
||||||
|
Params: params,
|
||||||
|
Returns: results,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mocker) mockPkgName() string {
|
||||||
|
if m.cfg.PkgName != "" {
|
||||||
|
return m.cfg.PkgName
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.registry.SrcPkgName()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mocker) format(src []byte) ([]byte, error) {
|
||||||
|
switch m.cfg.Formatter {
|
||||||
|
case "goimports":
|
||||||
|
return goimports(src)
|
||||||
|
|
||||||
|
case "noop":
|
||||||
|
return src, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return gofmt(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseInterfaceName(namePair string) (ifaceName, mockName string) {
|
||||||
|
parts := strings.SplitN(namePair, ":", 2)
|
||||||
|
if len(parts) == 2 {
|
||||||
|
return parts[0], parts[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
ifaceName = parts[0]
|
||||||
|
return ifaceName, ifaceName + "Mock"
|
||||||
|
}
|
||||||
BIN
vendor/github.com/matryer/moq/preview.png
generated
vendored
Normal file
BIN
vendor/github.com/matryer/moq/preview.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 726 KiB |
28
vendor/github.com/matryer/moq/releasing.md
generated
vendored
Normal file
28
vendor/github.com/matryer/moq/releasing.md
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Releasing
|
||||||
|
|
||||||
|
This tool uses Go Releaser to manage release builds.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Install Go Releaser.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install goreleaser/tap/goreleaser
|
||||||
|
```
|
||||||
|
|
||||||
|
* Make a [New personal access token on GitHub](https://github.com/settings/tokens/new) and set it as the `GITHUB_TOKEN` environment variable
|
||||||
|
|
||||||
|
## Releasing
|
||||||
|
|
||||||
|
Tag the repo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git tag -a v0.1.0 -m "release tag."
|
||||||
|
$ git push origin v0.1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
Then:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GITHUB_TOKEN=xxx goreleaser --rm-dist
|
||||||
|
```
|
||||||
216
vendor/github.com/vektah/gqlparser/v2/ast/decode.go
generated
vendored
216
vendor/github.com/vektah/gqlparser/v2/ast/decode.go
generated
vendored
|
|
@ -1,216 +0,0 @@
|
||||||
package ast
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
func UnmarshalSelectionSet(b []byte) (SelectionSet, error) {
|
|
||||||
var tmp []json.RawMessage
|
|
||||||
|
|
||||||
if err := json.Unmarshal(b, &tmp); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = make([]Selection, 0)
|
|
||||||
for _, item := range tmp {
|
|
||||||
var field Field
|
|
||||||
if err := json.Unmarshal(item, &field); err == nil {
|
|
||||||
result = append(result, &field)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var fragmentSpread FragmentSpread
|
|
||||||
if err := json.Unmarshal(item, &fragmentSpread); err == nil {
|
|
||||||
result = append(result, &fragmentSpread)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var inlineFragment InlineFragment
|
|
||||||
if err := json.Unmarshal(item, &inlineFragment); err == nil {
|
|
||||||
result = append(result, &inlineFragment)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FragmentDefinition) UnmarshalJSON(b []byte) error {
|
|
||||||
var tmp map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(b, &tmp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k := range tmp {
|
|
||||||
switch k {
|
|
||||||
case "Name":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "VariableDefinition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.VariableDefinition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "TypeCondition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.TypeCondition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Directives":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Directives)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SelectionSet":
|
|
||||||
ss, err := UnmarshalSelectionSet(tmp[k])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.SelectionSet = ss
|
|
||||||
case "Definition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Definition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Position":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Position)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *InlineFragment) UnmarshalJSON(b []byte) error {
|
|
||||||
var tmp map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(b, &tmp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k := range tmp {
|
|
||||||
switch k {
|
|
||||||
case "TypeCondition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.TypeCondition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Directives":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Directives)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SelectionSet":
|
|
||||||
ss, err := UnmarshalSelectionSet(tmp[k])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.SelectionSet = ss
|
|
||||||
case "ObjectDefinition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.ObjectDefinition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Position":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Position)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *OperationDefinition) UnmarshalJSON(b []byte) error {
|
|
||||||
var tmp map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(b, &tmp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k := range tmp {
|
|
||||||
switch k {
|
|
||||||
case "Operation":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Operation)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Name":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "VariableDefinitions":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.VariableDefinitions)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Directives":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Directives)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SelectionSet":
|
|
||||||
ss, err := UnmarshalSelectionSet(tmp[k])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.SelectionSet = ss
|
|
||||||
case "Position":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Position)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Field) UnmarshalJSON(b []byte) error {
|
|
||||||
var tmp map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(b, &tmp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k := range tmp {
|
|
||||||
switch k {
|
|
||||||
case "Alias":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Alias)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Name":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Arguments":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Arguments)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Directives":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Directives)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SelectionSet":
|
|
||||||
ss, err := UnmarshalSelectionSet(tmp[k])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.SelectionSet = ss
|
|
||||||
case "Position":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Position)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "Definition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.Definition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "ObjectDefinition":
|
|
||||||
err := json.Unmarshal(tmp[k], &f.ObjectDefinition)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
4
vendor/github.com/vektah/gqlparser/v2/formatter/formatter.go
generated
vendored
4
vendor/github.com/vektah/gqlparser/v2/formatter/formatter.go
generated
vendored
|
|
@ -299,9 +299,7 @@ func (f *formatter) FormatArgumentDefinitionList(lists ast.ArgumentDefinitionLis
|
||||||
for idx, arg := range lists {
|
for idx, arg := range lists {
|
||||||
f.FormatArgumentDefinition(arg)
|
f.FormatArgumentDefinition(arg)
|
||||||
|
|
||||||
// Skip emitting (insignificant) comma in case it is the
|
if idx != len(lists)-1 {
|
||||||
// last argument, or we printed a new line in its definition.
|
|
||||||
if idx != len(lists)-1 && arg.Description == "" {
|
|
||||||
f.NoPadding().WriteWord(",")
|
f.NoPadding().WriteWord(",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
vendor/github.com/vektah/gqlparser/v2/gqlparser.go
generated
vendored
5
vendor/github.com/vektah/gqlparser/v2/gqlparser.go
generated
vendored
|
|
@ -8,7 +8,7 @@ import (
|
||||||
_ "github.com/vektah/gqlparser/v2/validator/rules"
|
_ "github.com/vektah/gqlparser/v2/validator/rules"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadSchema(str ...*ast.Source) (*ast.Schema, error) {
|
func LoadSchema(str ...*ast.Source) (*ast.Schema, *gqlerror.Error) {
|
||||||
return validator.LoadSchema(append([]*ast.Source{validator.Prelude}, str...)...)
|
return validator.LoadSchema(append([]*ast.Source{validator.Prelude}, str...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,8 +23,7 @@ func MustLoadSchema(str ...*ast.Source) *ast.Schema {
|
||||||
func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.List) {
|
func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.List) {
|
||||||
query, err := parser.ParseQuery(&ast.Source{Input: str})
|
query, err := parser.ParseQuery(&ast.Source{Input: str})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gqlErr := err.(*gqlerror.Error)
|
return nil, gqlerror.List{err}
|
||||||
return nil, gqlerror.List{gqlErr}
|
|
||||||
}
|
}
|
||||||
errs := validator.Validate(schema, query)
|
errs := validator.Validate(schema, query)
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
|
|
|
||||||
25
vendor/github.com/vektah/gqlparser/v2/lexer/lexer.go
generated
vendored
25
vendor/github.com/vektah/gqlparser/v2/lexer/lexer.go
generated
vendored
|
|
@ -37,11 +37,11 @@ func (s *Lexer) peek() (rune, int) {
|
||||||
return utf8.DecodeRuneInString(s.Input[s.end:])
|
return utf8.DecodeRuneInString(s.Input[s.end:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Lexer) makeToken(kind Type) (Token, error) {
|
func (s *Lexer) makeToken(kind Type) (Token, *gqlerror.Error) {
|
||||||
return s.makeValueToken(kind, s.Input[s.start:s.end])
|
return s.makeValueToken(kind, s.Input[s.start:s.end])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Lexer) makeValueToken(kind Type, value string) (Token, error) {
|
func (s *Lexer) makeValueToken(kind Type, value string) (Token, *gqlerror.Error) {
|
||||||
return Token{
|
return Token{
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
Value: value,
|
Value: value,
|
||||||
|
|
@ -55,7 +55,7 @@ func (s *Lexer) makeValueToken(kind Type, value string) (Token, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Lexer) makeError(format string, args ...interface{}) (Token, error) {
|
func (s *Lexer) makeError(format string, args ...interface{}) (Token, *gqlerror.Error) {
|
||||||
column := s.endRunes - s.lineStartRunes + 1
|
column := s.endRunes - s.lineStartRunes + 1
|
||||||
return Token{
|
return Token{
|
||||||
Kind: Invalid,
|
Kind: Invalid,
|
||||||
|
|
@ -74,7 +74,7 @@ func (s *Lexer) makeError(format string, args ...interface{}) (Token, error) {
|
||||||
// This skips over whitespace and comments until it finds the next lexable
|
// This skips over whitespace and comments until it finds the next lexable
|
||||||
// token, then lexes punctuators immediately or calls the appropriate helper
|
// token, then lexes punctuators immediately or calls the appropriate helper
|
||||||
// function for more complicated tokens.
|
// function for more complicated tokens.
|
||||||
func (s *Lexer) ReadToken() (token Token, err error) {
|
func (s *Lexer) ReadToken() (token Token, err *gqlerror.Error) {
|
||||||
|
|
||||||
s.ws()
|
s.ws()
|
||||||
s.start = s.end
|
s.start = s.end
|
||||||
|
|
@ -192,7 +192,7 @@ func (s *Lexer) ws() {
|
||||||
// readComment from the input
|
// readComment from the input
|
||||||
//
|
//
|
||||||
// #[\u0009\u0020-\uFFFF]*
|
// #[\u0009\u0020-\uFFFF]*
|
||||||
func (s *Lexer) readComment() (Token, error) {
|
func (s *Lexer) readComment() (Token, *gqlerror.Error) {
|
||||||
for s.end < len(s.Input) {
|
for s.end < len(s.Input) {
|
||||||
r, w := s.peek()
|
r, w := s.peek()
|
||||||
|
|
||||||
|
|
@ -213,7 +213,7 @@ func (s *Lexer) readComment() (Token, error) {
|
||||||
//
|
//
|
||||||
// Int: -?(0|[1-9][0-9]*)
|
// Int: -?(0|[1-9][0-9]*)
|
||||||
// Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
// Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
||||||
func (s *Lexer) readNumber() (Token, error) {
|
func (s *Lexer) readNumber() (Token, *gqlerror.Error) {
|
||||||
float := false
|
float := false
|
||||||
|
|
||||||
// backup to the first digit
|
// backup to the first digit
|
||||||
|
|
@ -299,7 +299,7 @@ func (s *Lexer) describeNext() string {
|
||||||
// readString from the input
|
// readString from the input
|
||||||
//
|
//
|
||||||
// "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
// "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
||||||
func (s *Lexer) readString() (Token, error) {
|
func (s *Lexer) readString() (Token, *gqlerror.Error) {
|
||||||
inputLen := len(s.Input)
|
inputLen := len(s.Input)
|
||||||
|
|
||||||
// this buffer is lazily created only if there are escape characters.
|
// this buffer is lazily created only if there are escape characters.
|
||||||
|
|
@ -409,7 +409,7 @@ func (s *Lexer) readString() (Token, error) {
|
||||||
// readBlockString from the input
|
// readBlockString from the input
|
||||||
//
|
//
|
||||||
// """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
|
// """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
|
||||||
func (s *Lexer) readBlockString() (Token, error) {
|
func (s *Lexer) readBlockString() (Token, *gqlerror.Error) {
|
||||||
inputLen := len(s.Input)
|
inputLen := len(s.Input)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
@ -434,6 +434,7 @@ func (s *Lexer) readBlockString() (Token, error) {
|
||||||
// skip the close quote
|
// skip the close quote
|
||||||
s.end += 3
|
s.end += 3
|
||||||
s.endRunes += 3
|
s.endRunes += 3
|
||||||
|
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,8 +456,6 @@ func (s *Lexer) readBlockString() (Token, error) {
|
||||||
buf.WriteByte('\n')
|
buf.WriteByte('\n')
|
||||||
s.end++
|
s.end++
|
||||||
s.endRunes++
|
s.endRunes++
|
||||||
s.line++
|
|
||||||
s.lineStartRunes = s.endRunes
|
|
||||||
} else {
|
} else {
|
||||||
var char = rune(r)
|
var char = rune(r)
|
||||||
var w = 1
|
var w = 1
|
||||||
|
|
@ -468,10 +467,6 @@ func (s *Lexer) readBlockString() (Token, error) {
|
||||||
s.end += w
|
s.end += w
|
||||||
s.endRunes++
|
s.endRunes++
|
||||||
buf.WriteRune(char)
|
buf.WriteRune(char)
|
||||||
if r == '\n' {
|
|
||||||
s.line++
|
|
||||||
s.lineStartRunes = s.endRunes
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -499,7 +494,7 @@ func unhex(b string) (v rune, ok bool) {
|
||||||
// readName from the input
|
// readName from the input
|
||||||
//
|
//
|
||||||
// [_A-Za-z][_0-9A-Za-z]*
|
// [_A-Za-z][_0-9A-Za-z]*
|
||||||
func (s *Lexer) readName() (Token, error) {
|
func (s *Lexer) readName() (Token, *gqlerror.Error) {
|
||||||
for s.end < len(s.Input) {
|
for s.end < len(s.Input) {
|
||||||
r, w := s.peek()
|
r, w := s.peek()
|
||||||
|
|
||||||
|
|
|
||||||
20
vendor/github.com/vektah/gqlparser/v2/lexer/lexer_test.yml
generated
vendored
20
vendor/github.com/vektah/gqlparser/v2/lexer/lexer_test.yml
generated
vendored
|
|
@ -307,26 +307,6 @@ lexes block strings:
|
||||||
end: 36
|
end: 36
|
||||||
value: "spans\n multiple\n lines"
|
value: "spans\n multiple\n lines"
|
||||||
|
|
||||||
- name: records correct line and column after block string
|
|
||||||
input: |
|
|
||||||
"""
|
|
||||||
|
|
||||||
some
|
|
||||||
description
|
|
||||||
|
|
||||||
""" foo
|
|
||||||
tokens:
|
|
||||||
-
|
|
||||||
kind: BLOCK_STRING
|
|
||||||
value: "some\ndescription"
|
|
||||||
-
|
|
||||||
kind: NAME
|
|
||||||
start: 27
|
|
||||||
end: 30
|
|
||||||
line: 6
|
|
||||||
column: 5
|
|
||||||
value: 'foo'
|
|
||||||
|
|
||||||
lex reports useful block string errors:
|
lex reports useful block string errors:
|
||||||
- name: unterminated string
|
- name: unterminated string
|
||||||
input: '"""'
|
input: '"""'
|
||||||
|
|
|
||||||
4
vendor/github.com/vektah/gqlparser/v2/parser/parser.go
generated
vendored
4
vendor/github.com/vektah/gqlparser/v2/parser/parser.go
generated
vendored
|
|
@ -10,11 +10,11 @@ import (
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
lexer lexer.Lexer
|
lexer lexer.Lexer
|
||||||
err error
|
err *gqlerror.Error
|
||||||
|
|
||||||
peeked bool
|
peeked bool
|
||||||
peekToken lexer.Token
|
peekToken lexer.Token
|
||||||
peekError error
|
peekError *gqlerror.Error
|
||||||
|
|
||||||
prev lexer.Token
|
prev lexer.Token
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
vendor/github.com/vektah/gqlparser/v2/parser/query.go
generated
vendored
4
vendor/github.com/vektah/gqlparser/v2/parser/query.go
generated
vendored
|
|
@ -1,12 +1,13 @@
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||||
"github.com/vektah/gqlparser/v2/lexer"
|
"github.com/vektah/gqlparser/v2/lexer"
|
||||||
|
|
||||||
. "github.com/vektah/gqlparser/v2/ast"
|
. "github.com/vektah/gqlparser/v2/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseQuery(source *Source) (*QueryDocument, error) {
|
func ParseQuery(source *Source) (*QueryDocument, *gqlerror.Error) {
|
||||||
p := parser{
|
p := parser{
|
||||||
lexer: lexer.New(source),
|
lexer: lexer.New(source),
|
||||||
}
|
}
|
||||||
|
|
@ -336,6 +337,7 @@ func (p *parser) parseTypeReference() *Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.skip(lexer.Bang) {
|
if p.skip(lexer.Bang) {
|
||||||
|
typ.Position = p.peekPos()
|
||||||
typ.NonNull = true
|
typ.NonNull = true
|
||||||
}
|
}
|
||||||
return &typ
|
return &typ
|
||||||
|
|
|
||||||
5
vendor/github.com/vektah/gqlparser/v2/parser/schema.go
generated
vendored
5
vendor/github.com/vektah/gqlparser/v2/parser/schema.go
generated
vendored
|
|
@ -2,10 +2,11 @@ package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/vektah/gqlparser/v2/ast"
|
. "github.com/vektah/gqlparser/v2/ast"
|
||||||
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||||
"github.com/vektah/gqlparser/v2/lexer"
|
"github.com/vektah/gqlparser/v2/lexer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseSchema(source *Source) (*SchemaDocument, error) {
|
func ParseSchema(source *Source) (*SchemaDocument, *gqlerror.Error) {
|
||||||
p := parser{
|
p := parser{
|
||||||
lexer: lexer.New(source),
|
lexer: lexer.New(source),
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +25,7 @@ func ParseSchema(source *Source) (*SchemaDocument, error) {
|
||||||
return ast, nil
|
return ast, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseSchemas(inputs ...*Source) (*SchemaDocument, error) {
|
func ParseSchemas(inputs ...*Source) (*SchemaDocument, *gqlerror.Error) {
|
||||||
ast := &SchemaDocument{}
|
ast := &SchemaDocument{}
|
||||||
for _, input := range inputs {
|
for _, input := range inputs {
|
||||||
inputAst, err := ParseSchema(input)
|
inputAst, err := ParseSchema(input)
|
||||||
|
|
|
||||||
2
vendor/github.com/vektah/gqlparser/v2/parser/schema_test.yml
generated
vendored
2
vendor/github.com/vektah/gqlparser/v2/parser/schema_test.yml
generated
vendored
|
|
@ -643,4 +643,4 @@ fuzzer:
|
||||||
input: "\"\"\"\r"
|
input: "\"\"\"\r"
|
||||||
error:
|
error:
|
||||||
message: 'Unexpected <Invalid>'
|
message: 'Unexpected <Invalid>'
|
||||||
locations: [{ line: 2, column: 1 }]
|
locations: [{ line: 1, column: 5 }]
|
||||||
|
|
|
||||||
35
vendor/github.com/vektah/gqlparser/v2/validator/rules/known_root_type.go
generated
vendored
35
vendor/github.com/vektah/gqlparser/v2/validator/rules/known_root_type.go
generated
vendored
|
|
@ -1,35 +0,0 @@
|
||||||
package validator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
|
||||||
. "github.com/vektah/gqlparser/v2/validator"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
AddRule("KnownRootType", func(observers *Events, addError AddErrFunc) {
|
|
||||||
// A query's root must be a valid type. Surprisingly, this isn't
|
|
||||||
// checked anywhere else!
|
|
||||||
observers.OnOperation(func(walker *Walker, operation *ast.OperationDefinition) {
|
|
||||||
var def *ast.Definition
|
|
||||||
switch operation.Operation {
|
|
||||||
case ast.Query, "":
|
|
||||||
def = walker.Schema.Query
|
|
||||||
case ast.Mutation:
|
|
||||||
def = walker.Schema.Mutation
|
|
||||||
case ast.Subscription:
|
|
||||||
def = walker.Schema.Subscription
|
|
||||||
default:
|
|
||||||
// This shouldn't even parse; if it did we probably need to
|
|
||||||
// update this switch block to add the new operation type.
|
|
||||||
panic(fmt.Sprintf(`got unknown operation type "%s"`, operation.Operation))
|
|
||||||
}
|
|
||||||
if def == nil {
|
|
||||||
addError(
|
|
||||||
Message(`Schema does not support operation type "%s"`, operation.Operation),
|
|
||||||
At(operation.Position))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
15
vendor/github.com/vektah/gqlparser/v2/validator/rules/values_of_correct_type.go
generated
vendored
15
vendor/github.com/vektah/gqlparser/v2/validator/rules/values_of_correct_type.go
generated
vendored
|
|
@ -16,13 +16,6 @@ func init() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if value.Kind == ast.NullValue && value.ExpectedType.NonNull {
|
|
||||||
addError(
|
|
||||||
Message(`Expected value of type "%s", found %s.`, value.ExpectedType.String(), value.String()),
|
|
||||||
At(value.Position),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if value.Definition.Kind == ast.Scalar {
|
if value.Definition.Kind == ast.Scalar {
|
||||||
// Skip custom validating scalars
|
// Skip custom validating scalars
|
||||||
if !value.Definition.OneOf("Int", "Float", "String", "Boolean", "ID") {
|
if !value.Definition.OneOf("Int", "Float", "String", "Boolean", "ID") {
|
||||||
|
|
@ -44,7 +37,13 @@ func init() {
|
||||||
|
|
||||||
switch value.Kind {
|
switch value.Kind {
|
||||||
case ast.NullValue:
|
case ast.NullValue:
|
||||||
return
|
if value.ExpectedType.NonNull {
|
||||||
|
addError(
|
||||||
|
Message(`Expected value of type "%s", found %s.`, value.ExpectedType.String(), value.String()),
|
||||||
|
At(value.Position),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
case ast.ListValue:
|
case ast.ListValue:
|
||||||
if value.ExpectedType.Elem == nil {
|
if value.ExpectedType.Elem == nil {
|
||||||
unexpectedTypeMessage(addError, value)
|
unexpectedTypeMessage(addError, value)
|
||||||
|
|
|
||||||
26
vendor/github.com/vektah/gqlparser/v2/validator/schema.go
generated
vendored
26
vendor/github.com/vektah/gqlparser/v2/validator/schema.go
generated
vendored
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/vektah/gqlparser/v2/parser"
|
"github.com/vektah/gqlparser/v2/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadSchema(inputs ...*Source) (*Schema, error) {
|
func LoadSchema(inputs ...*Source) (*Schema, *gqlerror.Error) {
|
||||||
ast, err := parser.ParseSchemas(inputs...)
|
ast, err := parser.ParseSchemas(inputs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -18,7 +18,7 @@ func LoadSchema(inputs ...*Source) (*Schema, error) {
|
||||||
return ValidateSchemaDocument(ast)
|
return ValidateSchemaDocument(ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, error) {
|
func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, *gqlerror.Error) {
|
||||||
schema := Schema{
|
schema := Schema{
|
||||||
Types: map[string]*Definition{},
|
Types: map[string]*Definition{},
|
||||||
Directives: map[string]*DirectiveDefinition{},
|
Directives: map[string]*DirectiveDefinition{},
|
||||||
|
|
@ -81,23 +81,8 @@ func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, error) {
|
||||||
|
|
||||||
for i, dir := range ast.Directives {
|
for i, dir := range ast.Directives {
|
||||||
if schema.Directives[dir.Name] != nil {
|
if schema.Directives[dir.Name] != nil {
|
||||||
// While the spec says SDL must not (§3.5) explicitly define builtin
|
|
||||||
// scalars, it may (§3.13) define builtin directives. Here we check for
|
|
||||||
// that, and reject doubly-defined directives otherwise.
|
|
||||||
switch dir.Name {
|
|
||||||
case "include", "skip", "deprecated", "specifiedBy": // the builtins
|
|
||||||
// In principle here we might want to validate that the
|
|
||||||
// directives are the same. But they might not be, if the
|
|
||||||
// server has an older spec than we do. (Plus, validating this
|
|
||||||
// is a lot of work.) So we just keep the first one we saw.
|
|
||||||
// That's an arbitrary choice, but in theory the only way it
|
|
||||||
// fails is if the server is using features newer than this
|
|
||||||
// version of gqlparser, in which case they're in trouble
|
|
||||||
// anyway.
|
|
||||||
default:
|
|
||||||
return nil, gqlerror.ErrorPosf(dir.Position, "Cannot redeclare directive %s.", dir.Name)
|
return nil, gqlerror.ErrorPosf(dir.Position, "Cannot redeclare directive %s.", dir.Name)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
schema.Directives[dir.Name] = ast.Directives[i]
|
schema.Directives[dir.Name] = ast.Directives[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,13 +262,6 @@ func validateDefinition(schema *Schema, def *Definition) *gqlerror.Error {
|
||||||
if len(def.EnumValues) == 0 {
|
if len(def.EnumValues) == 0 {
|
||||||
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more unique enum values.", def.Kind, def.Name)
|
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more unique enum values.", def.Kind, def.Name)
|
||||||
}
|
}
|
||||||
for _, value := range def.EnumValues {
|
|
||||||
for _, nonEnum := range [3]string{"true", "false", "null"} {
|
|
||||||
if value.Name == nonEnum {
|
|
||||||
return gqlerror.ErrorPosf(def.Position, "%s %s: non-enum value %s.", def.Kind, def.Name, value.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case InputObject:
|
case InputObject:
|
||||||
if len(def.Fields) == 0 {
|
if len(def.Fields) == 0 {
|
||||||
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more input fields.", def.Kind, def.Name)
|
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more input fields.", def.Kind, def.Name)
|
||||||
|
|
|
||||||
13
vendor/github.com/vektah/gqlparser/v2/validator/schema_test.yml
generated
vendored
13
vendor/github.com/vektah/gqlparser/v2/validator/schema_test.yml
generated
vendored
|
|
@ -523,11 +523,6 @@ directives:
|
||||||
message: "Cannot redeclare directive A."
|
message: "Cannot redeclare directive A."
|
||||||
locations: [{line: 2, column: 12}]
|
locations: [{line: 2, column: 12}]
|
||||||
|
|
||||||
- name: can redeclare builtin directives
|
|
||||||
input: |
|
|
||||||
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
|
||||||
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
|
||||||
|
|
||||||
- name: must be declared
|
- name: must be declared
|
||||||
input: |
|
input: |
|
||||||
type User {
|
type User {
|
||||||
|
|
@ -668,11 +663,3 @@ type references:
|
||||||
error:
|
error:
|
||||||
message: "Undefined type FooBar."
|
message: "Undefined type FooBar."
|
||||||
locations: [{line: 1, column: 21}]
|
locations: [{line: 1, column: 21}]
|
||||||
|
|
||||||
- name: Invalid enum value
|
|
||||||
input: |
|
|
||||||
enum Enum { true }
|
|
||||||
|
|
||||||
error:
|
|
||||||
message: "ENUM Enum: non-enum value true."
|
|
||||||
locations: [{line: 1, column: 6}]
|
|
||||||
|
|
|
||||||
2
vendor/github.com/vektah/gqlparser/v2/validator/vars.go
generated
vendored
2
vendor/github.com/vektah/gqlparser/v2/validator/vars.go
generated
vendored
|
|
@ -14,7 +14,7 @@ import (
|
||||||
var UnexpectedType = fmt.Errorf("Unexpected Type")
|
var UnexpectedType = fmt.Errorf("Unexpected Type")
|
||||||
|
|
||||||
// VariableValues coerces and validates variable values
|
// VariableValues coerces and validates variable values
|
||||||
func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables map[string]interface{}) (map[string]interface{}, error) {
|
func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables map[string]interface{}) (map[string]interface{}, *gqlerror.Error) {
|
||||||
coercedVars := map[string]interface{}{}
|
coercedVars := map[string]interface{}{}
|
||||||
|
|
||||||
validator := varValidator{
|
validator := varValidator{
|
||||||
|
|
|
||||||
10
vendor/modules.txt
vendored
10
vendor/modules.txt
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
# github.com/99designs/gqlgen v0.17.24
|
# github.com/99designs/gqlgen v0.17.2
|
||||||
## explicit; go 1.16
|
## explicit; go 1.16
|
||||||
github.com/99designs/gqlgen
|
github.com/99designs/gqlgen
|
||||||
github.com/99designs/gqlgen/api
|
github.com/99designs/gqlgen/api
|
||||||
|
|
@ -254,6 +254,12 @@ github.com/mailru/easyjson
|
||||||
github.com/mailru/easyjson/buffer
|
github.com/mailru/easyjson/buffer
|
||||||
github.com/mailru/easyjson/jlexer
|
github.com/mailru/easyjson/jlexer
|
||||||
github.com/mailru/easyjson/jwriter
|
github.com/mailru/easyjson/jwriter
|
||||||
|
# github.com/matryer/moq v0.2.3
|
||||||
|
## explicit; go 1.14
|
||||||
|
github.com/matryer/moq
|
||||||
|
github.com/matryer/moq/internal/registry
|
||||||
|
github.com/matryer/moq/internal/template
|
||||||
|
github.com/matryer/moq/pkg/moq
|
||||||
# github.com/mattn/go-sqlite3 v1.14.7
|
# github.com/mattn/go-sqlite3 v1.14.7
|
||||||
## explicit; go 1.12
|
## explicit; go 1.12
|
||||||
github.com/mattn/go-sqlite3
|
github.com/mattn/go-sqlite3
|
||||||
|
|
@ -375,7 +381,7 @@ github.com/vearutop/statigz
|
||||||
## explicit
|
## explicit
|
||||||
github.com/vektah/dataloaden
|
github.com/vektah/dataloaden
|
||||||
github.com/vektah/dataloaden/pkg/generator
|
github.com/vektah/dataloaden/pkg/generator
|
||||||
# github.com/vektah/gqlparser/v2 v2.5.1
|
# github.com/vektah/gqlparser/v2 v2.4.2
|
||||||
## explicit; go 1.16
|
## explicit; go 1.16
|
||||||
github.com/vektah/gqlparser/v2
|
github.com/vektah/gqlparser/v2
|
||||||
github.com/vektah/gqlparser/v2/ast
|
github.com/vektah/gqlparser/v2/ast
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue