diff --git a/.circleci/config.yml b/.circleci/config.yml index ef4a8afd24..26e594fb29 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ jobs: gqlgen/golang go run ./integration/server/server.go \ ) - sleep 2 + sleep 20 docker run \ -e SERVER_URL=http://integration_server:1234/query \ diff --git a/.circleci/golang.Dockerfile b/.circleci/golang.Dockerfile index 7cc98dbcaf..a0ceb286bf 100644 --- a/.circleci/golang.Dockerfile +++ b/.circleci/golang.Dockerfile @@ -1,12 +1,10 @@ -FROM golang:1.10 +FROM golang:1.11 -RUN curl -L -o /bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && chmod +x /bin/dep -RUN go get -u github.com/alecthomas/gometalinter github.com/vektah/gorunpkg -RUN gometalinter --install +RUN curl -sL --fail https://github.com/golangci/golangci-lint/releases/download/v1.13/golangci-lint-1.13-linux-amd64.tar.gz | tar zxv --strip-components=1 --dir=/go/bin -WORKDIR /go/src/github.com/99designs/gqlgen +WORKDIR /projects/gqlgen -COPY Gopkg.* /go/src/github.com/99designs/gqlgen/ -RUN dep ensure -v --vendor-only +COPY go.* /projects/gqlgen/ +RUN go mod download -COPY . /go/src/github.com/99designs/gqlgen/ +COPY . /projects/gqlgen/ diff --git a/.circleci/test.sh b/.circleci/test.sh index 79c98f18f2..37b0e9dc6a 100755 --- a/.circleci/test.sh +++ b/.circleci/test.sh @@ -18,4 +18,4 @@ echo "### running testsuite" go test -race ./... echo "### linting" -gometalinter --vendor ./... +golangci-lint run diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 89f1be95e2..1b9e422f96 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1,10 @@ -### Expected Behaviour +### What happened? -### Actual Behavior +### What did you expect? ### Minimal graphql.schema and models to reproduce + +### versions + - `gqlgen version`? + - `go version`? + - dep or go modules? diff --git a/.gitignore b/.gitignore index a9712beb0b..3dbd96815b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,8 @@ /integration/schema-fetched.graphql /example/chat/package-lock.json /codegen/gen +/gen .idea/ +*.test +*.out diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..2239d630a0 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +linters-settings: + errcheck: + ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy diff --git a/.gometalinter.json b/.gometalinter.json deleted file mode 100644 index ed98029895..0000000000 --- a/.gometalinter.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "sort": ["path"], - "Deadline": "5m", - "Linters": { - "errcheck": { - "Command": "errcheck -abspath -ignore '[rR]ead|[wW]rite|Close|[fF]print'", - "Pattern": "PATH:LINE:COL:MESSAGE", - "InstallFrom": "github.com/kisielk/errcheck", - "PartitionStrategy": "packages" - } - }, - "Skip": ["internal/imports/testdata"], - "Disable": ["gas","golint","gocyclo","goconst", "gotype", "maligned", "gosec", "staticcheck"] -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..461709ecf8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,27 @@ +# Contribution Guidelines + +Want to contribute to gqlgen? Here are some guidelines for how we accept help. + +## Getting in Touch + +Our [gitter](https://gitter.im/gqlgen/Lobby) channel is the best place to ask questions or get advice on using gqlgen. + +## Reporting Bugs and Issues + + We use [GitHub Issues](https://github.com/99designs/gqlgen/issues) to track bugs, so please do a search before submitting to ensure your problem isn't already tracked. + +### New Issues + +Please provide the expected and observed behaviours in your issue. A minimal GraphQL schema or configuration file should be provided where appropriate. + +## Proposing a Change + +If you intend to implement a feature for gqlgen, or make a non-trivial change to the current implementation, we recommend [first filing an issue](https://github.com/99designs/gqlgen/issues/new) marked with the `proposal` tag, so that the engineering team can provide guidance and feedback on the direction of an implementation. This also help ensure that other people aren't also working on the same thing. + +Bug fixes are welcome and should come with appropriate test coverage. + +New features should be made against the `next` branch. + +### License + +By contributing to gqlgen, you agree that your contributions will be licensed under its MIT license. diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index ba7c4bd22b..0000000000 --- a/Gopkg.lock +++ /dev/null @@ -1,270 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - digest = "1:99b2e09d42b4d0929e9e6ac496922f5221baa79b60968576d5ce310b44640c3b" - name = "github.com/agnivade/levenshtein" - packages = ["."] - pruneopts = "UT" - revision = "1787a73e302ce294513cfab1982e186f5cf8985f" - -[[projects]] - digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - digest = "1:66ddebb274faa160a4a23394a17ad3c8e15fee9bf5408d13f77d22b61bc7f072" - name = "github.com/go-chi/chi" - packages = ["."] - pruneopts = "UT" - revision = "e83ac2304db3c50cf03d96a2fcd39009d458bc35" - version = "v3.3.2" - -[[projects]] - digest = "1:f3df613325a793ffb3d0ce7644a3bb6f62db45ac744dafe20172fe999c61cdbf" - name = "github.com/gogo/protobuf" - packages = [ - "io", - "proto", - ] - pruneopts = "UT" - revision = "1adfc126b41513cc696b209667c8656ea7aac67c" - version = "v1.0.0" - -[[projects]] - digest = "1:160eabf7a69910fd74f29c692718bc2437c1c1c7d4c9dea9712357752a70e5df" - name = "github.com/gorilla/context" - packages = ["."] - pruneopts = "UT" - revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" - version = "v1.1" - -[[projects]] - digest = "1:88aa9e326e2bd6045a46e00a922954b3e1a9ac5787109f49ac85366df370e1e5" - name = "github.com/gorilla/mux" - packages = ["."] - pruneopts = "UT" - revision = "53c1911da2b537f792e7cafcb446b05ffe33b996" - version = "v1.6.1" - -[[projects]] - digest = "1:43dd08a10854b2056e615d1b1d22ac94559d822e1f8b6fcc92c1a1057e85188e" - name = "github.com/gorilla/websocket" - packages = ["."] - pruneopts = "UT" - revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b" - version = "v1.2.0" - -[[projects]] - branch = "master" - digest = "1:cf296baa185baae04a9a7004efee8511d08e2f5f51d4cbe5375da89722d681db" - name = "github.com/hashicorp/golang-lru" - packages = [ - ".", - "simplelru", - ] - pruneopts = "UT" - revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3" - -[[projects]] - branch = "master" - digest = "1:ab9cfaf00fc5db5fd9d8e5f33da52e62bcc977d1976503dcc2a1492f391bd9ed" - name = "github.com/mitchellh/mapstructure" - packages = ["."] - pruneopts = "UT" - revision = "a4e142e9c047c904fa2f1e144d9a84e6133024bc" - -[[projects]] - digest = "1:d07bd28263c09c5d7f6502e8ddac63e027eca0eafcd07632790d958b50360317" - name = "github.com/opentracing/basictracer-go" - packages = [ - ".", - "wire", - ] - pruneopts = "UT" - revision = "1b32af207119a14b1b231d451df3ed04a72efebf" - version = "v1.0.0" - -[[projects]] - digest = "1:450b7623b185031f3a456801155c8320209f75d0d4c4e633c6b1e59d44d6e392" - name = "github.com/opentracing/opentracing-go" - packages = [ - ".", - "ext", - "log", - ] - pruneopts = "UT" - revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" - version = "v1.0.2" - -[[projects]] - digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" - name = "github.com/pkg/errors" - packages = ["."] - pruneopts = "UT" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:b0c25f00bad20d783d259af2af8666969e2fc343fa0dc9efe52936bbd67fb758" - name = "github.com/rs/cors" - packages = ["."] - pruneopts = "UT" - revision = "9a47f48565a795472d43519dd49aac781f3034fb" - version = "v1.6.0" - -[[projects]] - branch = "master" - digest = "1:7ca2584fa7da0520cd2d1136a10194fe5a5b220bdb215074ab6f7b5ad91115f4" - name = "github.com/shurcooL/httpfs" - packages = ["vfsutil"] - pruneopts = "UT" - revision = "809beceb23714880abc4a382a00c05f89d13b1cc" - -[[projects]] - branch = "master" - digest = "1:a3f0c6930421c8a4c02aaf2a00c5e7b808204b15a47b1d8c285c1e9cbda886b5" - name = "github.com/shurcooL/vfsgen" - packages = ["."] - pruneopts = "UT" - revision = "ffb13db8def02f545acc58bd288ec6057c2bbfb9" - -[[projects]] - digest = "1:7e8d267900c7fa7f35129a2a37596e38ed0f11ca746d6d9ba727980ee138f9f6" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require", - ] - pruneopts = "UT" - revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" - version = "v1.2.1" - -[[projects]] - digest = "1:b24d38b282bacf9791408a080f606370efa3d364e4b5fd9ba0f7b87786d3b679" - name = "github.com/urfave/cli" - packages = ["."] - pruneopts = "UT" - revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" - version = "v1.20.0" - -[[projects]] - branch = "master" - digest = "1:3684f335059f8441260c3e949c0b99de97ea1057ecc493fdbd72ff3c27863277" - name = "github.com/vektah/dataloaden" - packages = ["."] - pruneopts = "UT" - revision = "314ac81052eedc03ac0a79bdc89d05a49a2a5814" - -[[projects]] - digest = "1:ed6a41de3eedd8d4868eea057837860453ebbe08c5e385fd50d4c24e5642ec18" - name = "github.com/vektah/gqlparser" - packages = [ - ".", - "ast", - "gqlerror", - "lexer", - "parser", - "validator", - "validator/rules", - ] - pruneopts = "UT" - revision = "e805d08bb209b1accdea76bd2327811858d81985" - version = "v1.0.0" - -[[projects]] - branch = "master" - digest = "1:76ee51c3f468493aff39dbacc401e8831fbb765104cbf613b89bef01cf4bad70" - name = "golang.org/x/net" - packages = ["context"] - pruneopts = "UT" - revision = "b3c676e531a6dc479fa1b35ac961c13f5e2b4d2e" - -[[projects]] - branch = "master" - digest = "1:3cbc05413b8aac22b1f6d4350ed696b5a83a8515a4136db8f1ec3a0aee3d76e1" - name = "golang.org/x/tools" - packages = [ - "go/ast/astutil", - "go/buildutil", - "go/loader", - "imports", - ] - pruneopts = "UT" - revision = "ce871d178848e3eea1e8795e5cfb74053dde4bb9" - -[[projects]] - digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" - -[[projects]] - branch = "master" - digest = "1:741ebea9214cc226789d3003baeca9b169e04b5b336fb1a3b2c16e75bd296bb5" - name = "sourcegraph.com/sourcegraph/appdash" - packages = [ - ".", - "httptrace", - "internal/wire", - "opentracing", - "sqltrace", - "traceapp", - "traceapp/tmpl", - ] - pruneopts = "UT" - revision = "2cc67fd647551af94593ecaaa89fe4e5b2940a3e" - -[[projects]] - branch = "master" - digest = "1:8e0a2957fe342f22d70a543c3fcdf390f7627419c3d82d87ab4fd715a9ef5716" - name = "sourcegraph.com/sourcegraph/appdash-data" - packages = ["."] - pruneopts = "UT" - revision = "73f23eafcf67cad684fba328dd545a116ac273ff" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/go-chi/chi", - "github.com/gorilla/websocket", - "github.com/hashicorp/golang-lru", - "github.com/mitchellh/mapstructure", - "github.com/opentracing/opentracing-go", - "github.com/pkg/errors", - "github.com/rs/cors", - "github.com/stretchr/testify/assert", - "github.com/stretchr/testify/require", - "github.com/urfave/cli", - "github.com/vektah/dataloaden", - "github.com/vektah/gqlparser", - "github.com/vektah/gqlparser/ast", - "github.com/vektah/gqlparser/gqlerror", - "github.com/vektah/gqlparser/parser", - "github.com/vektah/gqlparser/validator", - "golang.org/x/tools/go/ast/astutil", - "golang.org/x/tools/go/loader", - "golang.org/x/tools/imports", - "gopkg.in/yaml.v2", - "sourcegraph.com/sourcegraph/appdash", - "sourcegraph.com/sourcegraph/appdash/opentracing", - "sourcegraph.com/sourcegraph/appdash/traceapp", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 7876142a7e..0000000000 --- a/Gopkg.toml +++ /dev/null @@ -1,29 +0,0 @@ -required = ["github.com/vektah/dataloaden"] - -[[constraint]] - branch = "master" - name = "github.com/mitchellh/mapstructure" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.1" - -[[constraint]] - branch = "master" - name = "golang.org/x/tools" - -[[constraint]] - name = "github.com/vektah/gqlparser" - version = "^1.0.0" - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - name = "gopkg.in/yaml.v2" - version = "2.2.1" - -[[constraint]] - name = "github.com/rs/cors" - version = "1.6.0" diff --git a/README.md b/README.md index 708f66127d..0b302bdd55 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,31 @@ # gqlgen [![CircleCI](https://badgen.net/circleci/github/99designs/gqlgen/master)](https://circleci.com/gh/99designs/gqlgen) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/) -This is a library for quickly creating strictly typed graphql servers in golang. - -See the [docs](https://gqlgen.com/) for a getting started guide. - -### Feature comparison - -| | [gqlgen](https://github.com/99designs/gqlgen) | [gophers](https://github.com/graph-gophers/graphql-go) | [graphql-go](https://github.com/graphql-go/graphql) | [thunder](https://github.com/samsarahq/thunder) | -| --------: | :-------- | :-------- | :-------- | :-------- | -| Kind | schema first | schema first | run time types | struct first | -| Boilerplate | less | more | more | some | -| Docs | [docs](https://gqlgen.com) & [examples](https://github.com/99designs/gqlgen/tree/master/example) | [examples](https://github.com/graph-gophers/graphql-go/tree/master/example/starwars) | [examples](https://github.com/graphql-go/graphql/tree/master/examples) | [examples](https://github.com/samsarahq/thunder/tree/master/example)| -| Query | :+1: | :+1: | :+1: | :+1: | -| Mutation | :+1: | :construction: [pr](https://github.com/graph-gophers/graphql-go/pull/182) | :+1: | :+1: | -| Subscription | :+1: | :construction: [pr](https://github.com/graph-gophers/graphql-go/pull/182) | :+1: | :+1: | -| Type Safety | :+1: | :+1: | :no_entry: | :+1: | -| Type Binding | :+1: | :construction: [pr](https://github.com/graph-gophers/graphql-go/pull/194) | :no_entry: | :+1: | -| Embedding | :+1: | :no_entry: | :construction: [pr](https://github.com/graphql-go/graphql/pull/371) | :no_entry: | -| Interfaces | :+1: | :+1: | :+1: | :no_entry: [is](https://github.com/samsarahq/thunder/issues/78) | -| Generated Enums | :+1: | :no_entry: | :no_entry: | :no_entry: | -| Generated Inputs | :+1: | :no_entry: | :no_entry: | :no_entry: | -| Stitching gql | :clock1: [is](https://github.com/99designs/gqlgen/issues/5) | :no_entry: | :no_entry: | :no_entry: | -| Opentracing | :+1: | :+1: | :no_entry: | :scissors:[pr](https://github.com/samsarahq/thunder/pull/77) | -| Hooks for error logging | :+1: | :no_entry: | :no_entry: | :no_entry: | -| Dataloading | :+1: | :+1: | :+1: | :warning: | -| Concurrency | :+1: | :+1: | :+1: | :+1: | -| Custom errors & error.path | :+1: | :no_entry: [is](https://github.com/graphql-go/graphql/issues/259) | :no_entry: | :no_entry: | -| Query complexity | :+1: | :no_entry: [is](https://github.com/graphql-go/graphql/issues/231) | :no_entry: | :no_entry: | - - -### Help - -Create an issue or join the conversation on [gitter](https://gitter.im/gqlgen) +## What is gqlgen? + +[gqlgen](https://github.com/99designs/gqlgen) is a Go library for building GraphQL servers without any fuss. gqlgen is: + + - **Schema first** — Define your API using the GraphQL [Schema Definition Language](http://graphql.org/learn/schema/). + - **Type safe** — You should never see `map[string]interface{}` here. + - **Codegen** — Let us generate the boring bits, so you can build your app quickly. + +[Feature Comparison](https://gqlgen.com/feature-comparison/) + +## Getting Started + +First work your way through the [Getting Started](https://gqlgen.com/getting-started/) tutorial. + +If you can't find what your looking for, look at our [examples](https://github.com/99designs/gqlgen/tree/master/example) for example usage of gqlgen. + +## Reporting Issues + +If you think you've found a bug, or something isn't behaving the way you think it should, please raise an [issue](https://github.com/99designs/gqlgen/issues) on GitHub. + +## Contributing + +Read our [Contribution Guidelines](https://github.com/99designs/gqlgen/blob/master/CONTRIBUTING.md) for information on how you can help out gqlgen. + +## Other Resources + + - [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/) + - [GraphQL workshop for Golang developers by Iván Corrales Solera](https://graphql-go.wesovilabs.com) diff --git a/api/generate.go b/api/generate.go new file mode 100644 index 0000000000..3dd083f52f --- /dev/null +++ b/api/generate.go @@ -0,0 +1,76 @@ +package api + +import ( + "syscall" + + "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/plugin" + "github.com/99designs/gqlgen/plugin/modelgen" + "github.com/99designs/gqlgen/plugin/resolvergen" + "github.com/pkg/errors" + "golang.org/x/tools/go/packages" +) + +func Generate(cfg *config.Config, option ...Option) error { + _ = syscall.Unlink(cfg.Exec.Filename) + _ = syscall.Unlink(cfg.Model.Filename) + + plugins := []plugin.Plugin{ + modelgen.New(), + resolvergen.New(), + } + + for _, o := range option { + o(cfg, &plugins) + } + + for _, p := range plugins { + if mut, ok := p.(plugin.ConfigMutator); ok { + err := mut.MutateConfig(cfg) + if err != nil { + return errors.Wrap(err, p.Name()) + } + } + } + // Merge again now that the generated models have been injected into the typemap + data, err := codegen.BuildData(cfg) + if err != nil { + return errors.Wrap(err, "merging failed") + } + + if err = codegen.GenerateCode(data); err != nil { + return errors.Wrap(err, "generating core failed") + } + + for _, p := range plugins { + if mut, ok := p.(plugin.CodeGenerator); ok { + err := mut.GenerateCode(data) + if err != nil { + return errors.Wrap(err, p.Name()) + } + } + } + + if err := validate(cfg); err != nil { + return errors.Wrap(err, "validation failed") + } + + return nil +} + +func validate(cfg *config.Config) error { + roots := []string{cfg.Exec.ImportPath()} + if cfg.Model.IsDefined() { + roots = append(roots, cfg.Model.ImportPath()) + } + + if cfg.Resolver.IsDefined() { + roots = append(roots, cfg.Resolver.ImportPath()) + } + _, err := packages.Load(&packages.Config{Mode: packages.LoadTypes | packages.LoadSyntax}, roots...) + if err != nil { + return errors.Wrap(err, "validation failed") + } + return nil +} diff --git a/api/option.go b/api/option.go new file mode 100644 index 0000000000..f7ba6774bd --- /dev/null +++ b/api/option.go @@ -0,0 +1,20 @@ +package api + +import ( + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/plugin" +) + +type Option func(cfg *config.Config, plugins *[]plugin.Plugin) + +func NoPlugins() Option { + return func(cfg *config.Config, plugins *[]plugin.Plugin) { + *plugins = nil + } +} + +func AddPlugin(p plugin.Plugin) Option { + return func(cfg *config.Config, plugins *[]plugin.Plugin) { + *plugins = append(*plugins, p) + } +} diff --git a/appveyor.yml b/appveyor.yml index 9f43012041..db47511148 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,18 +3,15 @@ version: "{build}" # Source Config skip_branch_with_pr: true -clone_folder: c:\gopath\src\github.com\99designs\gqlgen +clone_folder: c:\projects\gqlgen # Build host environment: GOPATH: c:\gopath - GOVERSION: 1.10 + GOVERSION: 1.11.5 PATH: '%PATH%;c:\gopath\bin' -branches: - only: ["master", "next"] - init: - git config --global core.autocrlf input @@ -31,16 +28,5 @@ build: false deploy: false test_script: - - go get -u github.com/vektah/gorunpkg github.com/golang/dep/cmd/dep - - dep ensure -vendor-only - go generate ./... - go test -timeout 20m ./... - - - echo "testing init" - - rd /s /q vendor - - go get ./... - - go install - - cd c:\gopath\src\github.com\99designs\ - - mkdir init-project - - cd init-project - - gqlgen init diff --git a/client/websocket.go b/client/websocket.go index d66c872ca3..f7452b4c97 100644 --- a/client/websocket.go +++ b/client/websocket.go @@ -84,7 +84,10 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter Close: c.Close, Next: func(response interface{}) error { var op operationMessage - c.ReadJSON(&op) + err := c.ReadJSON(&op) + if err != nil { + return err + } if op.Type != dataMsg { if op.Type == errorMsg { return fmt.Errorf(string(op.Payload)) diff --git a/codegen/ambient.go b/cmd/ambient.go similarity index 95% rename from codegen/ambient.go rename to cmd/ambient.go index c9909fcc78..7838fdf16d 100644 --- a/codegen/ambient.go +++ b/cmd/ambient.go @@ -1,4 +1,4 @@ -package codegen +package cmd import ( // Import and ignore the ambient imports listed below so dependency managers diff --git a/cmd/gen.go b/cmd/gen.go index 97bd6342f1..c69858b44b 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -2,10 +2,10 @@ package cmd import ( "fmt" - "io/ioutil" "os" - "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/api" + "github.com/99designs/gqlgen/codegen/config" "github.com/pkg/errors" "github.com/urfave/cli" ) @@ -18,38 +18,27 @@ var genCmd = cli.Command{ cli.StringFlag{Name: "config, c", Usage: "the config filename"}, }, Action: func(ctx *cli.Context) { - var config *codegen.Config + var cfg *config.Config var err error if configFilename := ctx.String("config"); configFilename != "" { - config, err = codegen.LoadConfig(configFilename) + cfg, err = config.LoadConfig(configFilename) if err != nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) } } else { - config, err = codegen.LoadConfigFromDefaultLocations() + cfg, err = config.LoadConfigFromDefaultLocations() if os.IsNotExist(errors.Cause(err)) { - config = codegen.DefaultConfig() + cfg = config.DefaultConfig() } else if err != nil { fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - } - - for _, filename := range config.SchemaFilename { - var schemaRaw []byte - schemaRaw, err = ioutil.ReadFile(filename) - if err != nil { - fmt.Fprintln(os.Stderr, "unable to open schema: "+err.Error()) - os.Exit(1) + os.Exit(2) } - config.SchemaStr[filename] = string(schemaRaw) } - err = codegen.Generate(*config) - if err != nil { + if err = api.Generate(cfg); err != nil { fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(2) + os.Exit(3) } }, } diff --git a/cmd/init.go b/cmd/init.go index 6ad7e58c81..e07bed9708 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -7,10 +7,13 @@ import ( "os" "strings" - "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/api" + "github.com/99designs/gqlgen/plugin/servergen" + + "github.com/99designs/gqlgen/codegen/config" "github.com/pkg/errors" "github.com/urfave/cli" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" ) var configComment = ` @@ -68,41 +71,27 @@ var initCmd = cli.Command{ }, } -func GenerateGraphServer(config *codegen.Config, serverFilename string) { - for _, filename := range config.SchemaFilename { - schemaRaw, err := ioutil.ReadFile(filename) - if err != nil { - fmt.Fprintln(os.Stderr, "unable to open schema: "+err.Error()) - os.Exit(1) - } - config.SchemaStr[filename] = string(schemaRaw) - } - - if err := codegen.Generate(*config); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - if err := codegen.GenerateServer(*config, serverFilename); err != nil { +func GenerateGraphServer(cfg *config.Config, serverFilename string) { + err := api.Generate(cfg, api.AddPlugin(servergen.New(serverFilename))) + if err != nil { fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) } fmt.Fprintf(os.Stdout, "Exec \"go run ./%s\" to start GraphQL server\n", serverFilename) } -func initConfig(ctx *cli.Context) *codegen.Config { - var config *codegen.Config +func initConfig(ctx *cli.Context) *config.Config { + var cfg *config.Config var err error configFilename := ctx.String("config") if configFilename != "" { - config, err = codegen.LoadConfig(configFilename) + cfg, err = config.LoadConfig(configFilename) } else { - config, err = codegen.LoadConfigFromDefaultLocations() + cfg, err = config.LoadConfigFromDefaultLocations() } - if config != nil { - fmt.Fprintf(os.Stderr, "init failed: a configuration file already exists at %s\n", config.FilePath) + if cfg != nil { + fmt.Fprintf(os.Stderr, "init failed: a configuration file already exists\n") os.Exit(1) } @@ -114,9 +103,9 @@ func initConfig(ctx *cli.Context) *codegen.Config { if configFilename == "" { configFilename = "gqlgen.yml" } - config = codegen.DefaultConfig() + cfg = config.DefaultConfig() - config.Resolver = codegen.PackageConfig{ + cfg.Resolver = config.PackageConfig{ Filename: "resolver.go", Type: "Resolver", } @@ -124,23 +113,21 @@ func initConfig(ctx *cli.Context) *codegen.Config { var buf bytes.Buffer buf.WriteString(strings.TrimSpace(configComment)) buf.WriteString("\n\n") - { - var b []byte - b, err = yaml.Marshal(config) - if err != nil { - fmt.Fprintln(os.Stderr, "unable to marshal yaml: "+err.Error()) - os.Exit(1) - } - buf.Write(b) + var b []byte + b, err = yaml.Marshal(cfg) + if err != nil { + fmt.Fprintln(os.Stderr, "unable to marshal yaml: "+err.Error()) + os.Exit(1) } + buf.Write(b) err = ioutil.WriteFile(configFilename, buf.Bytes(), 0644) if err != nil { - fmt.Fprintln(os.Stderr, "unable to write config file: "+err.Error()) + fmt.Fprintln(os.Stderr, "unable to write cfg file: "+err.Error()) os.Exit(1) } - return config + return cfg } func initSchema(schemaFilename string) { diff --git a/cmd/root.go b/cmd/root.go index 519c2e1af5..dc2970ac89 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,6 @@ import ( "os" "github.com/99designs/gqlgen/graphql" - "github.com/99designs/gqlgen/internal/gopath" "github.com/urfave/cli" // Required since otherwise dep will prune away these unused packages before codegen has a chance to run @@ -23,14 +22,6 @@ func Execute() { app.Flags = genCmd.Flags app.Version = graphql.Version app.Before = func(context *cli.Context) error { - pwd, err := os.Getwd() - if err != nil { - return fmt.Errorf("unable to determine current workding dir: %s\n", err.Error()) - } - - if !gopath.Contains(pwd) { - return fmt.Errorf("gqlgen must be run from inside your $GOPATH\n") - } if context.Bool("verbose") { log.SetFlags(0) } else { @@ -47,7 +38,7 @@ func Execute() { } if err := app.Run(os.Args); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } } diff --git a/codegen/args.go b/codegen/args.go new file mode 100644 index 0000000000..d1498bddb1 --- /dev/null +++ b/codegen/args.go @@ -0,0 +1,104 @@ +package codegen + +import ( + "fmt" + "go/types" + "strings" + + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/pkg/errors" + "github.com/vektah/gqlparser/ast" +) + +type ArgSet struct { + Args []*FieldArgument + FuncDecl string +} + +type FieldArgument struct { + *ast.ArgumentDefinition + TypeReference *config.TypeReference + VarName string // The name of the var in go + Object *Object // A link back to the parent object + Default interface{} // The default value + Directives []*Directive + Value interface{} // value set in Data +} + +func (f *FieldArgument) Stream() bool { + return f.Object != nil && f.Object.Stream +} + +func (b *builder) buildArg(obj *Object, arg *ast.ArgumentDefinition) (*FieldArgument, error) { + tr, err := b.Binder.TypeReference(arg.Type, nil) + if err != nil { + return nil, err + } + + argDirs, err := b.getDirectives(arg.Directives) + if err != nil { + return nil, err + } + newArg := FieldArgument{ + ArgumentDefinition: arg, + TypeReference: tr, + Object: obj, + VarName: templates.ToGoPrivate(arg.Name), + Directives: argDirs, + } + + if arg.DefaultValue != nil { + newArg.Default, err = arg.DefaultValue.Value(nil) + if err != nil { + return nil, errors.Errorf("default value is not valid: %s", err.Error()) + } + } + + return &newArg, nil +} + +func (b *builder) bindArgs(field *Field, params *types.Tuple) error { + var newArgs []*FieldArgument + +nextArg: + for j := 0; j < params.Len(); j++ { + param := params.At(j) + for _, oldArg := range field.Args { + if strings.EqualFold(oldArg.Name, param.Name()) { + tr, err := b.Binder.TypeReference(oldArg.Type, param.Type()) + if err != nil { + return err + } + oldArg.TypeReference = tr + + newArgs = append(newArgs, oldArg) + continue nextArg + } + } + + // no matching arg found, abort + return fmt.Errorf("arg %s not in schema", param.Name()) + } + + field.Args = newArgs + return nil +} + +func (a *Data) Args() map[string][]*FieldArgument { + ret := map[string][]*FieldArgument{} + for _, o := range a.Objects { + for _, f := range o.Fields { + if len(f.Args) > 0 { + ret[f.ArgsFunc()] = f.Args + } + } + } + + for _, d := range a.Directives { + if len(d.Args) > 0 { + ret[d.ArgsFunc()] = d.Args + } + } + return ret +} diff --git a/codegen/args.gotpl b/codegen/args.gotpl new file mode 100644 index 0000000000..4c7212182c --- /dev/null +++ b/codegen/args.gotpl @@ -0,0 +1,43 @@ +{{ range $name, $args := .Args }} +func (ec *executionContext) {{ $name }}(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + {{- range $i, $arg := . }} + var arg{{$i}} {{ $arg.TypeReference.GO | ref}} + if tmp, ok := rawArgs[{{$arg.Name|quote}}]; ok { + {{- if $arg.Directives }} + getArg0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp) } + + {{- range $i, $directive := $arg.Directives }} + getArg{{add $i 1}} := func(ctx context.Context) (res interface{}, err error) { + {{- range $dArg := $directive.Args }} + {{- if and $dArg.TypeReference.IsPtr ( notNil "Value" $dArg ) }} + {{ $dArg.VarName }} := {{ $dArg.Value | dump }} + {{- end }} + {{- end }} + n := getArg{{$i}} + return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "tmp" "n" }}) + } + {{- end }} + + tmp, err = getArg{{$arg.Directives|len}}(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.({{ $arg.TypeReference.GO | ref }}) ; ok { + arg{{$i}} = data + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be {{ $arg.TypeReference.GO }}`, tmp) + } + {{- else }} + arg{{$i}}, err = ec.{{ $arg.TypeReference.UnmarshalFunc }}(ctx, tmp) + if err != nil { + return nil, err + } + {{- end }} + } + args[{{$arg.Name|quote}}] = arg{{$i}} + {{- end }} + return args, nil +} +{{ end }} diff --git a/codegen/build.go b/codegen/build.go deleted file mode 100644 index 582689a745..0000000000 --- a/codegen/build.go +++ /dev/null @@ -1,194 +0,0 @@ -package codegen - -import ( - "fmt" - "go/build" - "go/types" - "os" - - "github.com/pkg/errors" - "golang.org/x/tools/go/loader" -) - -type Build struct { - PackageName string - Objects Objects - Inputs Objects - Interfaces []*Interface - QueryRoot *Object - MutationRoot *Object - SubscriptionRoot *Object - SchemaRaw map[string]string - SchemaFilename SchemaFilenames - Directives []*Directive -} - -type ModelBuild struct { - PackageName string - Models []Model - Enums []Enum -} - -type ResolverBuild struct { - PackageName string - ResolverType string - Objects Objects - ResolverFound bool -} - -type ServerBuild struct { - PackageName string - ExecPackageName string - ResolverPackageName string -} - -// Create a list of models that need to be generated -func (cfg *Config) models() (*ModelBuild, error) { - namedTypes := cfg.buildNamedTypes() - - progLoader := cfg.newLoaderWithoutErrors() - - prog, err := progLoader.Load() - if err != nil { - return nil, errors.Wrap(err, "loading failed") - } - - cfg.bindTypes(namedTypes, cfg.Model.Dir(), prog) - - models, err := cfg.buildModels(namedTypes, prog) - if err != nil { - return nil, err - } - return &ModelBuild{ - PackageName: cfg.Model.Package, - Models: models, - Enums: cfg.buildEnums(namedTypes), - }, nil -} - -// bind a schema together with some code to generate a Build -func (cfg *Config) resolver() (*ResolverBuild, error) { - progLoader := cfg.newLoaderWithoutErrors() - progLoader.Import(cfg.Resolver.ImportPath()) - - prog, err := progLoader.Load() - if err != nil { - return nil, err - } - - destDir := cfg.Resolver.Dir() - - namedTypes := cfg.buildNamedTypes() - - cfg.bindTypes(namedTypes, destDir, prog) - - objects, err := cfg.buildObjects(namedTypes, prog) - if err != nil { - return nil, err - } - - def, _ := findGoType(prog, cfg.Resolver.ImportPath(), cfg.Resolver.Type) - resolverFound := def != nil - - return &ResolverBuild{ - PackageName: cfg.Resolver.Package, - Objects: objects, - ResolverType: cfg.Resolver.Type, - ResolverFound: resolverFound, - }, nil -} - -func (cfg *Config) server(destDir string) *ServerBuild { - return &ServerBuild{ - PackageName: cfg.Resolver.Package, - ExecPackageName: cfg.Exec.ImportPath(), - ResolverPackageName: cfg.Resolver.ImportPath(), - } -} - -// bind a schema together with some code to generate a Build -func (cfg *Config) bind() (*Build, error) { - namedTypes := cfg.buildNamedTypes() - - progLoader := cfg.newLoaderWithoutErrors() - prog, err := progLoader.Load() - if err != nil { - return nil, errors.Wrap(err, "loading failed") - } - - cfg.bindTypes(namedTypes, cfg.Exec.Dir(), prog) - - objects, err := cfg.buildObjects(namedTypes, prog) - if err != nil { - return nil, err - } - - inputs, err := cfg.buildInputs(namedTypes, prog) - if err != nil { - return nil, err - } - directives, err := cfg.buildDirectives(namedTypes) - if err != nil { - return nil, err - } - - b := &Build{ - PackageName: cfg.Exec.Package, - Objects: objects, - Interfaces: cfg.buildInterfaces(namedTypes, prog), - Inputs: inputs, - SchemaRaw: cfg.SchemaStr, - SchemaFilename: cfg.SchemaFilename, - Directives: directives, - } - - if cfg.schema.Query != nil { - b.QueryRoot = b.Objects.ByName(cfg.schema.Query.Name) - } else { - return b, fmt.Errorf("query entry point missing") - } - - if cfg.schema.Mutation != nil { - b.MutationRoot = b.Objects.ByName(cfg.schema.Mutation.Name) - } - - if cfg.schema.Subscription != nil { - b.SubscriptionRoot = b.Objects.ByName(cfg.schema.Subscription.Name) - } - return b, nil -} - -func (cfg *Config) validate() error { - progLoader := cfg.newLoaderWithErrors() - _, err := progLoader.Load() - return err -} - -func (cfg *Config) newLoaderWithErrors() loader.Config { - conf := loader.Config{} - - for _, pkg := range cfg.Models.referencedPackages() { - conf.Import(pkg) - } - return conf -} - -func (cfg *Config) newLoaderWithoutErrors() loader.Config { - conf := cfg.newLoaderWithErrors() - conf.AllowErrors = true - conf.TypeChecker = types.Config{ - Error: func(e error) {}, - } - return conf -} - -func resolvePkg(pkgName string) (string, error) { - cwd, _ := os.Getwd() - - pkg, err := build.Default.Import(pkgName, cwd, build.FindOnly) - if err != nil { - return "", err - } - - return pkg.ImportPath, nil -} diff --git a/codegen/codegen.go b/codegen/codegen.go deleted file mode 100644 index 8aadd48cd2..0000000000 --- a/codegen/codegen.go +++ /dev/null @@ -1,183 +0,0 @@ -package codegen - -import ( - "fmt" - "log" - "os" - "path/filepath" - "regexp" - "syscall" - - "github.com/99designs/gqlgen/codegen/templates" - "github.com/pkg/errors" - "github.com/vektah/gqlparser" - "github.com/vektah/gqlparser/ast" - "github.com/vektah/gqlparser/gqlerror" -) - -func Generate(cfg Config) error { - if err := cfg.normalize(); err != nil { - return err - } - - if err := cfg.check(); err != nil { - return fmt.Errorf("invalid config format: " + err.Error()) - } - _ = syscall.Unlink(cfg.Exec.Filename) - _ = syscall.Unlink(cfg.Model.Filename) - - modelsBuild, err := cfg.models() - if err != nil { - return errors.Wrap(err, "model plan failed") - } - if len(modelsBuild.Models) > 0 || len(modelsBuild.Enums) > 0 { - if err = templates.RenderToFile("models.gotpl", cfg.Model.Filename, modelsBuild); err != nil { - return err - } - - for _, model := range modelsBuild.Models { - modelCfg := cfg.Models[model.GQLType] - modelCfg.Model = cfg.Model.ImportPath() + "." + model.GoType - cfg.Models[model.GQLType] = modelCfg - } - - for _, enum := range modelsBuild.Enums { - modelCfg := cfg.Models[enum.GQLType] - modelCfg.Model = cfg.Model.ImportPath() + "." + enum.GoType - cfg.Models[enum.GQLType] = modelCfg - } - } - - build, err := cfg.bind() - if err != nil { - return errors.Wrap(err, "exec plan failed") - } - - if err := templates.RenderToFile("generated.gotpl", cfg.Exec.Filename, build); err != nil { - return err - } - - if cfg.Resolver.IsDefined() { - if err := generateResolver(cfg); err != nil { - return errors.Wrap(err, "generating resolver failed") - } - } - - if err := cfg.validate(); err != nil { - return errors.Wrap(err, "validation failed") - } - - return nil -} - -func GenerateServer(cfg Config, filename string) error { - if err := cfg.Exec.normalize(); err != nil { - return errors.Wrap(err, "exec") - } - if err := cfg.Resolver.normalize(); err != nil { - return errors.Wrap(err, "resolver") - } - - serverFilename := abs(filename) - serverBuild := cfg.server(filepath.Dir(serverFilename)) - - if _, err := os.Stat(serverFilename); os.IsNotExist(errors.Cause(err)) { - err = templates.RenderToFile("server.gotpl", serverFilename, serverBuild) - if err != nil { - return errors.Wrap(err, "generate server failed") - } - } else { - log.Printf("Skipped server: %s already exists\n", serverFilename) - } - return nil -} - -func generateResolver(cfg Config) error { - resolverBuild, err := cfg.resolver() - if err != nil { - return errors.Wrap(err, "resolver build failed") - } - filename := cfg.Resolver.Filename - - if resolverBuild.ResolverFound { - log.Printf("Skipped resolver: %s.%s already exists\n", cfg.Resolver.ImportPath(), cfg.Resolver.Type) - return nil - } - - if _, err := os.Stat(filename); os.IsNotExist(errors.Cause(err)) { - if err := templates.RenderToFile("resolver.gotpl", filename, resolverBuild); err != nil { - return err - } - } else { - log.Printf("Skipped resolver: %s already exists\n", filename) - } - - return nil -} - -func (cfg *Config) normalize() error { - if err := cfg.Model.normalize(); err != nil { - return errors.Wrap(err, "model") - } - - if err := cfg.Exec.normalize(); err != nil { - return errors.Wrap(err, "exec") - } - - if cfg.Resolver.IsDefined() { - if err := cfg.Resolver.normalize(); err != nil { - return errors.Wrap(err, "resolver") - } - } - - builtins := TypeMap{ - "__Directive": {Model: "github.com/99designs/gqlgen/graphql/introspection.Directive"}, - "__Type": {Model: "github.com/99designs/gqlgen/graphql/introspection.Type"}, - "__Field": {Model: "github.com/99designs/gqlgen/graphql/introspection.Field"}, - "__EnumValue": {Model: "github.com/99designs/gqlgen/graphql/introspection.EnumValue"}, - "__InputValue": {Model: "github.com/99designs/gqlgen/graphql/introspection.InputValue"}, - "__Schema": {Model: "github.com/99designs/gqlgen/graphql/introspection.Schema"}, - "Int": {Model: "github.com/99designs/gqlgen/graphql.Int"}, - "Float": {Model: "github.com/99designs/gqlgen/graphql.Float"}, - "String": {Model: "github.com/99designs/gqlgen/graphql.String"}, - "Boolean": {Model: "github.com/99designs/gqlgen/graphql.Boolean"}, - "ID": {Model: "github.com/99designs/gqlgen/graphql.ID"}, - "Time": {Model: "github.com/99designs/gqlgen/graphql.Time"}, - "Map": {Model: "github.com/99designs/gqlgen/graphql.Map"}, - } - - if cfg.Models == nil { - cfg.Models = TypeMap{} - } - for typeName, entry := range builtins { - if !cfg.Models.Exists(typeName) { - cfg.Models[typeName] = entry - } - } - - var sources []*ast.Source - for _, filename := range cfg.SchemaFilename { - sources = append(sources, &ast.Source{Name: filename, Input: cfg.SchemaStr[filename]}) - } - - var err *gqlerror.Error - cfg.schema, err = gqlparser.LoadSchema(sources...) - if err != nil { - return err - } - return nil -} - -var invalidPackageNameChar = regexp.MustCompile(`[^\w]`) - -func sanitizePackageName(pkg string) string { - return invalidPackageNameChar.ReplaceAllLiteralString(filepath.Base(pkg), "_") -} - -func abs(path string) string { - absPath, err := filepath.Abs(path) - if err != nil { - panic(err) - } - return filepath.ToSlash(absPath) -} diff --git a/codegen/codegen_test.go b/codegen/codegen_test.go deleted file mode 100644 index ebe1bf1641..0000000000 --- a/codegen/codegen_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package codegen - -import ( - "syscall" - "testing" - - "github.com/stretchr/testify/require" - "golang.org/x/tools/go/loader" -) - -func TestGenerateServer(t *testing.T) { - name := "graphserver" - schema := ` - type Query { - user: User - } - type User { - id: Int - fist_name: String - } -` - serverFilename := "gen/" + name + "/server/server.go" - cfg := Config{ - SchemaFilename: SchemaFilenames{"schema.graphql"}, - SchemaStr: map[string]string{"schema.graphql": schema}, - Exec: PackageConfig{Filename: "gen/" + name + "/exec.go"}, - Model: PackageConfig{Filename: "gen/" + name + "/model.go"}, - Resolver: PackageConfig{Filename: "gen/" + name + "/resolver.go", Type: "Resolver"}, - } - - _ = syscall.Unlink(cfg.Resolver.Filename) - _ = syscall.Unlink(serverFilename) - - err := Generate(cfg) - require.NoError(t, err) - - err = GenerateServer(cfg, serverFilename) - require.NoError(t, err) - - conf := loader.Config{} - conf.CreateFromFilenames("gen/"+name, serverFilename) - - _, err = conf.Load() - require.NoError(t, err) -} diff --git a/codegen/complexity.go b/codegen/complexity.go new file mode 100644 index 0000000000..66d21a840e --- /dev/null +++ b/codegen/complexity.go @@ -0,0 +1,11 @@ +package codegen + +func (o *Object) UniqueFields() map[string]*Field { + m := map[string]*Field{} + + for _, f := range o.Fields { + m[f.GoFieldName] = f + } + + return m +} diff --git a/codegen/config/binder.go b/codegen/config/binder.go new file mode 100644 index 0000000000..5e8c1cf696 --- /dev/null +++ b/codegen/config/binder.go @@ -0,0 +1,451 @@ +package config + +import ( + "fmt" + "go/token" + "go/types" + + "github.com/99designs/gqlgen/codegen/templates" + "github.com/99designs/gqlgen/internal/code" + "github.com/pkg/errors" + "github.com/vektah/gqlparser/ast" + "golang.org/x/tools/go/packages" +) + +// Binder connects graphql types to golang types using static analysis +type Binder struct { + pkgs []*packages.Package + schema *ast.Schema + cfg *Config + References []*TypeReference +} + +func (c *Config) NewBinder(s *ast.Schema) (*Binder, error) { + pkgs, err := packages.Load(&packages.Config{Mode: packages.LoadTypes | packages.LoadSyntax}, c.Models.ReferencedPackages()...) + if err != nil { + return nil, err + } + + for _, p := range pkgs { + for _, e := range p.Errors { + if e.Kind == packages.ListError { + return nil, p.Errors[0] + } + } + } + + return &Binder{ + pkgs: pkgs, + schema: s, + cfg: c, + }, nil +} + +func (b *Binder) TypePosition(typ types.Type) token.Position { + named, isNamed := typ.(*types.Named) + if !isNamed { + return token.Position{ + Filename: "unknown", + } + } + + return b.ObjectPosition(named.Obj()) +} + +func (b *Binder) ObjectPosition(typ types.Object) token.Position { + if typ == nil { + return token.Position{ + Filename: "unknown", + } + } + pkg := b.getPkg(typ.Pkg().Path()) + return pkg.Fset.Position(typ.Pos()) +} + +func (b *Binder) FindType(pkgName string, typeName string) (types.Type, error) { + obj, err := b.FindObject(pkgName, typeName) + if err != nil { + return nil, err + } + + if fun, isFunc := obj.(*types.Func); isFunc { + return fun.Type().(*types.Signature).Params().At(0).Type(), nil + } + return obj.Type(), nil +} + +func (b *Binder) getPkg(find string) *packages.Package { + for _, p := range b.pkgs { + if code.NormalizeVendor(find) == code.NormalizeVendor(p.PkgPath) { + return p + } + } + return nil +} + +var MapType = types.NewMap(types.Typ[types.String], types.NewInterfaceType(nil, nil).Complete()) +var InterfaceType = types.NewInterfaceType(nil, nil) + +func (b *Binder) DefaultUserObject(name string) (types.Type, error) { + models := b.cfg.Models[name].Model + if len(models) == 0 { + return nil, fmt.Errorf(name + " not found in typemap") + } + + if models[0] == "map[string]interface{}" { + return MapType, nil + } + + if models[0] == "interface{}" { + return InterfaceType, nil + } + + pkgName, typeName := code.PkgAndType(models[0]) + if pkgName == "" { + return nil, fmt.Errorf("missing package name for %s", name) + } + + obj, err := b.FindObject(pkgName, typeName) + if err != nil { + return nil, err + } + + return obj.Type(), nil +} + +func (b *Binder) FindObject(pkgName string, typeName string) (types.Object, error) { + if pkgName == "" { + return nil, fmt.Errorf("package cannot be nil") + } + fullName := typeName + if pkgName != "" { + fullName = pkgName + "." + typeName + } + + pkg := b.getPkg(pkgName) + if pkg == nil { + return nil, errors.Errorf("required package was not loaded: %s", fullName) + } + + // function based marshalers take precedence + for astNode, def := range pkg.TypesInfo.Defs { + // only look at defs in the top scope + if def == nil || def.Parent() == nil || def.Parent() != pkg.Types.Scope() { + continue + } + + if astNode.Name == "Marshal"+typeName { + return def, nil + } + } + + // then look for types directly + for astNode, def := range pkg.TypesInfo.Defs { + // only look at defs in the top scope + if def == nil || def.Parent() == nil || def.Parent() != pkg.Types.Scope() { + continue + } + + if astNode.Name == typeName { + return def, nil + } + } + + return nil, errors.Errorf("unable to find type %s\n", fullName) +} + +func (b *Binder) PointerTo(ref *TypeReference) *TypeReference { + newRef := &TypeReference{ + GO: types.NewPointer(ref.GO), + GQL: ref.GQL, + CastType: ref.CastType, + Definition: ref.Definition, + Unmarshaler: ref.Unmarshaler, + Marshaler: ref.Marshaler, + IsMarshaler: ref.IsMarshaler, + } + + b.References = append(b.References, newRef) + return newRef +} + +// TypeReference is used by args and field types. The Definition can refer to both input and output types. +type TypeReference struct { + Definition *ast.Definition + GQL *ast.Type + GO types.Type + CastType types.Type // Before calling marshalling functions cast from/to this base type + Marshaler *types.Func // When using external marshalling functions this will point to the Marshal 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 +} + +func (ref *TypeReference) Elem() *TypeReference { + if p, isPtr := ref.GO.(*types.Pointer); isPtr { + return &TypeReference{ + GO: p.Elem(), + GQL: ref.GQL, + CastType: ref.CastType, + Definition: ref.Definition, + Unmarshaler: ref.Unmarshaler, + Marshaler: ref.Marshaler, + IsMarshaler: ref.IsMarshaler, + } + } + + if s, isSlice := ref.GO.(*types.Slice); isSlice { + return &TypeReference{ + GO: s.Elem(), + GQL: ref.GQL.Elem, + CastType: ref.CastType, + Definition: ref.Definition, + Unmarshaler: ref.Unmarshaler, + Marshaler: ref.Marshaler, + IsMarshaler: ref.IsMarshaler, + } + } + return nil +} + +func (t *TypeReference) IsPtr() bool { + _, isPtr := t.GO.(*types.Pointer) + return isPtr +} + +func (t *TypeReference) IsNilable() bool { + _, isPtr := t.GO.(*types.Pointer) + _, isMap := t.GO.(*types.Map) + _, isInterface := t.GO.(*types.Interface) + return isPtr || isMap || isInterface +} + +func (t *TypeReference) IsSlice() bool { + _, isSlice := t.GO.(*types.Slice) + return isSlice +} + +func (t *TypeReference) IsNamed() bool { + _, isSlice := t.GO.(*types.Named) + return isSlice +} + +func (t *TypeReference) IsStruct() bool { + _, isStruct := t.GO.Underlying().(*types.Struct) + return isStruct +} + +func (t *TypeReference) IsScalar() bool { + return t.Definition.Kind == ast.Scalar +} + +func (t *TypeReference) HasIsZero() bool { + it := t.GO + if ptr, isPtr := it.(*types.Pointer); isPtr { + it = ptr.Elem() + } + namedType, ok := it.(*types.Named) + if !ok { + return false + } + + for i := 0; i < namedType.NumMethods(); i++ { + switch namedType.Method(i).Name() { + case "IsZero": + return true + } + } + return false +} + +func (t *TypeReference) UniquenessKey() string { + var nullability = "O" + if t.GQL.NonNull { + nullability = "N" + } + + return nullability + t.Definition.Name + "2" + templates.TypeIdentifier(t.GO) +} + +func (t *TypeReference) MarshalFunc() string { + if t.Definition == nil { + panic(errors.New("Definition missing for " + t.GQL.Name())) + } + + if t.Definition.Kind == ast.InputObject { + return "" + } + + return "marshal" + t.UniquenessKey() +} + +func (t *TypeReference) UnmarshalFunc() string { + if t.Definition == nil { + panic(errors.New("Definition missing for " + t.GQL.Name())) + } + + if !t.Definition.IsInputType() { + return "" + } + + return "unmarshal" + t.UniquenessKey() +} + +func (b *Binder) PushRef(ret *TypeReference) { + b.References = append(b.References, ret) +} + +func isMap(t types.Type) bool { + if t == nil { + return true + } + _, ok := t.(*types.Map) + return ok +} + +func isIntf(t types.Type) bool { + if t == nil { + return true + } + _, ok := t.(*types.Interface) + return ok +} + +func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret *TypeReference, err error) { + var pkgName, typeName string + def := b.schema.Types[schemaType.Name()] + defer func() { + if err == nil && ret != nil { + b.PushRef(ret) + } + }() + + if len(b.cfg.Models[schemaType.Name()].Model) == 0 { + return nil, fmt.Errorf("%s was not found", schemaType.Name()) + } + + for _, model := range b.cfg.Models[schemaType.Name()].Model { + if model == "map[string]interface{}" { + if !isMap(bindTarget) { + continue + } + return &TypeReference{ + Definition: def, + GQL: schemaType, + GO: MapType, + }, nil + } + + if model == "interface{}" { + if !isIntf(bindTarget) { + continue + } + return &TypeReference{ + Definition: def, + GQL: schemaType, + GO: InterfaceType, + }, nil + } + + pkgName, typeName = code.PkgAndType(model) + if pkgName == "" { + return nil, fmt.Errorf("missing package name for %s", schemaType.Name()) + } + + ref := &TypeReference{ + Definition: def, + GQL: schemaType, + } + + obj, err := b.FindObject(pkgName, typeName) + if err != nil { + return nil, err + } + + if fun, isFunc := obj.(*types.Func); isFunc { + ref.GO = fun.Type().(*types.Signature).Params().At(0).Type() + ref.Marshaler = fun + ref.Unmarshaler = types.NewFunc(0, fun.Pkg(), "Unmarshal"+typeName, nil) + } else if hasMethod(obj.Type(), "MarshalGQL") && hasMethod(obj.Type(), "UnmarshalGQL") { + ref.GO = obj.Type() + ref.IsMarshaler = true + } else if underlying := basicUnderlying(obj.Type()); underlying != nil && underlying.Kind() == types.String { + // Special case for named types wrapping strings. Used by default enum implementations. + + ref.GO = obj.Type() + ref.CastType = underlying + + underlyingRef, err := b.TypeReference(&ast.Type{NamedType: "String"}, nil) + if err != nil { + return nil, err + } + + ref.Marshaler = underlyingRef.Marshaler + ref.Unmarshaler = underlyingRef.Unmarshaler + } else { + ref.GO = obj.Type() + } + + ref.GO = b.CopyModifiersFromAst(schemaType, ref.GO) + + if bindTarget != nil { + if err = code.CompatibleTypes(ref.GO, bindTarget); err != nil { + continue + } + ref.GO = bindTarget + } + + return ref, nil + } + + return nil, fmt.Errorf("%s has type compatible with %s", schemaType.Name(), bindTarget.String()) +} + +func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type { + if t.Elem != nil { + return types.NewSlice(b.CopyModifiersFromAst(t.Elem, base)) + } + + var isInterface bool + if named, ok := base.(*types.Named); ok { + _, isInterface = named.Underlying().(*types.Interface) + } + + if !isInterface && !t.NonNull { + return types.NewPointer(base) + } + + return base +} + +func hasMethod(it types.Type, name string) bool { + if ptr, isPtr := it.(*types.Pointer); isPtr { + it = ptr.Elem() + } + namedType, ok := it.(*types.Named) + if !ok { + return false + } + + for i := 0; i < namedType.NumMethods(); i++ { + if namedType.Method(i).Name() == name { + return true + } + } + return false +} + +func basicUnderlying(it types.Type) *types.Basic { + if ptr, isPtr := it.(*types.Pointer); isPtr { + it = ptr.Elem() + } + namedType, ok := it.(*types.Named) + if !ok { + return nil + } + + if basic, ok := namedType.Underlying().(*types.Basic); ok { + return basic + } + + return nil +} diff --git a/codegen/config.go b/codegen/config/config.go similarity index 50% rename from codegen/config.go rename to codegen/config/config.go index 9826ca5dfe..7a7232b58d 100644 --- a/codegen/config.go +++ b/codegen/config/config.go @@ -1,27 +1,36 @@ -package codegen +package config import ( "fmt" - "go/build" + "go/types" "io/ioutil" "os" "path/filepath" "sort" "strings" - "github.com/99designs/gqlgen/internal/gopath" + "github.com/99designs/gqlgen/internal/code" "github.com/pkg/errors" + "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" ) +type Config struct { + SchemaFilename StringList `yaml:"schema,omitempty"` + Exec PackageConfig `yaml:"exec"` + Model PackageConfig `yaml:"model"` + Resolver PackageConfig `yaml:"resolver,omitempty"` + Models TypeMap `yaml:"models,omitempty"` + StructTag string `yaml:"struct_tag,omitempty"` +} + var cfgFilenames = []string{".gqlgen.yml", "gqlgen.yml", "gqlgen.yaml"} // DefaultConfig creates a copy of the default config func DefaultConfig() *Config { return &Config{ - SchemaFilename: SchemaFilenames{"schema.graphql"}, - SchemaStr: map[string]string{}, + SchemaFilename: StringList{"schema.graphql"}, Model: PackageConfig{Filename: "models_gen.go"}, Exec: PackageConfig{Filename: "generated.go"}, } @@ -56,7 +65,7 @@ func LoadConfig(filename string) (*Config, error) { } preGlobbing := config.SchemaFilename - config.SchemaFilename = SchemaFilenames{} + config.SchemaFilename = StringList{} for _, f := range preGlobbing { matches, err := filepath.Glob(f) if err != nil { @@ -71,26 +80,9 @@ func LoadConfig(filename string) (*Config, error) { } } - config.FilePath = filename - config.SchemaStr = map[string]string{} - return config, nil } -type Config struct { - SchemaFilename SchemaFilenames `yaml:"schema,omitempty"` - SchemaStr map[string]string `yaml:"-"` - Exec PackageConfig `yaml:"exec"` - Model PackageConfig `yaml:"model"` - Resolver PackageConfig `yaml:"resolver,omitempty"` - Models TypeMap `yaml:"models,omitempty"` - StructTag string `yaml:"struct_tag,omitempty"` - - FilePath string `yaml:"-"` - - schema *ast.Schema `yaml:"-"` -} - type PackageConfig struct { Filename string `yaml:"filename,omitempty"` Package string `yaml:"package,omitempty"` @@ -98,7 +90,7 @@ type PackageConfig struct { } type TypeMapEntry struct { - Model string `yaml:"model"` + Model StringList `yaml:"model"` Fields map[string]TypeMapField `yaml:"fields,omitempty"` } @@ -107,9 +99,9 @@ type TypeMapField struct { FieldName string `yaml:"fieldName"` } -type SchemaFilenames []string +type StringList []string -func (a *SchemaFilenames) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (a *StringList) UnmarshalYAML(unmarshal func(interface{}) error) error { var single string err := unmarshal(&single) if err == nil { @@ -127,7 +119,7 @@ func (a *SchemaFilenames) UnmarshalYAML(unmarshal func(interface{}) error) error return nil } -func (a SchemaFilenames) Has(file string) bool { +func (a StringList) Has(file string) bool { for _, existing := range a { if existing == file { return true @@ -144,20 +136,14 @@ func (c *PackageConfig) normalize() error { // If Package is not set, first attempt to load the package at the output dir. If that fails // fallback to just the base dir name of the output filename. if c.Package == "" { - cwd, _ := os.Getwd() - pkg, _ := build.Default.Import(c.ImportPath(), cwd, 0) - if pkg.Name != "" { - c.Package = pkg.Name - } else { - c.Package = filepath.Base(c.Dir()) - } + c.Package = code.NameForPackage(c.ImportPath()) } - c.Package = sanitizePackageName(c.Package) + return nil } func (c *PackageConfig) ImportPath() string { - return gopath.MustDir2Import(c.Dir()) + return code.ImportPathForDir(c.Dir()) } func (c *PackageConfig) Dir() string { @@ -171,33 +157,40 @@ func (c *PackageConfig) Check() error { if c.Filename != "" && !strings.HasSuffix(c.Filename, ".go") { return fmt.Errorf("filename should be path to a go source file") } - return nil + + return c.normalize() +} + +func (c *PackageConfig) Pkg() *types.Package { + return types.NewPackage(c.ImportPath(), c.Dir()) } func (c *PackageConfig) IsDefined() bool { return c.Filename != "" } -func (cfg *Config) check() error { - if err := cfg.Models.Check(); err != nil { +func (c *Config) Check() error { + if err := c.Models.Check(); err != nil { return errors.Wrap(err, "config.models") } - if err := cfg.Exec.Check(); err != nil { + if err := c.Exec.Check(); err != nil { return errors.Wrap(err, "config.exec") } - if err := cfg.Model.Check(); err != nil { + if err := c.Model.Check(); err != nil { return errors.Wrap(err, "config.model") } - if err := cfg.Resolver.Check(); err != nil { - return errors.Wrap(err, "config.resolver") + if c.Resolver.IsDefined() { + if err := c.Resolver.Check(); err != nil { + return errors.Wrap(err, "config.resolver") + } } // check packages names against conflict, if present in the same dir // and check filenames for uniqueness packageConfigList := []PackageConfig{ - cfg.Model, - cfg.Exec, - cfg.Resolver, + c.Model, + c.Exec, + c.Resolver, } filesMap := make(map[string]bool) pkgConfigsByDir := make(map[string]PackageConfig) @@ -214,7 +207,11 @@ func (cfg *Config) check() error { pkgConfigsByDir[current.Dir()] = current } - return nil + return c.normalize() +} + +func stripPath(path string) string { + return filepath.Base(path) } type TypeMap map[string]TypeMapEntry @@ -224,27 +221,36 @@ func (tm TypeMap) Exists(typeName string) bool { return ok } +func (tm TypeMap) UserDefined(typeName string) bool { + m, ok := tm[typeName] + return ok && len(m.Model) > 0 +} + func (tm TypeMap) Check() error { for typeName, entry := range tm { - if strings.LastIndex(entry.Model, ".") < strings.LastIndex(entry.Model, "/") { - return fmt.Errorf("model %s: invalid type specifier \"%s\" - you need to specify a struct to map to", typeName, entry.Model) + for _, model := range entry.Model { + if strings.LastIndex(model, ".") < strings.LastIndex(model, "/") { + return fmt.Errorf("model %s: invalid type specifier \"%s\" - you need to specify a struct to map to", typeName, entry.Model) + } } } return nil } -func (tm TypeMap) referencedPackages() []string { +func (tm TypeMap) ReferencedPackages() []string { var pkgs []string for _, typ := range tm { - if typ.Model == "map[string]interface{}" { - continue - } - pkg, _ := pkgAndType(typ.Model) - if pkg == "" || inStrSlice(pkgs, pkg) { - continue + for _, model := range typ.Model { + if model == "map[string]interface{}" || model == "interface{}" { + continue + } + pkg, _ := code.PkgAndType(model) + if pkg == "" || inStrSlice(pkgs, pkg) { + continue + } + pkgs = append(pkgs, code.QualifyPackagePath(pkg)) } - pkgs = append(pkgs, pkg) } sort.Slice(pkgs, func(i, j int) bool { @@ -253,6 +259,12 @@ func (tm TypeMap) referencedPackages() []string { return pkgs } +func (tm TypeMap) Add(Name string, goType string) { + modelCfg := tm[Name] + modelCfg.Model = append(modelCfg.Model, goType) + tm[Name] = modelCfg +} + func inStrSlice(haystack []string, needle string) bool { for _, v := range haystack { if needle == v { @@ -295,6 +307,102 @@ func findCfgInDir(dir string) string { return "" } -func stripPath(path string) string { - return filepath.Base(path) +func (c *Config) normalize() error { + if err := c.Model.normalize(); err != nil { + return errors.Wrap(err, "model") + } + + if err := c.Exec.normalize(); err != nil { + return errors.Wrap(err, "exec") + } + + if c.Resolver.IsDefined() { + if err := c.Resolver.normalize(); err != nil { + return errors.Wrap(err, "resolver") + } + } + + if c.Models == nil { + c.Models = TypeMap{} + } + + return nil +} + +func (c *Config) InjectBuiltins(s *ast.Schema) { + builtins := TypeMap{ + "__Directive": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.Directive"}}, + "__DirectiveLocation": {Model: StringList{"github.com/99designs/gqlgen/graphql.String"}}, + "__Type": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.Type"}}, + "__TypeKind": {Model: StringList{"github.com/99designs/gqlgen/graphql.String"}}, + "__Field": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.Field"}}, + "__EnumValue": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.EnumValue"}}, + "__InputValue": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.InputValue"}}, + "__Schema": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.Schema"}}, + "Float": {Model: StringList{"github.com/99designs/gqlgen/graphql.Float"}}, + "String": {Model: StringList{"github.com/99designs/gqlgen/graphql.String"}}, + "Boolean": {Model: StringList{"github.com/99designs/gqlgen/graphql.Boolean"}}, + "Int": {Model: StringList{ + "github.com/99designs/gqlgen/graphql.Int", + "github.com/99designs/gqlgen/graphql.Int32", + "github.com/99designs/gqlgen/graphql.Int64", + }}, + "ID": { + Model: StringList{ + "github.com/99designs/gqlgen/graphql.ID", + "github.com/99designs/gqlgen/graphql.IntID", + }, + }, + } + + for typeName, entry := range builtins { + if !c.Models.Exists(typeName) { + c.Models[typeName] = entry + } + } + + // These are additional types that are injected if defined in the schema as scalars. + extraBuiltins := TypeMap{ + "Time": {Model: StringList{"github.com/99designs/gqlgen/graphql.Time"}}, + "Map": {Model: StringList{"github.com/99designs/gqlgen/graphql.Map"}}, + } + + for typeName, entry := range extraBuiltins { + if t, ok := s.Types[typeName]; ok && t.Kind == ast.Scalar { + c.Models[typeName] = entry + } + } +} + +func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) { + schemaStrings := map[string]string{} + + var sources []*ast.Source + + for _, filename := range c.SchemaFilename { + filename = filepath.ToSlash(filename) + var err error + var schemaRaw []byte + schemaRaw, err = ioutil.ReadFile(filename) + if err != nil { + fmt.Fprintln(os.Stderr, "unable to open schema: "+err.Error()) + os.Exit(1) + } + schemaStrings[filename] = string(schemaRaw) + sources = append(sources, &ast.Source{Name: filename, Input: schemaStrings[filename]}) + } + + schema, err := gqlparser.LoadSchema(sources...) + if err != nil { + return nil, nil, err + } + return schema, schemaStrings, nil +} + +func abs(path string) string { + absPath, err := filepath.Abs(path) + if err != nil { + panic(err) + } + return filepath.ToSlash(absPath) } diff --git a/codegen/config_test.go b/codegen/config/config_test.go similarity index 79% rename from codegen/config_test.go rename to codegen/config/config_test.go index 09a20abf54..6ac5257cfd 100644 --- a/codegen/config_test.go +++ b/codegen/config/config_test.go @@ -1,4 +1,4 @@ -package codegen +package config import ( "os" @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) @@ -18,12 +17,12 @@ func TestLoadConfig(t *testing.T) { t.Run("malformed config", func(t *testing.T) { _, err := LoadConfig("testdata/cfg/malformedconfig.yml") - require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `asdf` into codegen.Config") + require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `asdf` into config.Config") }) t.Run("unknown keys", func(t *testing.T) { _, err := LoadConfig("testdata/cfg/unknownkeys.yml") - require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 2: field unknown not found in type codegen.Config") + require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 2: field unknown not found in type config.Config") }) } @@ -38,7 +37,7 @@ func TestLoadDefaultConfig(t *testing.T) { cfg, err = LoadConfigFromDefaultLocations() require.NoError(t, err) - require.Equal(t, SchemaFilenames{"inner"}, cfg.SchemaFilename) + require.Equal(t, StringList{"inner"}, cfg.SchemaFilename) }) t.Run("will find config in parent dirs", func(t *testing.T) { @@ -47,7 +46,7 @@ func TestLoadDefaultConfig(t *testing.T) { cfg, err = LoadConfigFromDefaultLocations() require.NoError(t, err) - require.Equal(t, SchemaFilenames{"outer"}, cfg.SchemaFilename) + require.Equal(t, StringList{"outer"}, cfg.SchemaFilename) }) t.Run("will return error if config doesn't exist", func(t *testing.T) { @@ -62,10 +61,10 @@ func TestLoadDefaultConfig(t *testing.T) { func TestReferencedPackages(t *testing.T) { t.Run("valid", func(t *testing.T) { tm := TypeMap{ - "Foo": {Model: "github.com/test.Foo"}, - "Bar": {Model: "github.com/test.Bar"}, - "Baz": {Model: "github.com/otherpkg.Baz"}, - "Map": {Model: "map[string]interface{}"}, + "Foo": {Model: StringList{"github.com/test.Foo"}}, + "Bar": {Model: StringList{"github.com/test.Bar"}}, + "Baz": {Model: StringList{"github.com/otherpkg.Baz"}}, + "Map": {Model: StringList{"map[string]interface{}"}}, "SkipResolver": { Fields: map[string]TypeMapField{ "field": {Resolver: false}, @@ -73,7 +72,7 @@ func TestReferencedPackages(t *testing.T) { }, } - pkgs := tm.referencedPackages() + pkgs := tm.ReferencedPackages() assert.Equal(t, []string{"github.com/test", "github.com/otherpkg"}, pkgs) }) @@ -88,7 +87,7 @@ func TestConfigCheck(t *testing.T) { err = config.normalize() require.NoError(t, err) - err = config.check() + err = config.Check() require.EqualError(t, err, "filenames exec.go and models.go are in the same directory but have different package definitions") }) } diff --git a/codegen/testdata/cfg/conflictedPackages.yml b/codegen/config/testdata/cfg/conflictedPackages.yml similarity index 100% rename from codegen/testdata/cfg/conflictedPackages.yml rename to codegen/config/testdata/cfg/conflictedPackages.yml diff --git a/codegen/testdata/cfg/gqlgen.yml b/codegen/config/testdata/cfg/gqlgen.yml similarity index 100% rename from codegen/testdata/cfg/gqlgen.yml rename to codegen/config/testdata/cfg/gqlgen.yml diff --git a/codegen/testdata/cfg/malformedconfig.yml b/codegen/config/testdata/cfg/malformedconfig.yml similarity index 100% rename from codegen/testdata/cfg/malformedconfig.yml rename to codegen/config/testdata/cfg/malformedconfig.yml diff --git a/codegen/testdata/cfg/otherdir/.gitkeep b/codegen/config/testdata/cfg/otherdir/.gitkeep similarity index 100% rename from codegen/testdata/cfg/otherdir/.gitkeep rename to codegen/config/testdata/cfg/otherdir/.gitkeep diff --git a/codegen/testdata/cfg/outer b/codegen/config/testdata/cfg/outer similarity index 100% rename from codegen/testdata/cfg/outer rename to codegen/config/testdata/cfg/outer diff --git a/codegen/testdata/cfg/subdir/gqlgen.yaml b/codegen/config/testdata/cfg/subdir/gqlgen.yaml similarity index 100% rename from codegen/testdata/cfg/subdir/gqlgen.yaml rename to codegen/config/testdata/cfg/subdir/gqlgen.yaml diff --git a/codegen/testdata/cfg/subdir/inner b/codegen/config/testdata/cfg/subdir/inner similarity index 100% rename from codegen/testdata/cfg/subdir/inner rename to codegen/config/testdata/cfg/subdir/inner diff --git a/codegen/testdata/cfg/unknownkeys.yml b/codegen/config/testdata/cfg/unknownkeys.yml similarity index 100% rename from codegen/testdata/cfg/unknownkeys.yml rename to codegen/config/testdata/cfg/unknownkeys.yml diff --git a/codegen/data.go b/codegen/data.go new file mode 100644 index 0000000000..f2ea70b4a4 --- /dev/null +++ b/codegen/data.go @@ -0,0 +1,168 @@ +package codegen + +import ( + "fmt" + "sort" + + "github.com/99designs/gqlgen/codegen/config" + "github.com/pkg/errors" + "github.com/vektah/gqlparser/ast" +) + +// Data is a unified model of the code to be generated. Plugins may modify this structure to do things like implement +// resolvers or directives automatically (eg grpc, validation) +type Data struct { + Config *config.Config + Schema *ast.Schema + SchemaStr map[string]string + Directives map[string]*Directive + Objects Objects + Inputs Objects + Interfaces map[string]*Interface + ReferencedTypes map[string]*config.TypeReference + ComplexityRoots map[string]*Object + + QueryRoot *Object + MutationRoot *Object + SubscriptionRoot *Object +} + +type builder struct { + Config *config.Config + Schema *ast.Schema + SchemaStr map[string]string + Binder *config.Binder + Directives map[string]*Directive +} + +func BuildData(cfg *config.Config) (*Data, error) { + b := builder{ + Config: cfg, + } + + var err error + b.Schema, b.SchemaStr, err = cfg.LoadSchema() + if err != nil { + return nil, err + } + + err = cfg.Check() + if err != nil { + return nil, err + } + + cfg.InjectBuiltins(b.Schema) + + b.Binder, err = b.Config.NewBinder(b.Schema) + if err != nil { + return nil, err + } + + b.Directives, err = b.buildDirectives() + if err != nil { + return nil, err + } + + dataDirectives := make(map[string]*Directive) + for name, d := range b.Directives { + if !d.Builtin { + dataDirectives[name] = d + } + } + + s := Data{ + Config: cfg, + Directives: dataDirectives, + Schema: b.Schema, + SchemaStr: b.SchemaStr, + Interfaces: map[string]*Interface{}, + } + + for _, schemaType := range b.Schema.Types { + switch schemaType.Kind { + case ast.Object: + obj, err := b.buildObject(schemaType) + if err != nil { + return nil, errors.Wrap(err, "unable to build object definition") + } + + s.Objects = append(s.Objects, obj) + case ast.InputObject: + input, err := b.buildObject(schemaType) + if err != nil { + return nil, errors.Wrap(err, "unable to build input definition") + } + + s.Inputs = append(s.Inputs, input) + + case ast.Union, ast.Interface: + s.Interfaces[schemaType.Name] = b.buildInterface(schemaType) + } + } + + if s.Schema.Query != nil { + s.QueryRoot = s.Objects.ByName(s.Schema.Query.Name) + } else { + return nil, fmt.Errorf("query entry point missing") + } + + if s.Schema.Mutation != nil { + s.MutationRoot = s.Objects.ByName(s.Schema.Mutation.Name) + } + + if s.Schema.Subscription != nil { + s.SubscriptionRoot = s.Objects.ByName(s.Schema.Subscription.Name) + } + + if err := b.injectIntrospectionRoots(&s); err != nil { + return nil, err + } + + s.ReferencedTypes, err = b.buildTypes() + if err != nil { + return nil, err + } + + sort.Slice(s.Objects, func(i, j int) bool { + return s.Objects[i].Definition.Name < s.Objects[j].Definition.Name + }) + + sort.Slice(s.Inputs, func(i, j int) bool { + return s.Inputs[i].Definition.Name < s.Inputs[j].Definition.Name + }) + + return &s, nil +} + +func (b *builder) injectIntrospectionRoots(s *Data) error { + obj := s.Objects.ByName(b.Schema.Query.Name) + if obj == nil { + return fmt.Errorf("root query type must be defined") + } + + __type, err := b.buildField(obj, &ast.FieldDefinition{ + Name: "__type", + Type: ast.NamedType("__Type", nil), + Arguments: []*ast.ArgumentDefinition{ + { + Name: "name", + Type: ast.NonNullNamedType("String", nil), + }, + }, + }) + if err != nil { + return err + } + + __schema, err := b.buildField(obj, &ast.FieldDefinition{ + Name: "__schema", + Type: ast.NamedType("__Schema", nil), + }) + if err != nil { + return err + } + + obj.Fields = append(obj.Fields, __type, __schema) + + return nil +} diff --git a/codegen/directive.go b/codegen/directive.go index 8017da069a..5a27e8ace7 100644 --- a/codegen/directive.go +++ b/codegen/directive.go @@ -4,11 +4,101 @@ import ( "fmt" "strconv" "strings" + + "github.com/99designs/gqlgen/codegen/templates" + "github.com/pkg/errors" + "github.com/vektah/gqlparser/ast" ) type Directive struct { - Name string - Args []FieldArgument + Name string + Args []*FieldArgument + Builtin bool +} + +func (b *builder) buildDirectives() (map[string]*Directive, error) { + directives := make(map[string]*Directive, len(b.Schema.Directives)) + + for name, dir := range b.Schema.Directives { + if _, ok := directives[name]; ok { + return nil, errors.Errorf("directive with name %s already exists", name) + } + + var builtin bool + if name == "skip" || name == "include" || name == "deprecated" { + builtin = true + } + + var args []*FieldArgument + for _, arg := range dir.Arguments { + tr, err := b.Binder.TypeReference(arg.Type, nil) + if err != nil { + return nil, err + } + + newArg := &FieldArgument{ + ArgumentDefinition: arg, + TypeReference: tr, + VarName: templates.ToGoPrivate(arg.Name), + } + + if arg.DefaultValue != nil { + var err error + newArg.Default, err = arg.DefaultValue.Value(nil) + if err != nil { + return nil, errors.Errorf("default value for directive argument %s(%s) is not valid: %s", dir.Name, arg.Name, err.Error()) + } + } + args = append(args, newArg) + } + + directives[name] = &Directive{ + Name: name, + Args: args, + Builtin: builtin, + } + } + + return directives, nil +} + +func (b *builder) getDirectives(list ast.DirectiveList) ([]*Directive, error) { + dirs := make([]*Directive, len(list)) + for i, d := range list { + argValues := make(map[string]interface{}, len(d.Arguments)) + for _, da := range d.Arguments { + val, err := da.Value.Value(nil) + if err != nil { + return nil, err + } + argValues[da.Name] = val + } + def, ok := b.Directives[d.Name] + if !ok { + return nil, fmt.Errorf("directive %s not found", d.Name) + } + + var args []*FieldArgument + for _, a := range def.Args { + value := a.Default + if argValue, ok := argValues[a.Name]; ok { + value = argValue + } + args = append(args, &FieldArgument{ + ArgumentDefinition: a.ArgumentDefinition, + Value: value, + VarName: a.VarName, + TypeReference: a.TypeReference, + }) + } + dirs[i] = &Directive{ + Name: d.Name, + Args: args, + } + + } + + return dirs, nil } func (d *Directive) ArgsFunc() string { @@ -23,7 +113,28 @@ func (d *Directive) CallArgs() string { args := []string{"ctx", "obj", "n"} for _, arg := range d.Args { - args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")") + args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")") + } + + return strings.Join(args, ", ") +} + +func (d *Directive) ResolveArgs(obj string, next string) string { + args := []string{"ctx", obj, next} + + for _, arg := range d.Args { + dArg := "&" + arg.VarName + if !arg.TypeReference.IsPtr() { + if arg.Value != nil { + dArg = templates.Dump(arg.Value) + } else { + dArg = templates.Dump(arg.Default) + } + } else if arg.Value == nil && arg.Default == nil { + dArg = "nil" + } + + args = append(args, dArg) } return strings.Join(args, ", ") @@ -33,7 +144,7 @@ func (d *Directive) Declaration() string { res := ucFirst(d.Name) + " func(ctx context.Context, obj interface{}, next graphql.Resolver" for _, arg := range d.Args { - res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) + res += fmt.Sprintf(", %s %s", arg.Name, templates.CurrentImports.LookupType(arg.TypeReference.GO)) } res += ") (res interface{}, err error)" diff --git a/codegen/directive_build.go b/codegen/directive_build.go deleted file mode 100644 index af77dc441f..0000000000 --- a/codegen/directive_build.go +++ /dev/null @@ -1,48 +0,0 @@ -package codegen - -import ( - "sort" - - "github.com/pkg/errors" -) - -func (cfg *Config) buildDirectives(types NamedTypes) ([]*Directive, error) { - var directives []*Directive - - for name, dir := range cfg.schema.Directives { - if name == "skip" || name == "include" || name == "deprecated" { - continue - } - - var args []FieldArgument - for _, arg := range dir.Arguments { - newArg := FieldArgument{ - GQLName: arg.Name, - Type: types.getType(arg.Type), - GoVarName: sanitizeArgName(arg.Name), - } - - if !newArg.Type.IsInput && !newArg.Type.IsScalar { - return nil, errors.Errorf("%s cannot be used as argument of directive %s(%s) only input and scalar types are allowed", arg.Type, dir.Name, arg.Name) - } - - if arg.DefaultValue != nil { - var err error - newArg.Default, err = arg.DefaultValue.Value(nil) - if err != nil { - return nil, errors.Errorf("default value for directive argument %s(%s) is not valid: %s", dir.Name, arg.Name, err.Error()) - } - } - args = append(args, newArg) - } - - directives = append(directives, &Directive{ - Name: name, - Args: args, - }) - } - - sort.Slice(directives, func(i, j int) bool { return directives[i].Name < directives[j].Name }) - - return directives, nil -} diff --git a/codegen/enum.go b/codegen/enum.go deleted file mode 100644 index 7804971c02..0000000000 --- a/codegen/enum.go +++ /dev/null @@ -1,12 +0,0 @@ -package codegen - -type Enum struct { - *NamedType - Description string - Values []EnumValue -} - -type EnumValue struct { - Name string - Description string -} diff --git a/codegen/enum_build.go b/codegen/enum_build.go deleted file mode 100644 index 457d923f22..0000000000 --- a/codegen/enum_build.go +++ /dev/null @@ -1,39 +0,0 @@ -package codegen - -import ( - "sort" - "strings" - - "github.com/99designs/gqlgen/codegen/templates" - "github.com/vektah/gqlparser/ast" -) - -func (cfg *Config) buildEnums(types NamedTypes) []Enum { - var enums []Enum - - for _, typ := range cfg.schema.Types { - namedType := types[typ.Name] - if typ.Kind != ast.Enum || strings.HasPrefix(typ.Name, "__") || namedType.IsUserDefined { - continue - } - - var values []EnumValue - for _, v := range typ.EnumValues { - values = append(values, EnumValue{v.Name, v.Description}) - } - - enum := Enum{ - NamedType: namedType, - Values: values, - Description: typ.Description, - } - enum.GoType = templates.ToCamel(enum.GQLType) - enums = append(enums, enum) - } - - sort.Slice(enums, func(i, j int) bool { - return enums[i].GQLType < enums[j].GQLType - }) - - return enums -} diff --git a/codegen/field.go b/codegen/field.go new file mode 100644 index 0000000000..f5f7b22139 --- /dev/null +++ b/codegen/field.go @@ -0,0 +1,394 @@ +package codegen + +import ( + "fmt" + "go/types" + "log" + "reflect" + "strconv" + "strings" + + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/pkg/errors" + "github.com/vektah/gqlparser/ast" +) + +type Field struct { + *ast.FieldDefinition + + TypeReference *config.TypeReference + GoFieldType GoFieldType // The field type in go, if any + GoReceiverName string // The name of method & var receiver in go, if any + GoFieldName string // The name of the method or var in go, if any + IsResolver bool // Does this field need a resolver + Args []*FieldArgument // A list of arguments to be passed to this field + MethodHasContext bool // If this is bound to a go method, does the method also take a context + NoErr bool // If this is bound to a go method, does that method have an error as the second argument + Object *Object // A link back to the parent object + Default interface{} // The default value + Directives []*Directive +} + +func (b *builder) buildField(obj *Object, field *ast.FieldDefinition) (*Field, error) { + dirs, err := b.getDirectives(field.Directives) + if err != nil { + return nil, err + } + + f := Field{ + FieldDefinition: field, + Object: obj, + Directives: dirs, + GoFieldName: templates.ToGo(field.Name), + GoFieldType: GoFieldVariable, + GoReceiverName: "obj", + } + + if field.DefaultValue != nil { + var err error + f.Default, err = field.DefaultValue.Value(nil) + if err != nil { + return nil, errors.Errorf("default value %s is not valid: %s", field.Name, err.Error()) + } + } + + for _, arg := range field.Arguments { + newArg, err := b.buildArg(obj, arg) + if err != nil { + return nil, err + } + f.Args = append(f.Args, newArg) + } + + if err = b.bindField(obj, &f); err != nil { + f.IsResolver = true + log.Println(err.Error()) + } + + if f.IsResolver && !f.TypeReference.IsPtr() && f.TypeReference.IsStruct() { + f.TypeReference = b.Binder.PointerTo(f.TypeReference) + } + + return &f, nil +} + +func (b *builder) bindField(obj *Object, f *Field) error { + defer func() { + if f.TypeReference == nil { + tr, err := b.Binder.TypeReference(f.Type, nil) + if err != nil { + panic(err) + } + f.TypeReference = tr + } + }() + + switch { + case f.Name == "__schema": + f.GoFieldType = GoFieldMethod + f.GoReceiverName = "ec" + f.GoFieldName = "introspectSchema" + return nil + case f.Name == "__type": + f.GoFieldType = GoFieldMethod + f.GoReceiverName = "ec" + f.GoFieldName = "introspectType" + return nil + case obj.Root: + f.IsResolver = true + return nil + case b.Config.Models[obj.Name].Fields[f.Name].Resolver: + f.IsResolver = true + return nil + case obj.Type == config.MapType: + f.GoFieldType = GoFieldMap + return nil + case b.Config.Models[obj.Name].Fields[f.Name].FieldName != "": + f.GoFieldName = b.Config.Models[obj.Name].Fields[f.Name].FieldName + } + + target, err := b.findBindTarget(obj.Type.(*types.Named), f.GoFieldName) + if err != nil { + return err + } + + pos := b.Binder.ObjectPosition(target) + + switch target := target.(type) { + case nil: + objPos := b.Binder.TypePosition(obj.Type) + return fmt.Errorf( + "%s:%d adding resolver method for %s.%s, nothing matched", + objPos.Filename, + objPos.Line, + obj.Name, + f.Name, + ) + + case *types.Func: + sig := target.Type().(*types.Signature) + if sig.Results().Len() == 1 { + f.NoErr = true + } else if sig.Results().Len() != 2 { + return fmt.Errorf("method has wrong number of args") + } + params := sig.Params() + // If the first argument is the context, remove it from the comparison and set + // the MethodHasContext flag so that the context will be passed to this model's method + if params.Len() > 0 && params.At(0).Type().String() == "context.Context" { + f.MethodHasContext = true + vars := make([]*types.Var, params.Len()-1) + for i := 1; i < params.Len(); i++ { + vars[i-1] = params.At(i) + } + params = types.NewTuple(vars...) + } + + if err = b.bindArgs(f, params); err != nil { + return errors.Wrapf(err, "%s:%d", pos.Filename, pos.Line) + } + + result := sig.Results().At(0) + tr, err := b.Binder.TypeReference(f.Type, result.Type()) + if err != nil { + return err + } + + // success, args and return type match. Bind to method + f.GoFieldType = GoFieldMethod + f.GoReceiverName = "obj" + f.GoFieldName = target.Name() + f.TypeReference = tr + + return nil + + case *types.Var: + tr, err := b.Binder.TypeReference(f.Type, target.Type()) + if err != nil { + return err + } + + // success, bind to var + f.GoFieldType = GoFieldVariable + f.GoReceiverName = "obj" + f.GoFieldName = target.Name() + f.TypeReference = tr + + return nil + default: + panic(fmt.Errorf("unknown bind target %T for %s", target, f.Name)) + } +} + +// findField attempts to match the name to a struct field with the following +// priorites: +// 1. Any method with a matching name +// 2. Any Fields with a struct tag (see config.StructTag) +// 3. Any fields with a matching name +// 4. Same logic again for embedded fields +func (b *builder) findBindTarget(named *types.Named, name string) (types.Object, error) { + for i := 0; i < named.NumMethods(); i++ { + method := named.Method(i) + if !method.Exported() { + continue + } + + if !strings.EqualFold(method.Name(), name) { + continue + } + + return method, nil + } + + strukt, ok := named.Underlying().(*types.Struct) + if !ok { + return nil, fmt.Errorf("not a struct") + } + return b.findBindStructTarget(strukt, name) +} + +func (b *builder) findBindStructTarget(strukt *types.Struct, name string) (types.Object, error) { + // struct tags have the highest priority + if b.Config.StructTag != "" { + var foundField *types.Var + for i := 0; i < strukt.NumFields(); i++ { + field := strukt.Field(i) + if !field.Exported() { + continue + } + tags := reflect.StructTag(strukt.Tag(i)) + if val, ok := tags.Lookup(b.Config.StructTag); ok && equalFieldName(val, name) { + if foundField != nil { + return nil, errors.Errorf("tag %s is ambigious; multiple fields have the same tag value of %s", b.Config.StructTag, val) + } + + foundField = field + } + } + if foundField != nil { + return foundField, nil + } + } + + // Then matching field names + for i := 0; i < strukt.NumFields(); i++ { + field := strukt.Field(i) + if !field.Exported() { + continue + } + if equalFieldName(field.Name(), name) { // aqui! + return field, nil + } + } + + // Then look in embedded structs + for i := 0; i < strukt.NumFields(); i++ { + field := strukt.Field(i) + if !field.Exported() { + continue + } + + if !field.Anonymous() { + continue + } + + fieldType := field.Type() + if ptr, ok := fieldType.(*types.Pointer); ok { + fieldType = ptr.Elem() + } + + switch fieldType := fieldType.(type) { + case *types.Named: + f, err := b.findBindTarget(fieldType, name) + if err != nil { + return nil, err + } + if f != nil { + return f, nil + } + case *types.Struct: + f, err := b.findBindStructTarget(fieldType, name) + if err != nil { + return nil, err + } + if f != nil { + return f, nil + } + default: + panic(fmt.Errorf("unknown embedded field type %T", field.Type())) + } + } + + return nil, nil +} + +func (f *Field) HasDirectives() bool { + return len(f.Directives) > 0 +} + +func (f *Field) IsReserved() bool { + return strings.HasPrefix(f.Name, "__") +} + +func (f *Field) IsMethod() bool { + return f.GoFieldType == GoFieldMethod +} + +func (f *Field) IsVariable() bool { + return f.GoFieldType == GoFieldVariable +} + +func (f *Field) IsMap() bool { + return f.GoFieldType == GoFieldMap +} + +func (f *Field) IsConcurrent() bool { + if f.Object.DisableConcurrency { + return false + } + return f.MethodHasContext || f.IsResolver +} + +func (f *Field) GoNameUnexported() string { + return templates.ToGoPrivate(f.Name) +} + +func (f *Field) ShortInvocation() string { + return fmt.Sprintf("%s().%s(%s)", f.Object.Definition.Name, f.GoFieldName, f.CallArgs()) +} + +func (f *Field) ArgsFunc() string { + if len(f.Args) == 0 { + return "" + } + + return "field_" + f.Object.Definition.Name + "_" + f.Name + "_args" +} + +func (f *Field) ResolverType() string { + if !f.IsResolver { + return "" + } + + return fmt.Sprintf("%s().%s(%s)", f.Object.Definition.Name, f.GoFieldName, f.CallArgs()) +} + +func (f *Field) ShortResolverDeclaration() string { + res := "(ctx context.Context" + + if !f.Object.Root { + res += fmt.Sprintf(", obj *%s", templates.CurrentImports.LookupType(f.Object.Type)) + } + for _, arg := range f.Args { + res += fmt.Sprintf(", %s %s", arg.VarName, templates.CurrentImports.LookupType(arg.TypeReference.GO)) + } + + result := templates.CurrentImports.LookupType(f.TypeReference.GO) + if f.Object.Stream { + result = "<-chan " + result + } + + res += fmt.Sprintf(") (%s, error)", result) + return res +} + +func (f *Field) ComplexitySignature() string { + res := fmt.Sprintf("func(childComplexity int") + for _, arg := range f.Args { + res += fmt.Sprintf(", %s %s", arg.VarName, templates.CurrentImports.LookupType(arg.TypeReference.GO)) + } + res += ") int" + return res +} + +func (f *Field) ComplexityArgs() string { + var args []string + for _, arg := range f.Args { + args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")") + } + + return strings.Join(args, ", ") +} + +func (f *Field) CallArgs() string { + var args []string + + if f.IsResolver { + args = append(args, "rctx") + + if !f.Object.Root { + args = append(args, "obj") + } + } else { + if f.MethodHasContext { + args = append(args, "ctx") + } + } + + for _, arg := range f.Args { + args = append(args, "args["+strconv.Quote(arg.Name)+"].("+templates.CurrentImports.LookupType(arg.TypeReference.GO)+")") + } + + return strings.Join(args, ", ") +} diff --git a/codegen/templates/field.gotpl b/codegen/field.gotpl similarity index 55% rename from codegen/templates/field.gotpl rename to codegen/field.gotpl index 3df847fa98..9718a08aad 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/field.gotpl @@ -1,19 +1,19 @@ -{{ $field := . }} -{{ $object := $field.Object }} +{{- range $object := .Objects }}{{- range $field := $object.Fields }} {{- if $object.Stream }} - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Field: field, + Args: nil, + }) {{- if $field.Args }} rawArgs := field.ArgumentMap(ec.Variables) - args, err := {{ $field.ArgsFunc }}(rawArgs) + args, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs) if err != nil { ec.Error(ctx, err) return nil } {{- end }} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Field: field, - }) // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 // and Tracer stack rctx := ctx @@ -27,35 +27,51 @@ if !ok { return nil } - var out graphql.OrderedMap - out.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }()) - return &out + return graphql.WriterFunc(func(w io.Writer) { + w.Write([]byte{'{'}) + graphql.MarshalString(field.Alias).MarshalGQL(w) + w.Write([]byte{':'}) + ec.{{ $field.TypeReference.MarshalFunc }}(ctx, field.Selections, res).MarshalGQL(w) + w.Write([]byte{'}'}) + }) } } {{ else }} - // nolint: vetshadow - func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{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}}) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func () { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: {{$object.Name|quote}}, + Field: field, + Args: nil, + IsMethod: {{or $field.IsMethod $field.IsResolver}}, + } + ctx = graphql.WithResolverContext(ctx, rctx) {{- if $field.Args }} rawArgs := field.ArgumentMap(ec.Variables) - args, err := {{ $field.ArgsFunc }}(rawArgs) + args, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } + rctx.Args = args {{- end }} - rctx := &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, - Args: {{if $field.Args }}args{{else}}nil{{end}}, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children {{- if $field.IsResolver }} return ec.resolvers.{{ $field.ShortInvocation }} + {{- else if $field.IsMap }} + switch v := {{$field.GoReceiverName}}[{{$field.Name|quote}}].(type) { + case {{$field.TypeReference.GO | ref}}: + return v, nil + case {{$field.TypeReference.Elem.GO | ref}}: + return &v, nil + case nil: + return ({{$field.TypeReference.GO | ref}})(nil), nil + default: + return nil, fmt.Errorf("unexpected type %T for field %s", v, {{ $field.Name | quote}}) + } {{- else if $field.IsMethod }} {{- if $field.NoErr }} return {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil @@ -67,16 +83,18 @@ {{- end }} }) if resTmp == nil { - {{- if $field.ASTType.NonNull }} + {{- if $field.TypeReference.GQL.NonNull }} if !ec.HasError(rctx) { ec.Errorf(ctx, "must not be null") } {{- end }} return graphql.Null } - res := resTmp.({{$field.Signature}}) + res := resTmp.({{$field.TypeReference.GO | ref}}) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - {{ $field.WriteJson }} + return ec.{{ $field.TypeReference.MarshalFunc }}(ctx, field.Selections, res) } {{ end }} + +{{- end }}{{- end}} diff --git a/codegen/util_test.go b/codegen/field_test.go similarity index 73% rename from codegen/util_test.go rename to codegen/field_test.go index 37b54c4c4f..6702a60697 100644 --- a/codegen/util_test.go +++ b/codegen/field_test.go @@ -8,17 +8,10 @@ import ( "go/types" "testing" + "github.com/99designs/gqlgen/codegen/config" "github.com/stretchr/testify/require" ) -func TestNormalizeVendor(t *testing.T) { - require.Equal(t, "bar/baz", normalizeVendor("foo/vendor/bar/baz")) - require.Equal(t, "[]bar/baz", normalizeVendor("[]foo/vendor/bar/baz")) - require.Equal(t, "*bar/baz", normalizeVendor("*foo/vendor/bar/baz")) - require.Equal(t, "*[]*bar/baz", normalizeVendor("*[]*foo/vendor/bar/baz")) - require.Equal(t, "[]*bar/baz", normalizeVendor("[]*foo/vendor/bar/baz")) -} - func TestFindField(t *testing.T) { input := ` package test @@ -71,8 +64,8 @@ type Embed struct { } for _, tt := range tests { - tt := tt - field, err := findField(tt.Struct, tt.Field, tt.Tag) + b := builder{Config: &config.Config{StructTag: tt.Tag}} + field, err := b.findBindStructTarget(tt.Struct, tt.Field) if tt.ShouldError { require.Nil(t, field, tt.Name) require.Error(t, err, tt.Name) @@ -121,24 +114,3 @@ func TestEqualFieldName(t *testing.T) { }) } } - -func TestEqualTypes(t *testing.T) { - tt := []struct { - Name string - Source string - Target string - Expected bool - }{ - {Name: "basic", Source: "bar/baz", Target: "bar/baz", Expected: true}, - {Name: "basic slice", Source: "[]bar/baz", Target: "[]bar/baz", Expected: true}, - {Name: "pointer", Source: "*bar/baz", Target: "bar/baz", Expected: true}, - {Name: "pointer slice", Source: "[]*bar/baz", Target: "[]bar/baz", Expected: true}, - } - - for _, tc := range tt { - t.Run(tc.Name, func(t *testing.T) { - result := equalTypes(tc.Source, tc.Target) - require.Equal(t, tc.Expected, result) - }) - } -} diff --git a/codegen/generate.go b/codegen/generate.go new file mode 100644 index 0000000000..eafa3f8743 --- /dev/null +++ b/codegen/generate.go @@ -0,0 +1,15 @@ +package codegen + +import ( + "github.com/99designs/gqlgen/codegen/templates" +) + +func GenerateCode(data *Data) error { + return templates.Render(templates.Options{ + PackageName: data.Config.Exec.Package, + Filename: data.Config.Exec.Filename, + Data: data, + RegionTags: true, + GeneratedHeader: true, + }) +} diff --git a/codegen/templates/generated.gotpl b/codegen/generated!.gotpl similarity index 67% rename from codegen/templates/generated.gotpl rename to codegen/generated!.gotpl index a37a1613e9..dce8ce977c 100644 --- a/codegen/templates/generated.gotpl +++ b/codegen/generated!.gotpl @@ -1,24 +1,17 @@ -// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. +{{ reserveImport "context" }} +{{ reserveImport "fmt" }} +{{ reserveImport "io" }} +{{ reserveImport "strconv" }} +{{ reserveImport "time" }} +{{ reserveImport "sync" }} +{{ reserveImport "errors" }} +{{ reserveImport "bytes" }} -package {{ .PackageName }} +{{ reserveImport "github.com/vektah/gqlparser" }} +{{ reserveImport "github.com/vektah/gqlparser/ast" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} -import ( - %%%IMPORTS%%% - - {{ reserveImport "context" }} - {{ reserveImport "fmt" }} - {{ reserveImport "io" }} - {{ reserveImport "strconv" }} - {{ reserveImport "time" }} - {{ reserveImport "sync" }} - {{ reserveImport "errors" }} - {{ reserveImport "bytes" }} - - {{ reserveImport "github.com/vektah/gqlparser" }} - {{ reserveImport "github.com/vektah/gqlparser/ast" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} -) // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { @@ -38,7 +31,7 @@ type Config struct { type ResolverRoot interface { {{- range $object := .Objects -}} {{ if $object.HasResolvers -}} - {{$object.GQLType}}() {{$object.GQLType}}Resolver + {{$object.Name}}() {{$object.Name}}Resolver {{ end }} {{- end }} } @@ -52,10 +45,10 @@ type DirectiveRoot struct { type ComplexityRoot struct { {{ range $object := .Objects }} {{ if not $object.IsReserved -}} - {{ $object.GQLType|toCamel }} struct { - {{ range $field := $object.Fields -}} + {{ $object.Name|go }} struct { + {{ range $field := $object.UniqueFields -}} {{ if not $field.IsReserved -}} - {{ $field.GQLName|toCamel }} {{ $field.ComplexitySignature }} + {{ $field.GoFieldName }} {{ $field.ComplexitySignature }} {{ end }} {{- end }} } @@ -65,32 +58,16 @@ type ComplexityRoot struct { {{ range $object := .Objects -}} {{ if $object.HasResolvers }} - type {{$object.GQLType}}Resolver interface { + type {{$object.Name}}Resolver interface { {{ range $field := $object.Fields -}} - {{ $field.ShortResolverDeclaration }} + {{- if $field.IsResolver }} + {{- $field.GoFieldName}}{{ $field.ShortResolverDeclaration }} + {{- end }} {{ end }} } {{- end }} {{- end }} -{{ range $object := .Objects -}} - {{ range $field := $object.Fields -}} - {{ if $field.Args }} - func {{ $field.ArgsFunc }}(rawArgs map[string]interface{}) (map[string]interface{}, error) { - {{ template "args.gotpl" $field.Args }} - } - {{ end }} - {{ end }} -{{- end }} - -{{ range $directive := .Directives }} - {{ if $directive.Args }} - func {{ $directive.ArgsFunc }}(rawArgs map[string]interface{}) (map[string]interface{}, error) { - {{ template "args.gotpl" $directive.Args }} - } - {{ end }} -{{ end }} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -102,22 +79,24 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { {{ range $object := .Objects }} {{ if not $object.IsReserved }} - {{ range $field := $object.Fields }} + {{ range $field := $object.UniqueFields }} {{ if not $field.IsReserved }} - case "{{$object.GQLType}}.{{$field.GQLName}}": - if e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil { + case "{{$object.Name}}.{{$field.GoFieldName}}": + if e.complexity.{{$object.Name|go}}.{{$field.GoFieldName}} == nil { break } {{ if $field.Args }} - args, err := {{ $field.ArgsFunc }}(rawArgs) + args, err := ec.{{ $field.ArgsFunc }}(context.TODO(),rawArgs) if err != nil { return 0, false } {{ end }} - return e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true + return e.complexity.{{$object.Name|go}}.{{$field.GoFieldName}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true {{ end }} {{ end }} {{ end }} @@ -131,7 +110,7 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio ec := executionContext{graphql.GetRequestContext(ctx), e} buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte { - data := ec._{{.QueryRoot.GQLType}}(ctx, op.SelectionSet) + data := ec._{{.QueryRoot.Name}}(ctx, op.SelectionSet) var buf bytes.Buffer data.MarshalGQL(&buf) return buf.Bytes() @@ -140,7 +119,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions, } + Extensions: ec.Extensions, + } {{- else }} return graphql.ErrorResponse(ctx, "queries are not supported") {{- end }} @@ -151,7 +131,7 @@ func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefini ec := executionContext{graphql.GetRequestContext(ctx), e} buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte { - data := ec._{{.MutationRoot.GQLType}}(ctx, op.SelectionSet) + data := ec._{{.MutationRoot.Name}}(ctx, op.SelectionSet) var buf bytes.Buffer data.MarshalGQL(&buf) return buf.Bytes() @@ -171,7 +151,7 @@ func (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDe {{- if .SubscriptionRoot }} ec := executionContext{graphql.GetRequestContext(ctx), e} - next := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.SelectionSet) + next := ec._{{.SubscriptionRoot.Name}}(ctx, op.SelectionSet) if ec.Errors != nil { return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors}) } @@ -209,22 +189,6 @@ type executionContext struct { *executableSchema } -{{- range $object := .Objects }} - {{ template "object.gotpl" $object }} - - {{- range $field := $object.Fields }} - {{ template "field.gotpl" $field }} - {{ end }} -{{- end}} - -{{- range $interface := .Interfaces }} - {{ template "interface.gotpl" $interface }} -{{- end }} - -{{- range $input := .Inputs }} - {{ template "input.gotpl" $input }} -{{- end }} - func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { defer func() { if r := recover(); r != nil { @@ -241,7 +205,7 @@ func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{} if ec.directives.{{$directive.Name|ucFirst}} != nil { {{- if $directive.Args }} rawArgs := d.ArgumentMap(ec.Variables) - args, err := {{ $directive.ArgsFunc }}(rawArgs) + args, err := ec.{{ $directive.ArgsFunc }}(ctx,rawArgs) if err != nil { ec.Error(ctx, err) return nil @@ -279,7 +243,7 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var parsedSchema = gqlparser.MustLoadSchema( - {{- range $filename, $schema := .SchemaRaw }} + {{- range $filename, $schema := .SchemaStr }} &ast.Source{Name: {{$filename|quote}}, Input: {{$schema|rawQuote}}}, {{- end }} ) diff --git a/codegen/input.gotpl b/codegen/input.gotpl new file mode 100644 index 0000000000..c8ac7ad3a5 --- /dev/null +++ b/codegen/input.gotpl @@ -0,0 +1,56 @@ +{{- range $input := .Inputs }} + {{- if not .HasUnmarshal }} + func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, v interface{}) ({{.Type | ref}}, error) { + var it {{.Type | ref}} + var asMap = v.(map[string]interface{}) + {{ range $field := .Fields}} + {{- if $field.Default}} + if _, present := asMap[{{$field.Name|quote}}] ; !present { + asMap[{{$field.Name|quote}}] = {{ $field.Default | dump }} + } + {{- end}} + {{- end }} + + for k, v := range asMap { + switch k { + {{- range $field := .Fields }} + case {{$field.Name|quote}}: + var err error + {{- if $field.Directives }} + getField0 := func(ctx context.Context) (interface{}, error) { return ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) } + + {{- range $i, $directive := $field.Directives }} + getField{{add $i 1}} := func(ctx context.Context) (res interface{}, err error) { + {{- range $dArg := $directive.Args }} + {{- if and $dArg.TypeReference.IsPtr ( notNil "Value" $dArg ) }} + {{ $dArg.VarName }} := {{ $dArg.Value | dump }} + {{- end }} + {{- end }} + n := getField{{$i}} + return ec.directives.{{$directive.Name|ucFirst}}({{$directive.ResolveArgs "it" "n" }}) + } + {{- end }} + + tmp, err := getField{{$field.Directives|len}}(ctx) + if err != nil { + return it, err + } + if data, ok := tmp.({{ $field.TypeReference.GO | ref }}) ; ok { + it.{{$field.GoFieldName}} = data + } else { + return it, fmt.Errorf(`unexpected type %T from directive, should be {{ $field.TypeReference.GO }}`, tmp) + } + {{- else }} + it.{{$field.GoFieldName}}, err = ec.{{ $field.TypeReference.UnmarshalFunc }}(ctx, v) + if err != nil { + return it, err + } + {{- end }} + {{- end }} + } + } + + return it, nil + } + {{- end }} +{{ end }} diff --git a/codegen/input_build.go b/codegen/input_build.go deleted file mode 100644 index 70fa564da9..0000000000 --- a/codegen/input_build.go +++ /dev/null @@ -1,96 +0,0 @@ -package codegen - -import ( - "go/types" - "sort" - - "github.com/pkg/errors" - "github.com/vektah/gqlparser/ast" - "golang.org/x/tools/go/loader" -) - -func (cfg *Config) buildInputs(namedTypes NamedTypes, prog *loader.Program) (Objects, error) { - var inputs Objects - - for _, typ := range cfg.schema.Types { - switch typ.Kind { - case ast.InputObject: - input, err := cfg.buildInput(namedTypes, typ) - if err != nil { - return nil, err - } - - def, err := findGoType(prog, input.Package, input.GoType) - if err != nil { - return nil, errors.Wrap(err, "cannot find type") - } - if def != nil { - input.Marshaler = buildInputMarshaler(typ, def) - bindErrs := bindObject(def.Type(), input, cfg.StructTag) - if len(bindErrs) > 0 { - return nil, bindErrs - } - } - - inputs = append(inputs, input) - } - } - - sort.Slice(inputs, func(i, j int) bool { - return inputs[i].GQLType < inputs[j].GQLType - }) - - return inputs, nil -} - -func (cfg *Config) buildInput(types NamedTypes, typ *ast.Definition) (*Object, error) { - obj := &Object{NamedType: types[typ.Name]} - typeEntry, entryExists := cfg.Models[typ.Name] - - for _, field := range typ.Fields { - newField := Field{ - GQLName: field.Name, - Type: types.getType(field.Type), - Object: obj, - } - - if entryExists { - if typeField, ok := typeEntry.Fields[field.Name]; ok { - newField.GoFieldName = typeField.FieldName - } - } - - if field.DefaultValue != nil { - var err error - newField.Default, err = field.DefaultValue.Value(nil) - if err != nil { - return nil, errors.Errorf("default value for %s.%s is not valid: %s", typ.Name, field.Name, err.Error()) - } - } - - if !newField.Type.IsInput && !newField.Type.IsScalar { - return nil, errors.Errorf("%s cannot be used as a field of %s. only input and scalar types are allowed", newField.GQLType, obj.GQLType) - } - - obj.Fields = append(obj.Fields, newField) - - } - return obj, nil -} - -// if user has implemented an UnmarshalGQL method on the input type manually, use it -// otherwise we will generate one. -func buildInputMarshaler(typ *ast.Definition, def types.Object) *Ref { - switch def := def.(type) { - case *types.TypeName: - namedType := def.Type().(*types.Named) - for i := 0; i < namedType.NumMethods(); i++ { - method := namedType.Method(i) - if method.Name() == "UnmarshalGQL" { - return nil - } - } - } - - return &Ref{GoType: typ.Name} -} diff --git a/codegen/input_test.go b/codegen/input_test.go deleted file mode 100644 index af2a7fc928..0000000000 --- a/codegen/input_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package codegen - -import ( - "testing" - - "github.com/stretchr/testify/require" - "golang.org/x/tools/go/loader" -) - -func TestTypeUnionAsInput(t *testing.T) { - err := generate("inputunion", ` - type Query { - addBookmark(b: Bookmarkable!): Boolean! - } - type Item {name: String} - union Bookmarkable = Item - `) - - require.EqualError(t, err, "model plan failed: Bookmarkable! cannot be used as argument of Query.addBookmark. only input and scalar types are allowed") -} - -func TestTypeInInput(t *testing.T) { - err := generate("typeinput", ` - type Query { - addBookmark(b: BookmarkableInput!): Boolean! - } - type Item {name: String} - input BookmarkableInput { - item: Item - } - `) - - require.EqualError(t, err, "model plan failed: Item cannot be used as a field of BookmarkableInput. only input and scalar types are allowed") -} - -func generate(name string, schema string, typemap ...TypeMap) error { - cfg := Config{ - SchemaFilename: SchemaFilenames{"schema.graphql"}, - SchemaStr: map[string]string{"schema.graphql": schema}, - Exec: PackageConfig{Filename: "gen/" + name + "/exec.go"}, - Model: PackageConfig{Filename: "gen/" + name + "/model.go"}, - } - - if len(typemap) > 0 { - cfg.Models = typemap[0] - } - err := Generate(cfg) - if err == nil { - conf := loader.Config{} - conf.Import("github.com/99designs/gqlgen/codegen/testdata/gen/" + name) - - _, err = conf.Load() - if err != nil { - panic(err) - } - } - return err -} diff --git a/codegen/interface.go b/codegen/interface.go index 2de0c88a9b..f59e8ed071 100644 --- a/codegen/interface.go +++ b/codegen/interface.go @@ -1,13 +1,63 @@ package codegen -type Interface struct { - *NamedType +import ( + "go/types" + + "github.com/vektah/gqlparser/ast" +) +type Interface struct { + *ast.Definition + Type types.Type Implementors []InterfaceImplementor + InTypemap bool } type InterfaceImplementor struct { - ValueReceiver bool + *ast.Definition + + Interface *Interface + Type types.Type +} + +func (b *builder) buildInterface(typ *ast.Definition) *Interface { + obj, err := b.Binder.DefaultUserObject(typ.Name) + if err != nil { + panic(err) + } + + i := &Interface{ + Definition: typ, + Type: obj, + InTypemap: b.Config.Models.UserDefined(typ.Name), + } + + for _, implementor := range b.Schema.GetPossibleTypes(typ) { + obj, err := b.Binder.DefaultUserObject(implementor.Name) + if err != nil { + panic(err) + } + + i.Implementors = append(i.Implementors, InterfaceImplementor{ + Definition: implementor, + Type: obj, + Interface: i, + }) + } + + return i +} + +func (i *InterfaceImplementor) ValueReceiver() bool { + interfaceType, err := findGoInterface(i.Interface.Type) + if interfaceType == nil || err != nil { + return true + } + + implementorType, err := findGoNamedType(i.Type) + if implementorType == nil || err != nil { + return true + } - *NamedType + return types.Implements(implementorType, interfaceType) } diff --git a/codegen/interface.gotpl b/codegen/interface.gotpl new file mode 100644 index 0000000000..81a5807653 --- /dev/null +++ b/codegen/interface.gotpl @@ -0,0 +1,20 @@ +{{- range $interface := .Interfaces }} + +func (ec *executionContext) _{{$interface.Name}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.Type | ref}}) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: + return graphql.Null + {{- range $implementor := $interface.Implementors }} + {{- if $implementor.ValueReceiver }} + case {{$implementor.Type | ref}}: + return ec._{{$implementor.Name}}(ctx, sel, &obj) + {{- end}} + case *{{$implementor.Type | ref}}: + return ec._{{$implementor.Name}}(ctx, sel, obj) + {{- end }} + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + +{{- end }} diff --git a/codegen/interface_build.go b/codegen/interface_build.go deleted file mode 100644 index 92052ba6b9..0000000000 --- a/codegen/interface_build.go +++ /dev/null @@ -1,53 +0,0 @@ -package codegen - -import ( - "go/types" - "sort" - - "github.com/vektah/gqlparser/ast" - "golang.org/x/tools/go/loader" -) - -func (cfg *Config) buildInterfaces(types NamedTypes, prog *loader.Program) []*Interface { - var interfaces []*Interface - for _, typ := range cfg.schema.Types { - if typ.Kind == ast.Union || typ.Kind == ast.Interface { - interfaces = append(interfaces, cfg.buildInterface(types, typ, prog)) - } - } - - sort.Slice(interfaces, func(i, j int) bool { - return interfaces[i].GQLType < interfaces[j].GQLType - }) - - return interfaces -} - -func (cfg *Config) buildInterface(types NamedTypes, typ *ast.Definition, prog *loader.Program) *Interface { - i := &Interface{NamedType: types[typ.Name]} - - for _, implementor := range cfg.schema.GetPossibleTypes(typ) { - t := types[implementor.Name] - - i.Implementors = append(i.Implementors, InterfaceImplementor{ - NamedType: t, - ValueReceiver: cfg.isValueReceiver(types[typ.Name], t, prog), - }) - } - - return i -} - -func (cfg *Config) isValueReceiver(intf *NamedType, implementor *NamedType, prog *loader.Program) bool { - interfaceType, err := findGoInterface(prog, intf.Package, intf.GoType) - if interfaceType == nil || err != nil { - return true - } - - implementorType, err := findGoNamedType(prog, implementor.Package, implementor.GoType) - if implementorType == nil || err != nil { - return true - } - - return types.Implements(implementorType, interfaceType) -} diff --git a/codegen/model.go b/codegen/model.go deleted file mode 100644 index bcdc8703a6..0000000000 --- a/codegen/model.go +++ /dev/null @@ -1,17 +0,0 @@ -package codegen - -type Model struct { - *NamedType - Description string - Fields []ModelField - Implements []*NamedType -} - -type ModelField struct { - *Type - GQLName string - GoFieldName string - GoFKName string - GoFKType string - Description string -} diff --git a/codegen/models_build.go b/codegen/models_build.go deleted file mode 100644 index 56d2ff1fae..0000000000 --- a/codegen/models_build.go +++ /dev/null @@ -1,91 +0,0 @@ -package codegen - -import ( - "sort" - - "github.com/vektah/gqlparser/ast" - "golang.org/x/tools/go/loader" -) - -func (cfg *Config) buildModels(types NamedTypes, prog *loader.Program) ([]Model, error) { - var models []Model - - for _, typ := range cfg.schema.Types { - var model Model - switch typ.Kind { - case ast.Object: - obj, err := cfg.buildObject(types, typ) - if err != nil { - return nil, err - } - if obj.Root || obj.IsUserDefined { - continue - } - model = cfg.obj2Model(obj) - case ast.InputObject: - obj, err := cfg.buildInput(types, typ) - if err != nil { - return nil, err - } - if obj.IsUserDefined { - continue - } - model = cfg.obj2Model(obj) - case ast.Interface, ast.Union: - intf := cfg.buildInterface(types, typ, prog) - if intf.IsUserDefined { - continue - } - model = int2Model(intf) - default: - continue - } - model.Description = typ.Description // It's this or change both obj2Model and buildObject - - models = append(models, model) - } - - sort.Slice(models, func(i, j int) bool { - return models[i].GQLType < models[j].GQLType - }) - - return models, nil -} - -func (cfg *Config) obj2Model(obj *Object) Model { - model := Model{ - NamedType: obj.NamedType, - Implements: obj.Implements, - Fields: []ModelField{}, - } - - model.GoType = ucFirst(obj.GQLType) - model.Marshaler = &Ref{GoType: obj.GoType} - - for i := range obj.Fields { - field := &obj.Fields[i] - mf := ModelField{Type: field.Type, GQLName: field.GQLName} - - if field.GoFieldName != "" { - mf.GoFieldName = field.GoFieldName - } else { - mf.GoFieldName = field.GoNameExported() - } - - model.Fields = append(model.Fields, mf) - } - - return model -} - -func int2Model(obj *Interface) Model { - model := Model{ - NamedType: obj.NamedType, - Fields: []ModelField{}, - } - - model.GoType = ucFirst(obj.GQLType) - model.Marshaler = &Ref{GoType: obj.GoType} - - return model -} diff --git a/codegen/object.go b/codegen/object.go index 656af297a0..539c3164c5 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -1,13 +1,13 @@ package codegen import ( - "bytes" - "fmt" + "go/types" "strconv" "strings" - "text/template" "unicode" + "github.com/99designs/gqlgen/codegen/config" + "github.com/pkg/errors" "github.com/vektah/gqlparser/ast" ) @@ -17,337 +17,150 @@ const ( GoFieldUndefined GoFieldType = iota GoFieldMethod GoFieldVariable + GoFieldMap ) type Object struct { - *NamedType + *ast.Definition - Fields []Field - Satisfies []string - Implements []*NamedType - ResolverInterface *Ref + Type types.Type + ResolverInterface types.Type Root bool + Fields []*Field + Implements []*ast.Definition DisableConcurrency bool Stream bool + Directives []*Directive } -type Field struct { - *Type - Description string // Description of a field - GQLName string // The name of the field in graphql - GoFieldType GoFieldType // The field type in go, if any - GoReceiverName string // The name of method & var receiver in go, if any - GoFieldName string // The name of the method or var in go, if any - Args []FieldArgument // A list of arguments to be passed to this field - ForceResolver bool // Should be emit Resolver method - MethodHasContext bool // If this is bound to a go method, does the method also take a context - NoErr bool // If this is bound to a go method, does that method have an error as the second argument - Object *Object // A link back to the parent object - Default interface{} // The default value -} - -type FieldArgument struct { - *Type - - GQLName string // The name of the argument in graphql - GoVarName string // The name of the var in go - Object *Object // A link back to the parent object - Default interface{} // The default value -} - -type Objects []*Object - -func (o *Object) Implementors() string { - satisfiedBy := strconv.Quote(o.GQLType) - for _, s := range o.Satisfies { - satisfiedBy += ", " + strconv.Quote(s) - } - return "[]string{" + satisfiedBy + "}" -} - -func (o *Object) HasResolvers() bool { - for _, f := range o.Fields { - if f.IsResolver() { - return true +func (b *builder) buildObject(typ *ast.Definition) (*Object, error) { + dirs, err := b.getDirectives(typ.Directives) + if err != nil { + return nil, errors.Wrap(err, typ.Name) + } + + obj := &Object{ + Definition: typ, + Root: b.Schema.Query == typ || b.Schema.Mutation == typ || b.Schema.Subscription == typ, + DisableConcurrency: typ == b.Schema.Mutation, + Stream: typ == b.Schema.Subscription, + Directives: dirs, + ResolverInterface: types.NewNamed( + types.NewTypeName(0, b.Config.Exec.Pkg(), typ.Name+"Resolver", nil), + nil, + nil, + ), + } + + if !obj.Root { + goObject, err := b.Binder.DefaultUserObject(typ.Name) + if err != nil { + return nil, err } + obj.Type = goObject } - return false -} -func (o *Object) IsConcurrent() bool { - for _, f := range o.Fields { - if f.IsConcurrent() { - return true - } + for _, intf := range b.Schema.GetImplements(typ) { + obj.Implements = append(obj.Implements, b.Schema.Types[intf.Name]) } - return false -} - -func (o *Object) IsReserved() bool { - return strings.HasPrefix(o.GQLType, "__") -} -func (f *Field) IsResolver() bool { - return f.GoFieldName == "" -} - -func (f *Field) IsReserved() bool { - return strings.HasPrefix(f.GQLName, "__") -} - -func (f *Field) IsMethod() bool { - return f.GoFieldType == GoFieldMethod -} + for _, field := range typ.Fields { + if strings.HasPrefix(field.Name, "__") { + continue + } -func (f *Field) IsVariable() bool { - return f.GoFieldType == GoFieldVariable -} + var f *Field + f, err = b.buildField(obj, field) + if err != nil { + return nil, err + } -func (f *Field) IsConcurrent() bool { - if f.Object.DisableConcurrency { - return false + obj.Fields = append(obj.Fields, f) } - return f.MethodHasContext || f.IsResolver() -} -func (f *Field) GoNameExported() string { - return lintName(ucFirst(f.GQLName)) + return obj, nil } -func (f *Field) GoNameUnexported() string { - return lintName(f.GQLName) -} - -func (f *Field) ShortInvocation() string { - if !f.IsResolver() { - return "" +func (o *Object) Reference() types.Type { + switch o.Type.(type) { + case *types.Pointer, *types.Slice, *types.Map: + return o.Type } - return fmt.Sprintf("%s().%s(%s)", f.Object.GQLType, f.GoNameExported(), f.CallArgs()) + return types.NewPointer(o.Type) } -func (f *Field) ArgsFunc() string { - if len(f.Args) == 0 { - return "" - } - - return "field_" + f.Object.GQLType + "_" + f.GQLName + "_args" -} +type Objects []*Object -func (f *Field) ResolverType() string { - if !f.IsResolver() { - return "" +func (o *Object) Implementors() string { + satisfiedBy := strconv.Quote(o.Name) + for _, s := range o.Implements { + satisfiedBy += ", " + strconv.Quote(s.Name) } - - return fmt.Sprintf("%s().%s(%s)", f.Object.GQLType, f.GoNameExported(), f.CallArgs()) + return "[]string{" + satisfiedBy + "}" } -func (f *Field) ShortResolverDeclaration() string { - if !f.IsResolver() { - return "" - } - res := fmt.Sprintf("%s(ctx context.Context", f.GoNameExported()) - - if !f.Object.Root { - res += fmt.Sprintf(", obj *%s", f.Object.FullName()) - } - for _, arg := range f.Args { - res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) - } - - result := f.Signature() - if f.Object.Stream { - result = "<-chan " + result +func (o *Object) HasResolvers() bool { + for _, f := range o.Fields { + if f.IsResolver { + return true + } } - - res += fmt.Sprintf(") (%s, error)", result) - return res + return false } -func (f *Field) ResolverDeclaration() string { - if !f.IsResolver() { - return "" - } - res := fmt.Sprintf("%s_%s(ctx context.Context", f.Object.GQLType, f.GoNameUnexported()) - - if !f.Object.Root { - res += fmt.Sprintf(", obj *%s", f.Object.FullName()) +func (o *Object) HasUnmarshal() bool { + if o.Type == config.MapType { + return true } - for _, arg := range f.Args { - res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) - } - - result := f.Signature() - if f.Object.Stream { - result = "<-chan " + result + for i := 0; i < o.Type.(*types.Named).NumMethods(); i++ { + switch o.Type.(*types.Named).Method(i).Name() { + case "UnmarshalGQL": + return true + } } - - res += fmt.Sprintf(") (%s, error)", result) - return res + return false } -func (f *Field) ComplexitySignature() string { - res := fmt.Sprintf("func(childComplexity int") - for _, arg := range f.Args { - res += fmt.Sprintf(", %s %s", arg.GoVarName, arg.Signature()) +func (o *Object) HasDirectives() bool { + if len(o.Directives) > 0 { + return true } - res += ") int" - return res -} - -func (f *Field) ComplexityArgs() string { - var args []string - for _, arg := range f.Args { - args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")") + for _, f := range o.Fields { + if f.HasDirectives() { + return true + } } - return strings.Join(args, ", ") + return false } -func (f *Field) CallArgs() string { - var args []string - - if f.IsResolver() { - args = append(args, "rctx") - - if !f.Object.Root { - args = append(args, "obj") - } - } else { - if f.MethodHasContext { - args = append(args, "ctx") +func (o *Object) IsConcurrent() bool { + for _, f := range o.Fields { + if f.IsConcurrent() { + return true } } - - for _, arg := range f.Args { - args = append(args, "args["+strconv.Quote(arg.GQLName)+"].("+arg.Signature()+")") - } - - return strings.Join(args, ", ") -} - -// should be in the template, but its recursive and has a bunch of args -func (f *Field) WriteJson() string { - return f.doWriteJson("res", f.Type.Modifiers, f.ASTType, false, 1) + return false } -func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Type, isPtr bool, depth int) string { - switch { - case len(remainingMods) > 0 && remainingMods[0] == modPtr: - return tpl(` - if {{.val}} == nil { - {{- if .nonNull }} - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - {{- end }} - return graphql.Null - } - {{.next }}`, map[string]interface{}{ - "val": val, - "nonNull": astType.NonNull, - "next": f.doWriteJson(val, remainingMods[1:], astType, true, depth+1), - }) - - case len(remainingMods) > 0 && remainingMods[0] == modList: - if isPtr { - val = "*" + val - } - var arr = "arr" + strconv.Itoa(depth) - var index = "idx" + strconv.Itoa(depth) - var usePtr bool - if len(remainingMods) == 1 && !isPtr { - usePtr = true - } - - return tpl(` - {{.arr}} := make(graphql.Array, len({{.val}})) - {{ if and .top (not .isScalar) }} var wg sync.WaitGroup {{ end }} - {{ if not .isScalar }} - isLen1 := len({{.val}}) == 1 - if !isLen1 { - wg.Add(len({{.val}})) - } - {{ end }} - for {{.index}} := range {{.val}} { - {{- if not .isScalar }} - {{.index}} := {{.index}} - rctx := &graphql.ResolverContext{ - Index: &{{.index}}, - Result: {{ if .usePtr }}&{{end}}{{.val}}[{{.index}}], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func({{.index}} int) { - if !isLen1 { - defer wg.Done() - } - {{.arr}}[{{.index}}] = func() graphql.Marshaler { - {{ .next }} - }() - } - if isLen1 { - f({{.index}}) - } else { - go f({{.index}}) - } - {{ else }} - {{.arr}}[{{.index}}] = func() graphql.Marshaler { - {{ .next }} - }() - {{- end}} - } - {{ if and .top (not .isScalar) }} wg.Wait() {{ end }} - return {{.arr}}`, map[string]interface{}{ - "val": val, - "arr": arr, - "index": index, - "top": depth == 1, - "arrayLen": len(val), - "isScalar": f.IsScalar, - "usePtr": usePtr, - "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1), - }) - - case f.IsScalar: - if isPtr { - val = "*" + val - } - return f.Marshal(val) - - default: - if !isPtr { - val = "&" + val - } - return tpl(` - return ec._{{.type}}(ctx, field.Selections, {{.val}})`, map[string]interface{}{ - "type": f.GQLType, - "val": val, - }) - } +func (o *Object) IsReserved() bool { + return strings.HasPrefix(o.Definition.Name, "__") } -func (f *FieldArgument) Stream() bool { - return f.Object != nil && f.Object.Stream +func (o *Object) Description() string { + return o.Definition.Description } func (os Objects) ByName(name string) *Object { for i, o := range os { - if strings.EqualFold(o.GQLType, name) { + if strings.EqualFold(o.Definition.Name, name) { return os[i] } } return nil } -func tpl(tpl string, vars map[string]interface{}) string { - b := &bytes.Buffer{} - err := template.Must(template.New("inline").Parse(tpl)).Execute(b, vars) - if err != nil { - panic(err) - } - return b.String() -} - func ucFirst(s string) string { if s == "" { return "" @@ -357,117 +170,3 @@ func ucFirst(s string) string { r[0] = unicode.ToUpper(r[0]) return string(r) } - -// copy from https://github.com/golang/lint/blob/06c8688daad7faa9da5a0c2f163a3d14aac986ca/lint.go#L679 - -// lintName returns a different name if it should be different. -func lintName(name string) (should string) { - // Fast path for simple cases: "_" and all lowercase. - if name == "_" { - return name - } - allLower := true - for _, r := range name { - if !unicode.IsLower(r) { - allLower = false - break - } - } - if allLower { - return name - } - - // Split camelCase at any lower->upper transition, and split on underscores. - // Check each word for common initialisms. - runes := []rune(name) - w, i := 0, 0 // index of start of word, scan - for i+1 <= len(runes) { - eow := false // whether we hit the end of a word - if i+1 == len(runes) { - eow = true - } else if runes[i+1] == '_' { - // underscore; shift the remainder forward over any run of underscores - eow = true - n := 1 - for i+n+1 < len(runes) && runes[i+n+1] == '_' { - n++ - } - - // Leave at most one underscore if the underscore is between two digits - if i+n+1 < len(runes) && unicode.IsDigit(runes[i]) && unicode.IsDigit(runes[i+n+1]) { - n-- - } - - copy(runes[i+1:], runes[i+n+1:]) - runes = runes[:len(runes)-n] - } else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) { - // lower->non-lower - eow = true - } - i++ - if !eow { - continue - } - - // [w,i) is a word. - word := string(runes[w:i]) - if u := strings.ToUpper(word); commonInitialisms[u] { - // Keep consistent case, which is lowercase only at the start. - if w == 0 && unicode.IsLower(runes[w]) { - u = strings.ToLower(u) - } - // All the common initialisms are ASCII, - // so we can replace the bytes exactly. - copy(runes[w:], []rune(u)) - } else if w > 0 && strings.ToLower(word) == word { - // already all lowercase, and not the first word, so uppercase the first character. - runes[w] = unicode.ToUpper(runes[w]) - } - w = i - } - return string(runes) -} - -// commonInitialisms is a set of common initialisms. -// Only add entries that are highly unlikely to be non-initialisms. -// For instance, "ID" is fine (Freudian code is rare), but "AND" is not. -var commonInitialisms = map[string]bool{ - "ACL": true, - "API": true, - "ASCII": true, - "CPU": true, - "CSS": true, - "DNS": true, - "EOF": true, - "GUID": true, - "HTML": true, - "HTTP": true, - "HTTPS": true, - "ID": true, - "IP": true, - "JSON": true, - "LHS": true, - "QPS": true, - "RAM": true, - "RHS": true, - "RPC": true, - "SLA": true, - "SMTP": true, - "SQL": true, - "SSH": true, - "TCP": true, - "TLS": true, - "TTL": true, - "UDP": true, - "UI": true, - "UID": true, - "UUID": true, - "URI": true, - "URL": true, - "UTF8": true, - "VM": true, - "XML": true, - "XMPP": true, - "XSRF": true, - "XSS": true, -} diff --git a/codegen/object.gotpl b/codegen/object.gotpl new file mode 100644 index 0000000000..19da1b1988 --- /dev/null +++ b/codegen/object.gotpl @@ -0,0 +1,77 @@ +{{- range $object := .Objects }} + +var {{ $object.Name|lcFirst}}Implementors = {{$object.Implementors}} + +{{- if .Stream }} +func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, {{$object.Name|lcFirst}}Implementors) + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: {{$object.Name|quote}}, + }) + if len(fields) != 1 { + ec.Errorf(ctx, "must subscribe to exactly one stream") + return nil + } + + switch fields[0].Name { + {{- range $field := $object.Fields }} + case "{{$field.Name}}": + return ec._{{$object.Name}}_{{$field.Name}}(ctx, fields[0]) + {{- end }} + default: + panic("unknown field " + strconv.Quote(fields[0].Name)) + } +} +{{- else }} +func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet{{ if not $object.Root }},obj {{$object.Reference | ref }}{{ end }}) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, {{$object.Name|lcFirst}}Implementors) + {{if $object.Root}} + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: {{$object.Name|quote}}, + }) + {{end}} + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString({{$object.Name|quote}}) + {{- range $field := $object.Fields }} + case "{{$field.Name}}": + {{- if $field.IsConcurrent }} + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) + {{- if $field.TypeReference.GQL.NonNull }} + if res == graphql.Null { + invalid = true + } + {{- end }} + return res + }) + {{- else }} + out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}}) + {{- if $field.TypeReference.GQL.NonNull }} + if out.Values[i] == graphql.Null { + invalid = true + } + {{- end }} + {{- end }} + {{- end }} + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } + return out +} +{{- end }} + +{{- end }} diff --git a/codegen/object_build.go b/codegen/object_build.go deleted file mode 100644 index 279d1eb6be..0000000000 --- a/codegen/object_build.go +++ /dev/null @@ -1,181 +0,0 @@ -package codegen - -import ( - "log" - "sort" - - "github.com/pkg/errors" - "github.com/vektah/gqlparser/ast" - "golang.org/x/tools/go/loader" -) - -func (cfg *Config) buildObjects(types NamedTypes, prog *loader.Program) (Objects, error) { - var objects Objects - - for _, typ := range cfg.schema.Types { - if typ.Kind != ast.Object { - continue - } - - obj, err := cfg.buildObject(types, typ) - if err != nil { - return nil, err - } - - def, err := findGoType(prog, obj.Package, obj.GoType) - if err != nil { - return nil, err - } - if def != nil { - for _, bindErr := range bindObject(def.Type(), obj, cfg.StructTag) { - log.Println(bindErr.Error()) - log.Println(" Adding resolver method") - } - } - - objects = append(objects, obj) - } - - sort.Slice(objects, func(i, j int) bool { - return objects[i].GQLType < objects[j].GQLType - }) - - return objects, nil -} - -var keywords = []string{ - "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", -} - -// sanitizeArgName prevents collisions with go keywords for arguments to resolver functions -func sanitizeArgName(name string) string { - for _, k := range keywords { - if name == k { - return name + "Arg" - } - } - return name -} - -func (cfg *Config) buildObject(types NamedTypes, typ *ast.Definition) (*Object, error) { - obj := &Object{NamedType: types[typ.Name]} - typeEntry, entryExists := cfg.Models[typ.Name] - - obj.ResolverInterface = &Ref{GoType: obj.GQLType + "Resolver"} - - if typ == cfg.schema.Query { - obj.Root = true - } - - if typ == cfg.schema.Mutation { - obj.Root = true - obj.DisableConcurrency = true - } - - if typ == cfg.schema.Subscription { - obj.Root = true - obj.Stream = true - } - - obj.Satisfies = append(obj.Satisfies, typ.Interfaces...) - - for _, intf := range cfg.schema.GetImplements(typ) { - obj.Implements = append(obj.Implements, types[intf.Name]) - } - - for _, field := range typ.Fields { - if typ == cfg.schema.Query && field.Name == "__type" { - obj.Fields = append(obj.Fields, Field{ - Type: &Type{types["__Schema"], []string{modPtr}, ast.NamedType("__Schema", nil), nil}, - GQLName: "__schema", - GoFieldType: GoFieldMethod, - GoReceiverName: "ec", - GoFieldName: "introspectSchema", - Object: obj, - Description: field.Description, - }) - continue - } - if typ == cfg.schema.Query && field.Name == "__schema" { - obj.Fields = append(obj.Fields, Field{ - Type: &Type{types["__Type"], []string{modPtr}, ast.NamedType("__Schema", nil), nil}, - GQLName: "__type", - GoFieldType: GoFieldMethod, - GoReceiverName: "ec", - GoFieldName: "introspectType", - Args: []FieldArgument{ - {GQLName: "name", Type: &Type{types["String"], []string{}, ast.NamedType("String", nil), nil}, Object: &Object{}}, - }, - Object: obj, - }) - continue - } - - var forceResolver bool - var goName string - if entryExists { - if typeField, ok := typeEntry.Fields[field.Name]; ok { - goName = typeField.FieldName - forceResolver = typeField.Resolver - } - } - - var args []FieldArgument - for _, arg := range field.Arguments { - newArg := FieldArgument{ - GQLName: arg.Name, - Type: types.getType(arg.Type), - Object: obj, - GoVarName: sanitizeArgName(arg.Name), - } - - if !newArg.Type.IsInput && !newArg.Type.IsScalar { - return nil, errors.Errorf("%s cannot be used as argument of %s.%s. only input and scalar types are allowed", arg.Type, obj.GQLType, field.Name) - } - - if arg.DefaultValue != nil { - var err error - newArg.Default, err = arg.DefaultValue.Value(nil) - if err != nil { - return nil, errors.Errorf("default value for %s.%s is not valid: %s", typ.Name, field.Name, err.Error()) - } - } - args = append(args, newArg) - } - - obj.Fields = append(obj.Fields, Field{ - GQLName: field.Name, - Type: types.getType(field.Type), - Args: args, - Object: obj, - GoFieldName: goName, - ForceResolver: forceResolver, - }) - } - - return obj, nil -} diff --git a/codegen/templates/args.gotpl b/codegen/templates/args.gotpl deleted file mode 100644 index 870a99edcb..0000000000 --- a/codegen/templates/args.gotpl +++ /dev/null @@ -1,13 +0,0 @@ - args := map[string]interface{}{} - {{- range $i, $arg := . }} - var arg{{$i}} {{$arg.Signature }} - if tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok { - var err error - {{$arg.Unmarshal (print "arg" $i) "tmp" }} - if err != nil { - return nil, err - } - } - args[{{$arg.GQLName|quote}}] = arg{{$i}} - {{- end }} - return args, nil diff --git a/codegen/templates/data.go b/codegen/templates/data.go deleted file mode 100644 index d3098aaae1..0000000000 --- a/codegen/templates/data.go +++ /dev/null @@ -1,13 +0,0 @@ -package templates - -var data = map[string]string{ - "args.gotpl": "\targs := map[string]interface{}{}\n\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := rawArgs[{{$arg.GQLName|quote}}]; ok {\n\t\t\tvar err error\n\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end }}\n\treturn args, nil\n", - "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler {\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := {{ $field.ArgsFunc }}(rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t{{- end }}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tField: field,\n\t\t})\n\t\t// FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259\n\t\t// and Tracer stack\n\t\trctx := ctx\n\t\tresults, err := ec.resolvers.{{ $field.ShortInvocation }}\n\t\tif err != nil {\n\t\t\tec.Error(ctx, err)\n\t\t\treturn nil\n\t\t}\n\t\treturn func() graphql.Marshaler {\n\t\t\tres, ok := <-results\n\t\t\tif !ok {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tvar out graphql.OrderedMap\n\t\t\tout.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }())\n\t\t\treturn &out\n\t\t}\n\t}\n{{ else }}\n\t// nolint: vetshadow\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler {\n\t\tctx = ec.Tracer.StartFieldExecution(ctx, field)\n\t\tdefer func () { ec.Tracer.EndFieldExecution(ctx) }()\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\targs, err := {{ $field.ArgsFunc }}(rawArgs)\n\t\t\tif err != nil {\n\t\t\t\tec.Error(ctx, err)\n\t\t\t\treturn graphql.Null\n\t\t\t}\n\t\t{{- end }}\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\tField: field,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\tctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {\n\t\t\tctx = rctx // use context from middleware stack in children\n\t\t\t{{- if $field.IsResolver }}\n\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t{{- end }}\n\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t{{- end }}\n\t\t})\n\t\tif resTmp == nil {\n\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\tif !ec.HasError(rctx) {\n\t\t\t\t\tec.Errorf(ctx, \"must not be null\")\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\treturn graphql.Null\n\t\t}\n\t\tres := resTmp.({{$field.Signature}})\n\t\trctx.Result = res\n\t\tctx = ec.Tracer.StartFieldChildExecution(ctx)\n\t\t{{ $field.WriteJson }}\n\t}\n{{ end }}\n", - "generated.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.\nfunc NewExecutableSchema(cfg Config) graphql.ExecutableSchema {\n\treturn &executableSchema{\n\t\tresolvers: cfg.Resolvers,\n\t\tdirectives: cfg.Directives,\n\t\tcomplexity: cfg.Complexity,\n\t}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\n\tComplexity ComplexityRoot\n}\n\ntype ResolverRoot interface {\n{{- range $object := .Objects -}}\n\t{{ if $object.HasResolvers -}}\n\t\t{{$object.GQLType}}() {{$object.GQLType}}Resolver\n\t{{ end }}\n{{- end }}\n}\n\ntype DirectiveRoot struct {\n{{ range $directive := .Directives }}\n\t{{ $directive.Declaration }}\n{{ end }}\n}\n\ntype ComplexityRoot struct {\n{{ range $object := .Objects }}\n\t{{ if not $object.IsReserved -}}\n\t\t{{ $object.GQLType|toCamel }} struct {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ if not $field.IsReserved -}}\n\t\t\t\t{{ $field.GQLName|toCamel }} {{ $field.ComplexitySignature }}\n\t\t\t{{ end }}\n\t\t{{- end }}\n\t\t}\n\t{{- end }}\n{{ end }}\n}\n\n{{ range $object := .Objects -}}\n\t{{ if $object.HasResolvers }}\n\t\ttype {{$object.GQLType}}Resolver interface {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ $field.ShortResolverDeclaration }}\n\t\t{{ end }}\n\t\t}\n\t{{- end }}\n{{- end }}\n\n{{ range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ if $field.Args }}\n\t\t\tfunc {{ $field.ArgsFunc }}(rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t\t}\n\t\t{{ end }}\n\t{{ end }}\n{{- end }}\n\n{{ range $directive := .Directives }}\n\t{{ if $directive.Args }}\n\t\tfunc {{ $directive.ArgsFunc }}(rawArgs map[string]interface{}) (map[string]interface{}, error) {\n\t\t{{ template \"args.gotpl\" $directive.Args }}\n\t\t}\n\t{{ end }}\n{{ end }}\n\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n\tcomplexity ComplexityRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {\n\tswitch typeName + \".\" + field {\n\t{{ range $object := .Objects }}\n\t\t{{ if not $object.IsReserved }}\n\t\t\t{{ range $field := $object.Fields }}\n\t\t\t\t{{ if not $field.IsReserved }}\n\t\t\t\t\tcase \"{{$object.GQLType}}.{{$field.GQLName}}\":\n\t\t\t\t\t\tif e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}} == nil {\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ if $field.Args }}\n\t\t\t\t\t\t\targs, err := {{ $field.ArgsFunc }}(rawArgs)\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn 0, false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t{{ end }}\n\t\t\t\t\t\treturn e.complexity.{{$object.GQLType|toCamel}}.{{$field.GQLName|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true\n\t\t\t\t{{ end }}\n\t\t\t{{ end }}\n\t\t{{ end }}\n\t{{ end }}\n\t}\n\treturn 0, false\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.QueryRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"queries are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.MutationRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t\tExtensions: ec.Extensions,\n\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"mutations are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.SelectionSet)\n\t\tif ec.Errors != nil {\n\t\t\treturn graphql.OneShot(&graphql.Response{Data: []byte(\"null\"), Errors: ec.Errors})\n\t\t}\n\n\t\tvar buf bytes.Buffer\n\t\treturn func() *graphql.Response {\n\t\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\t\tbuf.Reset()\n\t\t\t\tdata := next()\n\n\t\t\t\tif data == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tdata.MarshalGQL(&buf)\n\t\t\t\treturn buf.Bytes()\n\t\t\t})\n\n\t\t\tif buf == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\n\t\t\t\tExtensions: ec.Extensions,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(graphql.ErrorResponse(ctx, \"subscriptions are not supported\"))\n\t{{- end }}\n}\n\ntype executionContext struct {\n\t*graphql.RequestContext\n\t*executableSchema\n}\n\n{{- range $object := .Objects }}\n\t{{ template \"object.gotpl\" $object }}\n\n\t{{- range $field := $object.Fields }}\n\t\t{{ template \"field.gotpl\" $field }}\n\t{{ end }}\n{{- end}}\n\n{{- range $interface := .Interfaces }}\n\t{{ template \"interface.gotpl\" $interface }}\n{{- end }}\n\n{{- range $input := .Inputs }}\n\t{{ template \"input.gotpl\" $input }}\n{{- end }}\n\nfunc (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tec.Error(ctx, ec.Recover(ctx, r))\n\t\t\tret = nil\n\t\t}\n\t}()\n\t{{- if .Directives }}\n\trctx := graphql.GetResolverContext(ctx)\n\tfor _, d := range rctx.Field.Definition.Directives {\n\t\tswitch d.Name {\n\t\t{{- range $directive := .Directives }}\n\t\tcase \"{{$directive.Name}}\":\n\t\t\tif ec.directives.{{$directive.Name|ucFirst}} != nil {\n\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\trawArgs := d.ArgumentMap(ec.Variables)\n\t\t\t\t\targs, err := {{ $directive.ArgsFunc }}(rawArgs)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(ctx, err)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t\tn := next\n\t\t\t\tnext = func(ctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})\n\t\t\t\t}\n\t\t\t}\n\t\t{{- end }}\n\t\t}\n\t}\n\t{{- end }}\n\tres, err := ec.ResolverMiddleware(ctx, next)\n\tif err != nil {\n\t\tec.Error(ctx, err)\n\t\treturn nil\n\t}\n\treturn res\n}\n\nfunc (ec *executionContext) introspectSchema() (*introspection.Schema, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapSchema(parsedSchema), nil\n}\n\nfunc (ec *executionContext) introspectType(name string) (*introspection.Type, error) {\n\tif ec.DisableIntrospection {\n\t\treturn nil, errors.New(\"introspection disabled\")\n\t}\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t{{- range $filename, $schema := .SchemaRaw }}\n\t\t&ast.Source{Name: {{$filename|quote}}, Input: {{$schema|rawQuote}}},\n\t{{- end }}\n)\n", - "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\n\t\tvar asMap = v.(map[string]interface{})\n\t\t{{ range $field := .Fields}}\n\t\t\t{{- if $field.Default}}\n\t\t\t\tif _, present := asMap[{{$field.GQLName|quote}}] ; !present {\n\t\t\t\t\tasMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}\n\t\t\t\t}\n\t\t\t{{- end}}\n\t\t{{- end }}\n\n\t\tfor k, v := range asMap {\n\t\t\tswitch k {\n\t\t\t{{- range $field := .Fields }}\n\t\t\tcase {{$field.GQLName|quote}}:\n\t\t\t\tvar err error\n\t\t\t\t{{ $field.Unmarshal (print \"it.\" $field.GoFieldName) \"v\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn it, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\n\t\treturn it, nil\n\t}\n\t{{- end }}\n", - "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.FullName}}) graphql.Marshaler {\n\tswitch obj := (*obj).(type) {\n\tcase nil:\n\t\treturn graphql.Null\n\t{{- range $implementor := $interface.Implementors }}\n\t\t{{- if $implementor.ValueReceiver }}\n\t\t\tcase {{$implementor.FullName}}:\n\t\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.FullName}}:\n\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, obj)\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\n", - "models.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\n{{ range $model := .Models }}\n\t{{with .Description}} {{.|prefixLines \"// \"}} {{end}}\n\t{{- if .IsInterface }}\n\t\ttype {{.GoType}} interface {\n\t\t\tIs{{.GoType}}()\n\t\t}\n\t{{- else }}\n\t\ttype {{.GoType}} struct {\n\t\t\t{{- range $field := .Fields }}\n\t\t\t\t{{- with .Description}}\n\t\t\t\t\t{{.|prefixLines \"// \"}}\n\t\t\t\t{{- end}}\n\t\t\t\t{{- if $field.GoFieldName }}\n\t\t\t\t\t{{ $field.GoFieldName }} {{$field.Signature}} `json:\"{{$field.GQLName}}\"`\n\t\t\t\t{{- else }}\n\t\t\t\t\t{{ $field.GoFKName }} {{$field.GoFKType}}\n\t\t\t\t{{- end }}\n\t\t\t{{- end }}\n\t\t}\n\n\t\t{{- range $iface := .Implements }}\n\t\t\tfunc ({{$model.GoType}}) Is{{$iface.GoType}}() {}\n\t\t{{- end }}\n\n\t{{- end }}\n{{- end}}\n\n{{ range $enum := .Enums }}\n\t{{with .Description}}{{.|prefixLines \"// \"}} {{end}}\n\ttype {{.GoType}} string\n\tconst (\n\t{{- range $value := .Values}}\n\t\t{{- with .Description}}\n\t\t\t{{.|prefixLines \"// \"}}\n\t\t{{- end}}\n\t\t{{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}\n\t{{- end }}\n\t)\n\n\tfunc (e {{.GoType}}) IsValid() bool {\n\t\tswitch e {\n\t\tcase {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}:\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tfunc (e {{.GoType}}) String() string {\n\t\treturn string(e)\n\t}\n\n\tfunc (e *{{.GoType}}) UnmarshalGQL(v interface{}) error {\n\t\tstr, ok := v.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"enums must be strings\")\n\t\t}\n\n\t\t*e = {{.GoType}}(str)\n\t\tif !e.IsValid() {\n\t\t\treturn fmt.Errorf(\"%s is not a valid {{.GQLType}}\", str)\n\t\t}\n\t\treturn nil\n\t}\n\n\tfunc (e {{.GoType}}) MarshalGQL(w io.Writer) {\n\t\tfmt.Fprint(w, strconv.Quote(e.String()))\n\t}\n\n{{- end }}\n", - "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\tObject: {{$object.GQLType|quote}},\n\t})\n\tif len(fields) != 1 {\n\t\tec.Errorf(ctx, \"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\t{{if $object.Root}}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t})\n\t{{end}}\n\n\t{{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}}\n\tout := graphql.NewOrderedMap(len(fields))\n\tinvalid := false\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\twg.Add(1)\n\t\t\t\tgo func(i int, field graphql.CollectedField) {\n\t\t\t{{- end }}\n\t\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\tif out.Values[i] == graphql.Null {\n\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\t\twg.Done()\n\t\t\t\t}(i, field)\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\t{{if $object.IsConcurrent}} wg.Wait() {{end}}\n\tif invalid { return graphql.Null }\n\treturn out\n}\n{{- end }}\n", - "resolver.gotpl": "package {{ .PackageName }}\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"fmt\" }}\n\t{{ reserveImport \"io\" }}\n\t{{ reserveImport \"strconv\" }}\n\t{{ reserveImport \"time\" }}\n\t{{ reserveImport \"sync\" }}\n\t{{ reserveImport \"errors\" }}\n\t{{ reserveImport \"bytes\" }}\n\n\t{{ reserveImport \"github.com/99designs/gqlgen/handler\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser\" }}\n\t{{ reserveImport \"github.com/vektah/gqlparser/ast\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/graphql/introspection\" }}\n)\n\ntype {{.ResolverType}} struct {}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\tfunc (r *{{$.ResolverType}}) {{$object.GQLType}}() {{ $object.ResolverInterface.FullName }} {\n\t\t\treturn &{{lcFirst $object.GQLType}}Resolver{r}\n\t\t}\n\t{{ end -}}\n{{ end }}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\ttype {{lcFirst $object.GQLType}}Resolver struct { *Resolver }\n\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{- if $field.IsResolver -}}\n\t\t\tfunc (r *{{lcFirst $object.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} {\n\t\t\t\tpanic(\"not implemented\")\n\t\t\t}\n\t\t\t{{ end -}}\n\t\t{{ end -}}\n\t{{ end -}}\n{{ end }}\n", - "server.gotpl": "package main\n\nimport (\n\t%%%IMPORTS%%%\n\n\t{{ reserveImport \"context\" }}\n\t{{ reserveImport \"log\" }}\n\t{{ reserveImport \"net/http\" }}\n\t{{ reserveImport \"os\" }}\n\t{{ reserveImport \"github.com/99designs/gqlgen/handler\" }}\n)\n\nconst defaultPort = \"8080\"\n\nfunc main() {\n\tport := os.Getenv(\"PORT\")\n\tif port == \"\" {\n\t\tport = defaultPort\n\t}\n\n\thttp.Handle(\"/\", handler.Playground(\"GraphQL playground\", \"/query\"))\n\thttp.Handle(\"/query\", handler.GraphQL({{ lookupImport .ExecPackageName }}.NewExecutableSchema({{ lookupImport .ExecPackageName}}.Config{Resolvers: &{{ lookupImport .ResolverPackageName}}.Resolver{}})))\n\n\tlog.Printf(\"connect to http://localhost:%s/ for GraphQL playground\", port)\n\tlog.Fatal(http.ListenAndServe(\":\" + port, nil))\n}\n", -} diff --git a/codegen/templates/import.go b/codegen/templates/import.go index c9db2d96bb..effe9a0dfb 100644 --- a/codegen/templates/import.go +++ b/codegen/templates/import.go @@ -2,10 +2,10 @@ package templates import ( "fmt" - "go/build" + "go/types" "strconv" - "github.com/99designs/gqlgen/internal/gopath" + "github.com/99designs/gqlgen/internal/code" ) type Import struct { @@ -38,43 +38,42 @@ func (s *Imports) String() string { return res } -func (s *Imports) Reserve(path string, aliases ...string) string { +func (s *Imports) Reserve(path string, aliases ...string) (string, error) { if path == "" { panic("empty ambient import") } // if we are referencing our own package we dont need an import - if gopath.MustDir2Import(s.destDir) == path { - return "" - } - - pkg, err := build.Default.Import(path, s.destDir, 0) - if err != nil { - panic(err) + if code.ImportPathForDir(s.destDir) == path { + return "", nil } + name := code.NameForPackage(path) var alias string if len(aliases) != 1 { - alias = pkg.Name + alias = name } else { alias = aliases[0] } if existing := s.findByPath(path); existing != nil { - panic("ambient import already exists") + if existing.Alias == alias { + return "", nil + } + return "", fmt.Errorf("ambient import already exists") } if alias := s.findByAlias(alias); alias != nil { - panic("ambient import collides on an alias") + return "", fmt.Errorf("ambient import collides on an alias") } s.imports = append(s.imports, &Import{ - Name: pkg.Name, + Name: name, Path: path, Alias: alias, }) - return "" + return "", nil } func (s *Imports) Lookup(path string) string { @@ -82,8 +81,10 @@ func (s *Imports) Lookup(path string) string { return "" } + path = code.NormalizeVendor(path) + // if we are referencing our own package we dont need an import - if gopath.MustDir2Import(s.destDir) == path { + if code.ImportPathForDir(s.destDir) == path { return "" } @@ -91,13 +92,8 @@ func (s *Imports) Lookup(path string) string { return existing.Alias } - pkg, err := build.Default.Import(path, s.destDir, 0) - if err != nil { - panic(err) - } - imp := &Import{ - Name: pkg.Name, + Name: code.NameForPackage(path), Path: path, } s.imports = append(s.imports, imp) @@ -116,6 +112,12 @@ func (s *Imports) Lookup(path string) string { return imp.Alias } +func (s *Imports) LookupType(t types.Type) string { + return types.TypeString(t, func(i *types.Package) string { + return s.Lookup(i.Path()) + }) +} + func (s Imports) findByPath(importPath string) *Import { for _, imp := range s.imports { if imp.Path == importPath { diff --git a/codegen/templates/import_test.go b/codegen/templates/import_test.go index fb7931f986..b055beb724 100644 --- a/codegen/templates/import_test.go +++ b/codegen/templates/import_test.go @@ -1,6 +1,7 @@ package templates import ( + "go/types" "os" "testing" @@ -22,6 +23,15 @@ func TestImports(t *testing.T) { require.Equal(t, "bar", a.Lookup(aBar)) }) + t.Run("lookup by type", func(t *testing.T) { + a := Imports{destDir: wd} + + pkg := types.NewPackage("github.com/99designs/gqlgen/codegen/templates/testdata/b/bar", "bar") + typ := types.NewNamed(types.NewTypeName(0, pkg, "Boolean", types.Typ[types.Bool]), types.Typ[types.Bool], nil) + + require.Equal(t, "bar.Boolean", a.LookupType(typ)) + }) + t.Run("duplicates are decollisioned", func(t *testing.T) { a := Imports{destDir: wd} @@ -54,33 +64,14 @@ bar1 "github.com/99designs/gqlgen/codegen/templates/testdata/b/bar" ) }) - t.Run("reserved collisions on path will panic", func(t *testing.T) { - a := Imports{destDir: wd} - - a.Reserve(aBar) - - require.Panics(t, func() { - a.Reserve(aBar) - }) - }) - - t.Run("reserved collisions on alias will panic", func(t *testing.T) { - a := Imports{destDir: wd} - - a.Reserve(aBar) - - require.Panics(t, func() { - a.Reserve(bBar) - }) - }) - t.Run("aliased imports will not collide", func(t *testing.T) { a := Imports{destDir: wd} - a.Reserve(aBar, "abar") - a.Reserve(bBar, "bbar") + _, _ = a.Reserve(aBar, "abar") + _, _ = a.Reserve(bBar, "bbar") require.Equal(t, `abar "github.com/99designs/gqlgen/codegen/templates/testdata/a/bar" bbar "github.com/99designs/gqlgen/codegen/templates/testdata/b/bar"`, a.String()) }) + } diff --git a/codegen/templates/inliner/inliner.go b/codegen/templates/inliner/inliner.go deleted file mode 100644 index 3c5a0a81d0..0000000000 --- a/codegen/templates/inliner/inliner.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "bytes" - "go/format" - "io/ioutil" - "strconv" - "strings" -) - -func main() { - dir := "./" - - files, err := ioutil.ReadDir(dir) - if err != nil { - panic(err) - } - - out := bytes.Buffer{} - out.WriteString("package templates\n\n") - out.WriteString("var data = map[string]string{\n") - - for _, f := range files { - if !strings.HasSuffix(f.Name(), ".gotpl") { - continue - } - - b, err := ioutil.ReadFile(dir + f.Name()) - if err != nil { - panic(err) - } - - out.WriteString(strconv.Quote(f.Name())) - out.WriteRune(':') - out.WriteString(strconv.Quote(string(b))) - out.WriteString(",\n") - } - - out.WriteString("}\n") - - formatted, err2 := format.Source(out.Bytes()) - if err2 != nil { - panic(err2) - } - - ioutil.WriteFile(dir+"data.go", formatted, 0644) -} diff --git a/codegen/templates/input.gotpl b/codegen/templates/input.gotpl deleted file mode 100644 index f543608df0..0000000000 --- a/codegen/templates/input.gotpl +++ /dev/null @@ -1,28 +0,0 @@ - {{- if .IsMarshaled }} - func Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) { - var it {{.FullName}} - var asMap = v.(map[string]interface{}) - {{ range $field := .Fields}} - {{- if $field.Default}} - if _, present := asMap[{{$field.GQLName|quote}}] ; !present { - asMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }} - } - {{- end}} - {{- end }} - - for k, v := range asMap { - switch k { - {{- range $field := .Fields }} - case {{$field.GQLName|quote}}: - var err error - {{ $field.Unmarshal (print "it." $field.GoFieldName) "v" }} - if err != nil { - return it, err - } - {{- end }} - } - } - - return it, nil - } - {{- end }} diff --git a/codegen/templates/interface.gotpl b/codegen/templates/interface.gotpl deleted file mode 100644 index 84cbe5002c..0000000000 --- a/codegen/templates/interface.gotpl +++ /dev/null @@ -1,18 +0,0 @@ -{{- $interface := . }} - -func (ec *executionContext) _{{$interface.GQLType}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.FullName}}) graphql.Marshaler { - switch obj := (*obj).(type) { - case nil: - return graphql.Null - {{- range $implementor := $interface.Implementors }} - {{- if $implementor.ValueReceiver }} - case {{$implementor.FullName}}: - return ec._{{$implementor.GQLType}}(ctx, sel, &obj) - {{- end}} - case *{{$implementor.FullName}}: - return ec._{{$implementor.GQLType}}(ctx, sel, obj) - {{- end }} - default: - panic(fmt.Errorf("unexpected type %T", obj)) - } -} diff --git a/codegen/templates/models.gotpl b/codegen/templates/models.gotpl deleted file mode 100644 index db63a996ba..0000000000 --- a/codegen/templates/models.gotpl +++ /dev/null @@ -1,91 +0,0 @@ -// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. - -package {{ .PackageName }} - -import ( - %%%IMPORTS%%% - - {{ reserveImport "context" }} - {{ reserveImport "fmt" }} - {{ reserveImport "io" }} - {{ reserveImport "strconv" }} - {{ reserveImport "time" }} - {{ reserveImport "sync" }} - {{ reserveImport "errors" }} - {{ reserveImport "bytes" }} - - {{ reserveImport "github.com/vektah/gqlparser" }} - {{ reserveImport "github.com/vektah/gqlparser/ast" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} -) - -{{ range $model := .Models }} - {{with .Description}} {{.|prefixLines "// "}} {{end}} - {{- if .IsInterface }} - type {{.GoType}} interface { - Is{{.GoType}}() - } - {{- else }} - type {{.GoType}} struct { - {{- range $field := .Fields }} - {{- with .Description}} - {{.|prefixLines "// "}} - {{- end}} - {{- if $field.GoFieldName }} - {{ $field.GoFieldName }} {{$field.Signature}} `json:"{{$field.GQLName}}"` - {{- else }} - {{ $field.GoFKName }} {{$field.GoFKType}} - {{- end }} - {{- end }} - } - - {{- range $iface := .Implements }} - func ({{$model.GoType}}) Is{{$iface.GoType}}() {} - {{- end }} - - {{- end }} -{{- end}} - -{{ range $enum := .Enums }} - {{with .Description}}{{.|prefixLines "// "}} {{end}} - type {{.GoType}} string - const ( - {{- range $value := .Values}} - {{- with .Description}} - {{.|prefixLines "// "}} - {{- end}} - {{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}} - {{- end }} - ) - - func (e {{.GoType}}) IsValid() bool { - switch e { - case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}: - return true - } - return false - } - - func (e {{.GoType}}) String() string { - return string(e) - } - - func (e *{{.GoType}}) UnmarshalGQL(v interface{}) error { - str, ok := v.(string) - if !ok { - return fmt.Errorf("enums must be strings") - } - - *e = {{.GoType}}(str) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid {{.GQLType}}", str) - } - return nil - } - - func (e {{.GoType}}) MarshalGQL(w io.Writer) { - fmt.Fprint(w, strconv.Quote(e.String())) - } - -{{- end }} diff --git a/codegen/templates/object.gotpl b/codegen/templates/object.gotpl deleted file mode 100644 index e98cbe1ee5..0000000000 --- a/codegen/templates/object.gotpl +++ /dev/null @@ -1,69 +0,0 @@ -{{ $object := . }} - -var {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}} - -// nolint: gocyclo, errcheck, gas, goconst -{{- if .Stream }} -func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors) - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, - }) - if len(fields) != 1 { - ec.Errorf(ctx, "must subscribe to exactly one stream") - return nil - } - - switch fields[0].Name { - {{- range $field := $object.Fields }} - case "{{$field.GQLName}}": - return ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, fields[0]) - {{- end }} - default: - panic("unknown field " + strconv.Quote(fields[0].Name)) - } -} -{{- else }} -func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors) - {{if $object.Root}} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: {{$object.GQLType|quote}}, - }) - {{end}} - - {{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString({{$object.GQLType|quote}}) - {{- range $field := $object.Fields }} - case "{{$field.GQLName}}": - {{- if $field.IsConcurrent }} - wg.Add(1) - go func(i int, field graphql.CollectedField) { - {{- end }} - out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) - {{- if $field.ASTType.NonNull }} - if out.Values[i] == graphql.Null { - invalid = true - } - {{- end }} - {{- if $field.IsConcurrent }} - wg.Done() - }(i, field) - {{- end }} - {{- end }} - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - {{if $object.IsConcurrent}} wg.Wait() {{end}} - if invalid { return graphql.Null } - return out -} -{{- end }} diff --git a/codegen/templates/resolver.gotpl b/codegen/templates/resolver.gotpl deleted file mode 100644 index 53ba8c4338..0000000000 --- a/codegen/templates/resolver.gotpl +++ /dev/null @@ -1,44 +0,0 @@ -package {{ .PackageName }} - -import ( - %%%IMPORTS%%% - - {{ reserveImport "context" }} - {{ reserveImport "fmt" }} - {{ reserveImport "io" }} - {{ reserveImport "strconv" }} - {{ reserveImport "time" }} - {{ reserveImport "sync" }} - {{ reserveImport "errors" }} - {{ reserveImport "bytes" }} - - {{ reserveImport "github.com/99designs/gqlgen/handler" }} - {{ reserveImport "github.com/vektah/gqlparser" }} - {{ reserveImport "github.com/vektah/gqlparser/ast" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql" }} - {{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} -) - -type {{.ResolverType}} struct {} - -{{ range $object := .Objects -}} - {{- if $object.HasResolvers -}} - func (r *{{$.ResolverType}}) {{$object.GQLType}}() {{ $object.ResolverInterface.FullName }} { - return &{{lcFirst $object.GQLType}}Resolver{r} - } - {{ end -}} -{{ end }} - -{{ range $object := .Objects -}} - {{- if $object.HasResolvers -}} - type {{lcFirst $object.GQLType}}Resolver struct { *Resolver } - - {{ range $field := $object.Fields -}} - {{- if $field.IsResolver -}} - func (r *{{lcFirst $object.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} { - panic("not implemented") - } - {{ end -}} - {{ end -}} - {{ end -}} -{{ end }} diff --git a/codegen/templates/templates.go b/codegen/templates/templates.go index 22e5d7395c..9d45b6718e 100644 --- a/codegen/templates/templates.go +++ b/codegen/templates/templates.go @@ -1,13 +1,14 @@ -//go:generate go run ./inliner/inliner.go - package templates import ( "bytes" "fmt" + "go/types" "io/ioutil" "os" "path/filepath" + "reflect" + "runtime" "sort" "strconv" "strings" @@ -15,40 +16,136 @@ import ( "unicode" "github.com/99designs/gqlgen/internal/imports" - "github.com/pkg/errors" ) // this is done with a global because subtemplates currently get called in functions. Lets aim to remove this eventually. var CurrentImports *Imports -func Run(name string, tpldata interface{}) (*bytes.Buffer, error) { - t := template.New("").Funcs(template.FuncMap{ - "ucFirst": ucFirst, - "lcFirst": lcFirst, - "quote": strconv.Quote, - "rawQuote": rawQuote, - "toCamel": ToCamel, - "dump": dump, - "prefixLines": prefixLines, - "reserveImport": CurrentImports.Reserve, - "lookupImport": CurrentImports.Lookup, +type Options struct { + PackageName string + Filename string + RegionTags bool + GeneratedHeader bool + Data interface{} +} + +func Render(cfg Options) error { + if CurrentImports != nil { + panic(fmt.Errorf("recursive or concurrent call to RenderToFile detected")) + } + CurrentImports = &Imports{destDir: filepath.Dir(cfg.Filename)} + + // load path relative to calling source file + _, callerFile, _, _ := runtime.Caller(1) + rootDir := filepath.Dir(callerFile) + + t := template.New("").Funcs(Funcs()) + + var roots []string + // 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 + } + b, err := ioutil.ReadFile(path) + if err != nil { + return err + } + + t, err = t.New(name).Parse(string(b)) + if err != nil { + return errors.Wrap(err, cfg.Filename) + } + + roots = append(roots, name) + + return nil }) + if err != nil { + return errors.Wrap(err, "locating templates") + } - for filename, data := range data { - _, err := t.New(filename).Parse(data) + // then execute all the important looking ones in order, adding them to the same file + sort.Slice(roots, func(i, j int) bool { + // important files go first + if strings.HasSuffix(roots[i], "!.gotpl") { + return true + } + if strings.HasSuffix(roots[j], "!.gotpl") { + return false + } + return roots[i] < roots[j] + }) + var buf bytes.Buffer + for _, root := range roots { + if cfg.RegionTags { + buf.WriteString("\n// region " + center(70, "*", " "+root+" ") + "\n") + } + err = t.Lookup(root).Execute(&buf, cfg.Data) if err != nil { - panic(err) + return errors.Wrap(err, root) + } + if cfg.RegionTags { + buf.WriteString("\n// endregion " + center(70, "*", " "+root+" ") + "\n") } } - buf := &bytes.Buffer{} - err := t.Lookup(name).Execute(buf, tpldata) + var result bytes.Buffer + if cfg.GeneratedHeader { + result.WriteString("// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\n") + } + result.WriteString("package ") + result.WriteString(cfg.PackageName) + result.WriteString("\n\n") + result.WriteString("import (\n") + result.WriteString(CurrentImports.String()) + result.WriteString(")\n") + _, err = buf.WriteTo(&result) if err != nil { - return nil, err + return err + } + CurrentImports = nil + + return write(cfg.Filename, result.Bytes()) +} + +func center(width int, pad string, s string) string { + if len(s)+2 > width { + return s } + lpad := (width - len(s)) / 2 + rpad := width - (lpad + len(s)) + return strings.Repeat(pad, lpad) + s + strings.Repeat(pad, rpad) +} - return buf, nil +func Funcs() template.FuncMap { + return template.FuncMap{ + "ucFirst": ucFirst, + "lcFirst": lcFirst, + "quote": strconv.Quote, + "rawQuote": rawQuote, + "dump": Dump, + "ref": ref, + "ts": TypeIdentifier, + "call": Call, + "prefixLines": prefixLines, + "notNil": notNil, + "reserveImport": CurrentImports.Reserve, + "lookupImport": CurrentImports.Lookup, + "go": ToGo, + "goPrivate": ToGoPrivate, + "add": func(a, b int) int { + return a + b + }, + "render": func(filename string, tpldata interface{}) (*bytes.Buffer, error) { + return render(resolveName(filename, 0), tpldata) + }, + } } func ucFirst(s string) string { @@ -74,37 +171,276 @@ func isDelimiter(c rune) bool { return c == '-' || c == '_' || unicode.IsSpace(c) } -func ToCamel(s string) string { - buffer := make([]rune, 0, len(s)) - upper := true - lastWasUpper := false +func ref(p types.Type) string { + return CurrentImports.LookupType(p) +} + +var pkgReplacer = strings.NewReplacer( + "/", "ᚋ", + ".", "ᚗ", + "-", "ᚑ", +) + +func TypeIdentifier(t types.Type) string { + res := "" + for { + switch it := t.(type) { + case *types.Pointer: + t.Underlying() + res += "ᚖ" + t = it.Elem() + case *types.Slice: + res += "ᚕ" + t = it.Elem() + case *types.Named: + res += pkgReplacer.Replace(it.Obj().Pkg().Path()) + res += "ᚐ" + res += it.Obj().Name() + return res + case *types.Basic: + res += it.Name() + return res + case *types.Map: + res += "map" + return res + case *types.Interface: + res += "interface" + return res + default: + panic(fmt.Errorf("unexpected type %T", it)) + } + } +} + +func Call(p *types.Func) string { + pkg := CurrentImports.Lookup(p.Pkg().Path()) + + if pkg != "" { + pkg += "." + } + + if p.Type() != nil { + // make sure the returned type is listed in our imports. + ref(p.Type().(*types.Signature).Results().At(0).Type()) + } + + return pkg + p.Name() +} + +func ToGo(name string) string { + runes := make([]rune, 0, len(name)) + + 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) +} + +func ToGoPrivate(name string) string { + runes := make([]rune, 0, len(name)) + + first := true + wordWalker(name, func(info *wordInfo) { + word := info.Word + if 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 + } else if info.MatchCommonInitial { + word = strings.ToUpper(word) + } else if !info.HasCommonInitial { + word = ucFirst(strings.ToLower(word)) + } + runes = append(runes, []rune(word)...) + }) + + return sanitizeKeywords(string(runes)) +} + +type wordInfo struct { + Word string + MatchCommonInitial bool + HasCommonInitial bool +} + +// This function is based on the following code. +// https://github.com/golang/lint/blob/06c8688daad7faa9da5a0c2f163a3d14aac986ca/lint.go#L679 +func wordWalker(str string, f func(*wordInfo)) { + runes := []rune(str) + w, i := 0, 0 // index of start of word, scan + hasCommonInitial := false + for i+1 <= len(runes) { + eow := false // whether we hit the end of a word + if i+1 == len(runes) { + eow = true + } else if isDelimiter(runes[i+1]) { + // underscore; shift the remainder forward over any run of underscores + eow = true + n := 1 + for i+n+1 < len(runes) && isDelimiter(runes[i+n+1]) { + n++ + } - for _, c := range s { - if isDelimiter(c) { - upper = true + // Leave at most one underscore if the underscore is between two digits + if i+n+1 < len(runes) && unicode.IsDigit(runes[i]) && unicode.IsDigit(runes[i+n+1]) { + n-- + } + + copy(runes[i+1:], runes[i+n+1:]) + runes = runes[:len(runes)-n] + } else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) { + // lower->non-lower + eow = true + } + i++ + + // [w,i) is a word. + word := string(runes[w:i]) + if !eow && commonInitialisms[word] && !unicode.IsLower(runes[i]) { + // through + // split IDFoo → ID, Foo + // but URLs → URLs + } else if !eow { + if commonInitialisms[word] { + hasCommonInitial = true + } continue } - if !lastWasUpper && unicode.IsUpper(c) { - upper = true + + matchCommonInitial := false + if commonInitialisms[strings.ToUpper(word)] { + hasCommonInitial = true + matchCommonInitial = true } - if upper { - buffer = append(buffer, unicode.ToUpper(c)) - } else { - buffer = append(buffer, unicode.ToLower(c)) + f(&wordInfo{ + Word: word, + MatchCommonInitial: matchCommonInitial, + HasCommonInitial: hasCommonInitial, + }) + hasCommonInitial = false + w = i + } +} + +var keywords = []string{ + "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", + "_", +} + +// sanitizeKeywords prevents collisions with go keywords for arguments to resolver functions +func sanitizeKeywords(name string) string { + for _, k := range keywords { + if name == k { + return name + "Arg" } - upper = false - lastWasUpper = unicode.IsUpper(c) } + return name +} - return string(buffer) +// commonInitialisms is a set of common initialisms. +// Only add entries that are highly unlikely to be non-initialisms. +// For instance, "ID" is fine (Freudian code is rare), but "AND" is not. +var commonInitialisms = map[string]bool{ + "ACL": true, + "API": true, + "ASCII": true, + "CPU": true, + "CSS": true, + "DNS": true, + "EOF": true, + "GUID": true, + "HTML": true, + "HTTP": true, + "HTTPS": true, + "ID": true, + "IP": true, + "JSON": true, + "LHS": true, + "QPS": true, + "RAM": true, + "RHS": true, + "RPC": true, + "SLA": true, + "SMTP": true, + "SQL": true, + "SSH": true, + "TCP": true, + "TLS": true, + "TTL": true, + "UDP": true, + "UI": true, + "UID": true, + "UUID": true, + "URI": true, + "URL": true, + "UTF8": true, + "VM": true, + "XML": true, + "XMPP": true, + "XSRF": true, + "XSS": true, } func rawQuote(s string) string { return "`" + strings.Replace(s, "`", "`+\"`\"+`", -1) + "`" } -func dump(val interface{}) string { +func notNil(field string, data interface{}) bool { + v := reflect.ValueOf(data) + + if v.Kind() == reflect.Ptr { + v = v.Elem() + } + if v.Kind() != reflect.Struct { + return false + } + val := v.FieldByName(field) + + return val.IsValid() && !val.IsNil() +} + +func Dump(val interface{}) string { switch val := val.(type) { case int: return strconv.Itoa(val) @@ -121,7 +457,7 @@ func dump(val interface{}) string { case []interface{}: var parts []string for _, part := range val { - parts = append(parts, dump(part)) + parts = append(parts, Dump(part)) } return "[]interface{}{" + strings.Join(parts, ",") + "}" case map[string]interface{}: @@ -138,7 +474,7 @@ func dump(val interface{}) string { buf.WriteString(strconv.Quote(key)) buf.WriteString(":") - buf.WriteString(dump(data)) + buf.WriteString(Dump(data)) buf.WriteString(",") } buf.WriteString("}") @@ -152,22 +488,33 @@ func prefixLines(prefix, s string) string { return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) } -func RenderToFile(tpl string, filename string, data interface{}) error { - if CurrentImports != nil { - panic(fmt.Errorf("recursive or concurrent call to RenderToFile detected")) +func resolveName(name string, skip int) string { + if name[0] == '.' { + // load path relative to calling source file + _, callerFile, _, _ := runtime.Caller(skip + 1) + return filepath.Join(filepath.Dir(callerFile), name[1:]) } - CurrentImports = &Imports{destDir: filepath.Dir(filename)} - var buf *bytes.Buffer - buf, err := Run(tpl, data) + // load path relative to this directory + _, callerFile, _, _ := runtime.Caller(0) + return filepath.Join(filepath.Dir(callerFile), name) +} + +func render(filename string, tpldata interface{}) (*bytes.Buffer, error) { + t := template.New("").Funcs(Funcs()) + + b, err := ioutil.ReadFile(filename) if err != nil { - return errors.Wrap(err, filename+" generation failed") + return nil, err } - b := bytes.Replace(buf.Bytes(), []byte("%%%IMPORTS%%%"), []byte(CurrentImports.String()), -1) - CurrentImports = nil + t, err = t.New(filepath.Base(filename)).Parse(string(b)) + if err != nil { + panic(err) + } - return write(filename, b) + buf := &bytes.Buffer{} + return buf, t.Execute(buf, tpldata) } func write(filename string, b []byte) error { diff --git a/codegen/templates/templates_test.go b/codegen/templates/templates_test.go index dce5fffd6b..1e6beb20ee 100644 --- a/codegen/templates/templates_test.go +++ b/codegen/templates/templates_test.go @@ -6,10 +6,97 @@ import ( "github.com/stretchr/testify/require" ) -func TestToUpper(t *testing.T) { - require.Equal(t, "ToCamel", ToCamel("TO_CAMEL")) - require.Equal(t, "ToCamel", ToCamel("to_camel")) - require.Equal(t, "ToCamel", ToCamel("toCamel")) - require.Equal(t, "ToCamel", ToCamel("ToCamel")) - require.Equal(t, "ToCamel", ToCamel("to-camel")) +func TestToGo(t *testing.T) { + require.Equal(t, "ToCamel", ToGo("TO_CAMEL")) + require.Equal(t, "ToCamel", ToGo("to_camel")) + require.Equal(t, "ToCamel", ToGo("toCamel")) + require.Equal(t, "ToCamel", ToGo("ToCamel")) + require.Equal(t, "ToCamel", ToGo("to-camel")) + + require.Equal(t, "RelatedURLs", ToGo("RelatedURLs")) + require.Equal(t, "ImageIDs", ToGo("ImageIDs")) + require.Equal(t, "FooID", ToGo("FooID")) + require.Equal(t, "IDFoo", ToGo("IDFoo")) + require.Equal(t, "FooASCII", ToGo("FooASCII")) + require.Equal(t, "ASCIIFoo", ToGo("ASCIIFoo")) + require.Equal(t, "FooUTF8", ToGo("FooUTF8")) + require.Equal(t, "UTF8Foo", ToGo("UTF8Foo")) + require.Equal(t, "JSONEncoding", ToGo("JSONEncoding")) + + require.Equal(t, "A", ToGo("A")) + require.Equal(t, "ID", ToGo("ID")) + require.Equal(t, "ID", ToGo("id")) + require.Equal(t, "", ToGo("")) + + require.Equal(t, "RelatedUrls", ToGo("RelatedUrls")) + require.Equal(t, "ITicket", ToGo("ITicket")) + require.Equal(t, "FooTicket", ToGo("fooTicket")) +} + +func TestToGoPrivate(t *testing.T) { + require.Equal(t, "toCamel", ToGoPrivate("TO_CAMEL")) + require.Equal(t, "toCamel", ToGoPrivate("to_camel")) + require.Equal(t, "toCamel", ToGoPrivate("toCamel")) + require.Equal(t, "toCamel", ToGoPrivate("ToCamel")) + require.Equal(t, "toCamel", ToGoPrivate("to-camel")) + + require.Equal(t, "relatedURLs", ToGoPrivate("RelatedURLs")) + require.Equal(t, "imageIDs", ToGoPrivate("ImageIDs")) + require.Equal(t, "fooID", ToGoPrivate("FooID")) + require.Equal(t, "idFoo", ToGoPrivate("IDFoo")) + require.Equal(t, "fooASCII", ToGoPrivate("FooASCII")) + require.Equal(t, "asciiFoo", ToGoPrivate("ASCIIFoo")) + require.Equal(t, "fooUTF8", ToGoPrivate("FooUTF8")) + require.Equal(t, "utf8Foo", ToGoPrivate("UTF8Foo")) + require.Equal(t, "jsonEncoding", ToGoPrivate("JSONEncoding")) + + require.Equal(t, "relatedUrls", ToGoPrivate("RelatedUrls")) + require.Equal(t, "iTicket", ToGoPrivate("ITicket")) + + require.Equal(t, "rangeArg", ToGoPrivate("Range")) + + require.Equal(t, "a", ToGoPrivate("A")) + require.Equal(t, "id", ToGoPrivate("ID")) + require.Equal(t, "id", ToGoPrivate("id")) + require.Equal(t, "", ToGoPrivate("")) +} + +func Test_wordWalker(t *testing.T) { + + helper := func(str string) []*wordInfo { + resultList := []*wordInfo{} + wordWalker(str, func(info *wordInfo) { + resultList = append(resultList, info) + }) + return resultList + } + + require.Equal(t, []*wordInfo{{Word: "TO"}, {Word: "CAMEL"}}, helper("TO_CAMEL")) + require.Equal(t, []*wordInfo{{Word: "to"}, {Word: "camel"}}, helper("to_camel")) + require.Equal(t, []*wordInfo{{Word: "to"}, {Word: "Camel"}}, helper("toCamel")) + require.Equal(t, []*wordInfo{{Word: "To"}, {Word: "Camel"}}, helper("ToCamel")) + require.Equal(t, []*wordInfo{{Word: "to"}, {Word: "camel"}}, helper("to-camel")) + + require.Equal(t, []*wordInfo{{Word: "Related"}, {Word: "URLs", HasCommonInitial: true}}, helper("RelatedURLs")) + require.Equal(t, []*wordInfo{{Word: "Image"}, {Word: "IDs", HasCommonInitial: true}}, helper("ImageIDs")) + require.Equal(t, []*wordInfo{{Word: "Foo"}, {Word: "ID", HasCommonInitial: true, MatchCommonInitial: true}}, helper("FooID")) + require.Equal(t, []*wordInfo{{Word: "ID", HasCommonInitial: true, MatchCommonInitial: true}, {Word: "Foo"}}, helper("IDFoo")) + require.Equal(t, []*wordInfo{{Word: "Foo"}, {Word: "ASCII", HasCommonInitial: true, MatchCommonInitial: true}}, helper("FooASCII")) + require.Equal(t, []*wordInfo{{Word: "ASCII", HasCommonInitial: true, MatchCommonInitial: true}, {Word: "Foo"}}, helper("ASCIIFoo")) + require.Equal(t, []*wordInfo{{Word: "Foo"}, {Word: "UTF8", HasCommonInitial: true, MatchCommonInitial: true}}, helper("FooUTF8")) + require.Equal(t, []*wordInfo{{Word: "UTF8", HasCommonInitial: true, MatchCommonInitial: true}, {Word: "Foo"}}, helper("UTF8Foo")) + + require.Equal(t, []*wordInfo{{Word: "A"}}, helper("A")) + require.Equal(t, []*wordInfo{{Word: "ID", HasCommonInitial: true, MatchCommonInitial: true}}, helper("ID")) + require.Equal(t, []*wordInfo{{Word: "id", HasCommonInitial: true, MatchCommonInitial: true}}, helper("id")) + require.Equal(t, []*wordInfo{}, helper("")) + + require.Equal(t, []*wordInfo{{Word: "Related"}, {Word: "Urls"}}, helper("RelatedUrls")) + require.Equal(t, []*wordInfo{{Word: "ITicket"}}, helper("ITicket")) +} + +func TestCenter(t *testing.T) { + require.Equal(t, "fffff", center(3, "#", "fffff")) + require.Equal(t, "##fffff###", center(10, "#", "fffff")) + require.Equal(t, "###fffff###", center(11, "#", "fffff")) } diff --git a/codegen/testdata/gqlgen.yml b/codegen/testdata/gqlgen.yml new file mode 100644 index 0000000000..b32289be0d --- /dev/null +++ b/codegen/testdata/gqlgen.yml @@ -0,0 +1,21 @@ +schema: + - "testdata/schema.graphql" + +exec: + filename: out/generated.go +model: + filename: out/generated.go + +models: + ExistingModel: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingModel + ExistingInput: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInput + ExistingEnum: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingEnum + ExistingInterface: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInterface + ExistingUnion: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingUnion + + diff --git a/codegen/testdata/schema.graphql b/codegen/testdata/schema.graphql new file mode 100644 index 0000000000..5d49426216 --- /dev/null +++ b/codegen/testdata/schema.graphql @@ -0,0 +1,168 @@ +type Query { + invalidIdentifier: InvalidIdentifier + collision: It + recursive(input: RecursiveInputSlice): Boolean + nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean + nestedOutputs: [[OuterObject]] + keywords(input: Keywords): Boolean! + shapes: [Shape] + errorBubble: Error + modelMethods: ModelMethods + valid: String! + user(id: Int!): User! + nullableArg(arg: Int = 123): String + directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String + directiveInputNullable(arg: InputDirectives): String + directiveInput(arg: InputDirectives!): String +} + +type Subscription { + updated: String! + initPayload: String! +} + +type User { + id: Int! + friends: [User!]! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! +} + +type ModelMethods { + resolverField: Boolean! + noContext: Boolean! + withContext: Boolean! +} + +type InvalidIdentifier { + id: Int! +} + +type It { + id: ID! +} + +input RecursiveInputSlice { + self: [RecursiveInputSlice!] +} + +input InnerInput { + id:Int! +} + +input OuterInput { + inner: InnerInput! +} + +input InputDirectives { + text: String! @length(min: 0, max: 7, message: "not valid") + inner: InnerDirectives! + innerNullable: InnerDirectives +} + +input InnerDirectives { + message: String! @length(min: 1, message: "not valid") +} + +type OuterObject { + inner: InnerObject! +} + +type InnerObject { + id: Int! +} + +input Keywords { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! +} + +extend type Query { + keywordArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + ): Boolean! +} + +interface Shape { + area: Float +} +type Circle implements Shape { + radius: Float + area: Float +} +type Rectangle implements Shape { + length: Float + width: Float + area: Float +} +union ShapeUnion = Circle | Rectangle + +type ForcedResolver { + field: Circle +} + +type EmbeddedPointer { + ID: String + Title: String +} + +directive @length(min: Int!, max: Int, message: String!) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION +directive @range(min: Int = 0, max: Int, message: String) on ARGUMENT_DEFINITION + +enum Status { + OK + ERROR +} diff --git a/codegen/testserver/builtinscalar.graphql b/codegen/testserver/builtinscalar.graphql new file mode 100644 index 0000000000..deb8a9f624 --- /dev/null +++ b/codegen/testserver/builtinscalar.graphql @@ -0,0 +1,8 @@ + +""" +Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ +added to the TypeMap +""" +type Map { + id: ID! +} diff --git a/codegen/testserver/complexity.graphql b/codegen/testserver/complexity.graphql new file mode 100644 index 0000000000..2908586346 --- /dev/null +++ b/codegen/testserver/complexity.graphql @@ -0,0 +1,11 @@ +extend type Query { + overlapping: OverlappingFields +} + +type OverlappingFields { + oneFoo: Int! + twoFoo: Int! + oldFoo: Int! + newFoo: Int! + new_foo: Int! +} diff --git a/codegen/testserver/complexity_test.go b/codegen/testserver/complexity_test.go new file mode 100644 index 0000000000..2457eda8e8 --- /dev/null +++ b/codegen/testserver/complexity_test.go @@ -0,0 +1,46 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestComplexityCollisions(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + resolvers.QueryResolver.Overlapping = func(ctx context.Context) (fields *OverlappingFields, e error) { + return &OverlappingFields{ + Foo: 2, + NewFoo: 3, + }, nil + } + + resolvers.OverlappingFieldsResolver.OldFoo = func(ctx context.Context, obj *OverlappingFields) (i int, e error) { + return obj.Foo, nil + } + + var resp struct { + Overlapping struct { + OneFoo int `json:"oneFoo"` + TwoFoo int `json:"twoFoo"` + OldFoo int `json:"oldFoo"` + NewFoo int `json:"newFoo"` + New_foo int `json:"new_foo"` + } + } + c.MustPost(`query { overlapping { oneFoo, twoFoo, oldFoo, newFoo, new_foo } }`, &resp) + require.Equal(t, 2, resp.Overlapping.OneFoo) + require.Equal(t, 2, resp.Overlapping.TwoFoo) + require.Equal(t, 2, resp.Overlapping.OldFoo) + require.Equal(t, 3, resp.Overlapping.NewFoo) + require.Equal(t, 3, resp.Overlapping.New_foo) + +} diff --git a/codegen/testserver/directive_test.go b/codegen/testserver/directive_test.go new file mode 100644 index 0000000000..494be75f95 --- /dev/null +++ b/codegen/testserver/directive_test.go @@ -0,0 +1,228 @@ +package testserver + +import ( + "context" + "fmt" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestDirectives(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.DirectiveArg = func(ctx context.Context, arg string) (i *string, e error) { + s := "Ok" + return &s, nil + } + + resolvers.QueryResolver.DirectiveInput = func(ctx context.Context, arg InputDirectives) (i *string, e error) { + s := "Ok" + return &s, nil + } + + resolvers.QueryResolver.DirectiveInputNullable = func(ctx context.Context, arg *InputDirectives) (i *string, e error) { + s := "Ok" + return &s, nil + } + + resolvers.QueryResolver.DirectiveNullableArg = func(ctx context.Context, arg *int, arg2 *int) (i *string, e error) { + s := "Ok" + return &s, nil + } + + resolvers.QueryResolver.DirectiveInputType = func(ctx context.Context, arg InnerInput) (i *string, e error) { + s := "Ok" + return &s, nil + } + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{ + Resolvers: resolvers, + Directives: DirectiveRoot{ + Length: func(ctx context.Context, obj interface{}, next graphql.Resolver, min int, max *int) (interface{}, error) { + res, err := next(ctx) + if err != nil { + return nil, err + } + + s := res.(string) + if len(s) < min { + return nil, fmt.Errorf("too short") + } + if max != nil && len(s) > *max { + return nil, fmt.Errorf("too long") + } + return res, nil + }, + Range: func(ctx context.Context, obj interface{}, next graphql.Resolver, min *int, max *int) (interface{}, error) { + res, err := next(ctx) + if err != nil { + return nil, err + } + + switch res := res.(type) { + case int: + if min != nil && res < *min { + return nil, fmt.Errorf("too small") + } + if max != nil && res > *max { + return nil, fmt.Errorf("too large") + } + return next(ctx) + + case int64: + if min != nil && int(res) < *min { + return nil, fmt.Errorf("too small") + } + if max != nil && int(res) > *max { + return nil, fmt.Errorf("too large") + } + return next(ctx) + + case *int: + if min != nil && *res < *min { + return nil, fmt.Errorf("too small") + } + if max != nil && *res > *max { + return nil, fmt.Errorf("too large") + } + return next(ctx) + } + return nil, fmt.Errorf("unsupported type %T", res) + }, + Custom: func(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) { + return next(ctx) + }, + }, + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 1))) + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 2))) + }), + )) + c := client.New(srv.URL) + + t.Run("arg directives", func(t *testing.T) { + t.Run("when function errors on directives", func(t *testing.T) { + var resp struct { + DirectiveArg *string + } + + err := c.Post(`query { directiveArg(arg: "") }`, &resp) + + require.EqualError(t, err, `[{"message":"too short","path":["directiveArg"]}]`) + require.Nil(t, resp.DirectiveArg) + }) + t.Run("when function errors on nullable arg directives", func(t *testing.T) { + var resp struct { + DirectiveNullableArg *string + } + + err := c.Post(`query { directiveNullableArg(arg: -100) }`, &resp) + + require.EqualError(t, err, `[{"message":"too small","path":["directiveNullableArg"]}]`) + require.Nil(t, resp.DirectiveNullableArg) + }) + t.Run("when function success on nullable arg directives", func(t *testing.T) { + var resp struct { + DirectiveNullableArg *string + } + + err := c.Post(`query { directiveNullableArg }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveNullableArg) + }) + t.Run("when function success on valid nullable arg directives", func(t *testing.T) { + var resp struct { + DirectiveNullableArg *string + } + + err := c.Post(`query { directiveNullableArg(arg: 1) }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveNullableArg) + }) + t.Run("when function success", func(t *testing.T) { + var resp struct { + DirectiveArg *string + } + + err := c.Post(`query { directiveArg(arg: "test") }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveArg) + }) + }) + t.Run("input field directives", func(t *testing.T) { + t.Run("when function errors on directives", func(t *testing.T) { + var resp struct { + DirectiveInputNullable *string + } + + err := c.Post(`query { directiveInputNullable(arg: {text:"invalid text",inner:{message:"123"}}) }`, &resp) + + require.EqualError(t, err, `[{"message":"too long","path":["directiveInputNullable"]}]`) + require.Nil(t, resp.DirectiveInputNullable) + }) + t.Run("when function errors on inner directives", func(t *testing.T) { + var resp struct { + DirectiveInputNullable *string + } + + err := c.Post(`query { directiveInputNullable(arg: {text:"2",inner:{message:""}}) }`, &resp) + + require.EqualError(t, err, `[{"message":"too short","path":["directiveInputNullable"]}]`) + require.Nil(t, resp.DirectiveInputNullable) + }) + t.Run("when function errors on nullable inner directives", func(t *testing.T) { + var resp struct { + DirectiveInputNullable *string + } + + err := c.Post(`query { directiveInputNullable(arg: {text:"success",inner:{message:"1"},innerNullable:{message:""}}) }`, &resp) + + require.EqualError(t, err, `[{"message":"too short","path":["directiveInputNullable"]}]`) + require.Nil(t, resp.DirectiveInputNullable) + }) + t.Run("when function success", func(t *testing.T) { + var resp struct { + DirectiveInputNullable *string + } + + err := c.Post(`query { directiveInputNullable(arg: {text:"23",inner:{message:"1"}}) }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveInputNullable) + }) + t.Run("when function inner nullable success", func(t *testing.T) { + var resp struct { + DirectiveInputNullable *string + } + + err := c.Post(`query { directiveInputNullable(arg: {text:"23",inner:{message:"1"},innerNullable:{message:"success"}}) }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveInputNullable) + }) + t.Run("when arg has directive", func(t *testing.T) { + var resp struct { + DirectiveInputType *string + } + + err := c.Post(`query { directiveInputType(arg: {id: 1}) }`, &resp) + + require.Nil(t, err) + require.Equal(t, "Ok", *resp.DirectiveInputType) + }) + }) +} diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 3f97c620b1..7b9c87a1f4 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -7,8 +7,10 @@ import ( "context" "errors" "fmt" + "io" "strconv" "sync" + "time" introspection1 "github.com/99designs/gqlgen/codegen/testserver/introspection" "github.com/99designs/gqlgen/codegen/testserver/invalid-packagename" @@ -18,6 +20,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -36,29 +40,64 @@ type Config struct { type ResolverRoot interface { ForcedResolver() ForcedResolverResolver ModelMethods() ModelMethodsResolver + OverlappingFields() OverlappingFieldsResolver + Panics() PanicsResolver Query() QueryResolver Subscription() SubscriptionResolver User() UserResolver } type DirectiveRoot struct { + Custom func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) + + Length func(ctx context.Context, obj interface{}, next graphql.Resolver, min int, max *int) (res interface{}, err error) + + Range func(ctx context.Context, obj interface{}, next graphql.Resolver, min *int, max *int) (res interface{}, err error) } type ComplexityRoot struct { + A struct { + ID func(childComplexity int) int + } + + AIt struct { + ID func(childComplexity int) int + } + + AbIt struct { + ID func(childComplexity int) int + } + + Autobind struct { + IdInt func(childComplexity int) int + IdStr func(childComplexity int) int + Int func(childComplexity int) int + Int32 func(childComplexity int) int + Int64 func(childComplexity int) int + } + + B struct { + ID func(childComplexity int) int + } + Circle struct { - Radius func(childComplexity int) int Area func(childComplexity int) int + Radius func(childComplexity int) int + } + + EmbeddedDefaultScalar struct { + Value func(childComplexity int) int } EmbeddedPointer struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Title func(childComplexity int) int } Error struct { - Id func(childComplexity int) int ErrorOnNonRequiredField func(childComplexity int) int ErrorOnRequiredField func(childComplexity int) int + ID func(childComplexity int) int NilOnRequiredField func(childComplexity int) int } @@ -67,20 +106,29 @@ type ComplexityRoot struct { } InnerObject struct { - Id func(childComplexity int) int + ID func(childComplexity int) int } InvalidIdentifier struct { - Id func(childComplexity int) int + ID func(childComplexity int) int } It struct { - Id func(childComplexity int) int + ID func(childComplexity int) int + } + + Map struct { + ID func(childComplexity int) int + } + + MapStringInterfaceType struct { + A func(childComplexity int) int + B func(childComplexity int) int } ModelMethods struct { - ResolverField func(childComplexity int) int NoContext func(childComplexity int) int + ResolverField func(childComplexity int) int WithContext func(childComplexity int) int } @@ -88,37 +136,96 @@ type ComplexityRoot struct { Inner func(childComplexity int) int } + OverlappingFields struct { + Foo func(childComplexity int) int + NewFoo func(childComplexity int) int + OldFoo func(childComplexity int) int + } + + Panics struct { + ArgUnmarshal func(childComplexity int, u []MarshalPanic) int + FieldFuncMarshal func(childComplexity int, u []MarshalPanic) int + FieldScalarMarshal func(childComplexity int) int + } + Query struct { - InvalidIdentifier func(childComplexity int) int - Collision func(childComplexity int) int - MapInput func(childComplexity int, input *map[string]interface{}) int - Recursive func(childComplexity int, input *RecursiveInputSlice) int - NestedInputs func(childComplexity int, input [][]*OuterInput) int - NestedOutputs func(childComplexity int) int - Keywords func(childComplexity int, input *Keywords) int - Shapes func(childComplexity int) int - ErrorBubble func(childComplexity int) int - ModelMethods func(childComplexity int) int - Valid func(childComplexity int) int - User func(childComplexity int, id int) int - NullableArg func(childComplexity int, arg *int) int - KeywordArgs func(childComplexity int, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) int + Autobind func(childComplexity int) int + Collision func(childComplexity int) int + DefaultScalar func(childComplexity int, arg string) int + DeprecatedField func(childComplexity int) int + DirectiveArg func(childComplexity int, arg string) int + DirectiveInput func(childComplexity int, arg InputDirectives) int + DirectiveInputNullable func(childComplexity int, arg *InputDirectives) int + DirectiveInputType func(childComplexity int, arg InnerInput) int + DirectiveNullableArg func(childComplexity int, arg *int, arg2 *int) int + ErrorBubble func(childComplexity int) int + Fallback func(childComplexity int, arg FallbackToStringEncoding) int + InputSlice func(childComplexity int, arg []string) int + InvalidIdentifier func(childComplexity int) int + MapInput func(childComplexity int, input map[string]interface{}) int + MapStringInterface func(childComplexity int, in map[string]interface{}) int + ModelMethods func(childComplexity int) int + NestedInputs func(childComplexity int, input [][]*OuterInput) int + NestedOutputs func(childComplexity int) int + NullableArg func(childComplexity int, arg *int) int + OptionalUnion func(childComplexity int) int + Overlapping func(childComplexity int) int + Panics func(childComplexity int) int + Recursive func(childComplexity int, input *RecursiveInputSlice) int + ShapeUnion func(childComplexity int) int + Shapes func(childComplexity int) int + Slices func(childComplexity int) int + User func(childComplexity int, id int) int + Valid func(childComplexity int) int + ValidType func(childComplexity int) int } Rectangle struct { + Area func(childComplexity int) int Length func(childComplexity int) int Width func(childComplexity int) int - Area func(childComplexity int) int + } + + Slices struct { + Test1 func(childComplexity int) int + Test2 func(childComplexity int) int + Test3 func(childComplexity int) int + Test4 func(childComplexity int) int } Subscription struct { - Updated func(childComplexity int) int InitPayload func(childComplexity int) int + Updated func(childComplexity int) int } User struct { - Id func(childComplexity int) int + Created func(childComplexity int) int Friends func(childComplexity int) int + ID func(childComplexity int) int + Updated func(childComplexity int) int + } + + ValidType struct { + DifferentCase func(childComplexity int) int + DifferentCaseOld func(childComplexity int) int + ValidArgs func(childComplexity int, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string, _Arg string) int + ValidInputKeywords func(childComplexity int, input *ValidInput) int + } + + XXIt struct { + ID func(childComplexity int) int + } + + XxIt struct { + ID func(childComplexity int) int + } + + AsdfIt struct { + ID func(childComplexity int) int + } + + IIt struct { + ID func(childComplexity int) int } } @@ -128,21 +235,44 @@ type ForcedResolverResolver interface { type ModelMethodsResolver interface { ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) } +type OverlappingFieldsResolver interface { + OldFoo(ctx context.Context, obj *OverlappingFields) (int, error) +} +type PanicsResolver interface { + FieldScalarMarshal(ctx context.Context, obj *Panics) ([]MarshalPanic, error) + + ArgUnmarshal(ctx context.Context, obj *Panics, u []MarshalPanic) (bool, error) +} type QueryResolver interface { InvalidIdentifier(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) Collision(ctx context.Context) (*introspection1.It, error) - MapInput(ctx context.Context, input *map[string]interface{}) (*bool, error) + MapInput(ctx context.Context, input map[string]interface{}) (*bool, error) Recursive(ctx context.Context, input *RecursiveInputSlice) (*bool, error) NestedInputs(ctx context.Context, input [][]*OuterInput) (*bool, error) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) - Keywords(ctx context.Context, input *Keywords) (bool, error) - Shapes(ctx context.Context) ([]*Shape, error) + Shapes(ctx context.Context) ([]Shape, error) ErrorBubble(ctx context.Context) (*Error, error) ModelMethods(ctx context.Context) (*ModelMethods, error) Valid(ctx context.Context) (string, error) - User(ctx context.Context, id int) (User, error) + User(ctx context.Context, id int) (*User, error) NullableArg(ctx context.Context, arg *int) (*string, error) - KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) + DirectiveArg(ctx context.Context, arg string) (*string, error) + DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) + DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) + DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) + DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) + InputSlice(ctx context.Context, arg []string) (bool, error) + ShapeUnion(ctx context.Context) (ShapeUnion, error) + Autobind(ctx context.Context) (*Autobind, error) + DeprecatedField(ctx context.Context) (string, error) + Overlapping(ctx context.Context) (*OverlappingFields, error) + MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) + Panics(ctx context.Context) (*Panics, error) + DefaultScalar(ctx context.Context, arg string) (string, error) + Slices(ctx context.Context) (*Slices, error) + Fallback(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) + OptionalUnion(ctx context.Context) (TestUnion, error) + ValidType(ctx context.Context) (*ValidType, error) } type SubscriptionResolver interface { Updated(ctx context.Context) (<-chan string, error) @@ -152,725 +282,706 @@ type UserResolver interface { Friends(ctx context.Context, obj *User) ([]User, error) } -func field_Query_mapInput_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *map[string]interface{} - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 map[string]interface{} - if tmp != nil { - ptr1 = tmp.(map[string]interface{}) - arg0 = &ptr1 - } +type executableSchema struct { + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} - if err != nil { - return nil, err +func (e *executableSchema) Schema() *ast.Schema { + return parsedSchema +} + +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec + switch typeName + "." + field { + + case "A.ID": + if e.complexity.A.ID == nil { + break } - } - args["input"] = arg0 - return args, nil -} + return e.complexity.A.ID(childComplexity), true -func field_Query_recursive_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *RecursiveInputSlice - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 RecursiveInputSlice - if tmp != nil { - ptr1, err = UnmarshalRecursiveInputSlice(tmp) - arg0 = &ptr1 + case "AIt.ID": + if e.complexity.AIt.ID == nil { + break } - if err != nil { - return nil, err + return e.complexity.AIt.ID(childComplexity), true + + case "AbIt.ID": + if e.complexity.AbIt.ID == nil { + break } - } - args["input"] = arg0 - return args, nil -} + return e.complexity.AbIt.ID(childComplexity), true -func field_Query_nestedInputs_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 [][]*OuterInput - if tmp, ok := rawArgs["input"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } + case "Autobind.IdInt": + if e.complexity.Autobind.IdInt == nil { + break } - arg0 = make([][]*OuterInput, len(rawIf1)) - for idx1 := range rawIf1 { - var rawIf2 []interface{} - if rawIf1[idx1] != nil { - if tmp1, ok := rawIf1[idx1].([]interface{}); ok { - rawIf2 = tmp1 - } else { - rawIf2 = []interface{}{rawIf1[idx1]} - } - } - arg0[idx1] = make([]*OuterInput, len(rawIf2)) - for idx2 := range rawIf2 { - var ptr3 OuterInput - if rawIf2[idx2] != nil { - ptr3, err = UnmarshalOuterInput(rawIf2[idx2]) - arg0[idx1][idx2] = &ptr3 - } - } + + return e.complexity.Autobind.IdInt(childComplexity), true + + case "Autobind.IdStr": + if e.complexity.Autobind.IdStr == nil { + break } - if err != nil { - return nil, err + + return e.complexity.Autobind.IdStr(childComplexity), true + + case "Autobind.Int": + if e.complexity.Autobind.Int == nil { + break } - } - args["input"] = arg0 - return args, nil -} + return e.complexity.Autobind.Int(childComplexity), true -func field_Query_keywords_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *Keywords - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 Keywords - if tmp != nil { - ptr1, err = UnmarshalKeywords(tmp) - arg0 = &ptr1 + case "Autobind.Int32": + if e.complexity.Autobind.Int32 == nil { + break } - if err != nil { - return nil, err + return e.complexity.Autobind.Int32(childComplexity), true + + case "Autobind.Int64": + if e.complexity.Autobind.Int64 == nil { + break } - } - args["input"] = arg0 - return args, nil -} + return e.complexity.Autobind.Int64(childComplexity), true -func field_Query_user_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - return nil, err + case "B.ID": + if e.complexity.B.ID == nil { + break } - } - args["id"] = arg0 - return args, nil -} + return e.complexity.B.ID(childComplexity), true -func field_Query_nullableArg_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["arg"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 + case "Circle.Area": + if e.complexity.Circle.Area == nil { + break } - if err != nil { - return nil, err + return e.complexity.Circle.Area(childComplexity), true + + case "Circle.Radius": + if e.complexity.Circle.Radius == nil { + break } - } - args["arg"] = arg0 - return args, nil -} + return e.complexity.Circle.Radius(childComplexity), true -func field_Query_keywordArgs_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["break"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + case "EmbeddedDefaultScalar.Value": + if e.complexity.EmbeddedDefaultScalar.Value == nil { + break } - } - args["break"] = arg0 - var arg1 string - if tmp, ok := rawArgs["default"]; ok { - var err error - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.EmbeddedDefaultScalar.Value(childComplexity), true + + case "EmbeddedPointer.ID": + if e.complexity.EmbeddedPointer.ID == nil { + break } - } - args["default"] = arg1 - var arg2 string - if tmp, ok := rawArgs["func"]; ok { - var err error - arg2, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.EmbeddedPointer.ID(childComplexity), true + + case "EmbeddedPointer.Title": + if e.complexity.EmbeddedPointer.Title == nil { + break } - } - args["func"] = arg2 - var arg3 string - if tmp, ok := rawArgs["interface"]; ok { - var err error - arg3, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.EmbeddedPointer.Title(childComplexity), true + + case "Error.ErrorOnNonRequiredField": + if e.complexity.Error.ErrorOnNonRequiredField == nil { + break } - } - args["interface"] = arg3 - var arg4 string - if tmp, ok := rawArgs["select"]; ok { - var err error - arg4, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.Error.ErrorOnNonRequiredField(childComplexity), true + + case "Error.ErrorOnRequiredField": + if e.complexity.Error.ErrorOnRequiredField == nil { + break } - } - args["select"] = arg4 - var arg5 string - if tmp, ok := rawArgs["case"]; ok { - var err error - arg5, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.Error.ErrorOnRequiredField(childComplexity), true + + case "Error.ID": + if e.complexity.Error.ID == nil { + break } - } - args["case"] = arg5 - var arg6 string - if tmp, ok := rawArgs["defer"]; ok { - var err error - arg6, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.Error.ID(childComplexity), true + + case "Error.NilOnRequiredField": + if e.complexity.Error.NilOnRequiredField == nil { + break } - } - args["defer"] = arg6 - var arg7 string - if tmp, ok := rawArgs["go"]; ok { - var err error - arg7, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.Error.NilOnRequiredField(childComplexity), true + + case "ForcedResolver.Field": + if e.complexity.ForcedResolver.Field == nil { + break } - } - args["go"] = arg7 - var arg8 string - if tmp, ok := rawArgs["map"]; ok { - var err error - arg8, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.ForcedResolver.Field(childComplexity), true + + case "InnerObject.ID": + if e.complexity.InnerObject.ID == nil { + break } - } - args["map"] = arg8 - var arg9 string - if tmp, ok := rawArgs["struct"]; ok { - var err error - arg9, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.InnerObject.ID(childComplexity), true + + case "InvalidIdentifier.ID": + if e.complexity.InvalidIdentifier.ID == nil { + break } - } - args["struct"] = arg9 - var arg10 string - if tmp, ok := rawArgs["chan"]; ok { - var err error - arg10, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.InvalidIdentifier.ID(childComplexity), true + + case "It.ID": + if e.complexity.It.ID == nil { + break } - } - args["chan"] = arg10 - var arg11 string - if tmp, ok := rawArgs["else"]; ok { - var err error - arg11, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + + return e.complexity.It.ID(childComplexity), true + + case "Map.ID": + if e.complexity.Map.ID == nil { + break } - } - args["else"] = arg11 - var arg12 string - if tmp, ok := rawArgs["goto"]; ok { - var err error - arg12, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["goto"] = arg12 - var arg13 string - if tmp, ok := rawArgs["package"]; ok { - var err error - arg13, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["package"] = arg13 - var arg14 string - if tmp, ok := rawArgs["switch"]; ok { - var err error - arg14, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["switch"] = arg14 - var arg15 string - if tmp, ok := rawArgs["const"]; ok { - var err error - arg15, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["const"] = arg15 - var arg16 string - if tmp, ok := rawArgs["fallthrough"]; ok { - var err error - arg16, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["fallthrough"] = arg16 - var arg17 string - if tmp, ok := rawArgs["if"]; ok { - var err error - arg17, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["if"] = arg17 - var arg18 string - if tmp, ok := rawArgs["range"]; ok { - var err error - arg18, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["range"] = arg18 - var arg19 string - if tmp, ok := rawArgs["type"]; ok { - var err error - arg19, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["type"] = arg19 - var arg20 string - if tmp, ok := rawArgs["continue"]; ok { - var err error - arg20, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["continue"] = arg20 - var arg21 string - if tmp, ok := rawArgs["for"]; ok { - var err error - arg21, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["for"] = arg21 - var arg22 string - if tmp, ok := rawArgs["import"]; ok { - var err error - arg22, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["import"] = arg22 - var arg23 string - if tmp, ok := rawArgs["return"]; ok { - var err error - arg23, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["return"] = arg23 - var arg24 string - if tmp, ok := rawArgs["var"]; ok { - var err error - arg24, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["var"] = arg24 - return args, nil - -} -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} + return e.complexity.Map.ID(childComplexity), true -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err + case "MapStringInterfaceType.A": + if e.complexity.MapStringInterfaceType.A == nil { + break } - } - args["includeDeprecated"] = arg0 - return args, nil -} - -type executableSchema struct { - resolvers ResolverRoot - directives DirectiveRoot - complexity ComplexityRoot -} - -func (e *executableSchema) Schema() *ast.Schema { - return parsedSchema -} - -func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { - switch typeName + "." + field { + return e.complexity.MapStringInterfaceType.A(childComplexity), true - case "Circle.radius": - if e.complexity.Circle.Radius == nil { + case "MapStringInterfaceType.B": + if e.complexity.MapStringInterfaceType.B == nil { break } - return e.complexity.Circle.Radius(childComplexity), true + return e.complexity.MapStringInterfaceType.B(childComplexity), true - case "Circle.area": - if e.complexity.Circle.Area == nil { + case "ModelMethods.NoContext": + if e.complexity.ModelMethods.NoContext == nil { break } - return e.complexity.Circle.Area(childComplexity), true + return e.complexity.ModelMethods.NoContext(childComplexity), true - case "EmbeddedPointer.ID": - if e.complexity.EmbeddedPointer.Id == nil { + case "ModelMethods.ResolverField": + if e.complexity.ModelMethods.ResolverField == nil { break } - return e.complexity.EmbeddedPointer.Id(childComplexity), true + return e.complexity.ModelMethods.ResolverField(childComplexity), true - case "EmbeddedPointer.Title": - if e.complexity.EmbeddedPointer.Title == nil { + case "ModelMethods.WithContext": + if e.complexity.ModelMethods.WithContext == nil { break } - return e.complexity.EmbeddedPointer.Title(childComplexity), true + return e.complexity.ModelMethods.WithContext(childComplexity), true - case "Error.id": - if e.complexity.Error.Id == nil { + case "OuterObject.Inner": + if e.complexity.OuterObject.Inner == nil { break } - return e.complexity.Error.Id(childComplexity), true + return e.complexity.OuterObject.Inner(childComplexity), true - case "Error.errorOnNonRequiredField": - if e.complexity.Error.ErrorOnNonRequiredField == nil { + case "OverlappingFields.Foo": + if e.complexity.OverlappingFields.Foo == nil { break } - return e.complexity.Error.ErrorOnNonRequiredField(childComplexity), true + return e.complexity.OverlappingFields.Foo(childComplexity), true - case "Error.errorOnRequiredField": - if e.complexity.Error.ErrorOnRequiredField == nil { + case "OverlappingFields.NewFoo": + if e.complexity.OverlappingFields.NewFoo == nil { break } - return e.complexity.Error.ErrorOnRequiredField(childComplexity), true + return e.complexity.OverlappingFields.NewFoo(childComplexity), true - case "Error.nilOnRequiredField": - if e.complexity.Error.NilOnRequiredField == nil { + case "OverlappingFields.OldFoo": + if e.complexity.OverlappingFields.OldFoo == nil { break } - return e.complexity.Error.NilOnRequiredField(childComplexity), true + return e.complexity.OverlappingFields.OldFoo(childComplexity), true - case "ForcedResolver.field": - if e.complexity.ForcedResolver.Field == nil { + case "Panics.ArgUnmarshal": + if e.complexity.Panics.ArgUnmarshal == nil { break } - return e.complexity.ForcedResolver.Field(childComplexity), true - - case "InnerObject.id": - if e.complexity.InnerObject.Id == nil { - break + args, err := ec.field_Panics_argUnmarshal_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.InnerObject.Id(childComplexity), true + return e.complexity.Panics.ArgUnmarshal(childComplexity, args["u"].([]MarshalPanic)), true - case "InvalidIdentifier.id": - if e.complexity.InvalidIdentifier.Id == nil { + case "Panics.FieldFuncMarshal": + if e.complexity.Panics.FieldFuncMarshal == nil { break } - return e.complexity.InvalidIdentifier.Id(childComplexity), true - - case "It.id": - if e.complexity.It.Id == nil { - break + args, err := ec.field_Panics_fieldFuncMarshal_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.It.Id(childComplexity), true + return e.complexity.Panics.FieldFuncMarshal(childComplexity, args["u"].([]MarshalPanic)), true - case "ModelMethods.resolverField": - if e.complexity.ModelMethods.ResolverField == nil { + case "Panics.FieldScalarMarshal": + if e.complexity.Panics.FieldScalarMarshal == nil { break } - return e.complexity.ModelMethods.ResolverField(childComplexity), true + return e.complexity.Panics.FieldScalarMarshal(childComplexity), true - case "ModelMethods.noContext": - if e.complexity.ModelMethods.NoContext == nil { + case "Query.Autobind": + if e.complexity.Query.Autobind == nil { break } - return e.complexity.ModelMethods.NoContext(childComplexity), true + return e.complexity.Query.Autobind(childComplexity), true - case "ModelMethods.withContext": - if e.complexity.ModelMethods.WithContext == nil { + case "Query.Collision": + if e.complexity.Query.Collision == nil { break } - return e.complexity.ModelMethods.WithContext(childComplexity), true + return e.complexity.Query.Collision(childComplexity), true - case "OuterObject.inner": - if e.complexity.OuterObject.Inner == nil { + case "Query.DefaultScalar": + if e.complexity.Query.DefaultScalar == nil { break } - return e.complexity.OuterObject.Inner(childComplexity), true - - case "Query.invalidIdentifier": - if e.complexity.Query.InvalidIdentifier == nil { - break + args, err := ec.field_Query_defaultScalar_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.Query.InvalidIdentifier(childComplexity), true + return e.complexity.Query.DefaultScalar(childComplexity, args["arg"].(string)), true - case "Query.collision": - if e.complexity.Query.Collision == nil { + case "Query.DeprecatedField": + if e.complexity.Query.DeprecatedField == nil { break } - return e.complexity.Query.Collision(childComplexity), true + return e.complexity.Query.DeprecatedField(childComplexity), true - case "Query.mapInput": - if e.complexity.Query.MapInput == nil { + case "Query.DirectiveArg": + if e.complexity.Query.DirectiveArg == nil { break } - args, err := field_Query_mapInput_args(rawArgs) + args, err := ec.field_Query_directiveArg_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.MapInput(childComplexity, args["input"].(*map[string]interface{})), true + return e.complexity.Query.DirectiveArg(childComplexity, args["arg"].(string)), true - case "Query.recursive": - if e.complexity.Query.Recursive == nil { + case "Query.DirectiveInput": + if e.complexity.Query.DirectiveInput == nil { break } - args, err := field_Query_recursive_args(rawArgs) + args, err := ec.field_Query_directiveInput_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Recursive(childComplexity, args["input"].(*RecursiveInputSlice)), true + return e.complexity.Query.DirectiveInput(childComplexity, args["arg"].(InputDirectives)), true - case "Query.nestedInputs": - if e.complexity.Query.NestedInputs == nil { + case "Query.DirectiveInputNullable": + if e.complexity.Query.DirectiveInputNullable == nil { break } - args, err := field_Query_nestedInputs_args(rawArgs) + args, err := ec.field_Query_directiveInputNullable_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.NestedInputs(childComplexity, args["input"].([][]*OuterInput)), true + return e.complexity.Query.DirectiveInputNullable(childComplexity, args["arg"].(*InputDirectives)), true - case "Query.nestedOutputs": - if e.complexity.Query.NestedOutputs == nil { + case "Query.DirectiveInputType": + if e.complexity.Query.DirectiveInputType == nil { break } - return e.complexity.Query.NestedOutputs(childComplexity), true + args, err := ec.field_Query_directiveInputType_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } - case "Query.keywords": - if e.complexity.Query.Keywords == nil { + return e.complexity.Query.DirectiveInputType(childComplexity, args["arg"].(InnerInput)), true + + case "Query.DirectiveNullableArg": + if e.complexity.Query.DirectiveNullableArg == nil { break } - args, err := field_Query_keywords_args(rawArgs) + args, err := ec.field_Query_directiveNullableArg_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Keywords(childComplexity, args["input"].(*Keywords)), true + return e.complexity.Query.DirectiveNullableArg(childComplexity, args["arg"].(*int), args["arg2"].(*int)), true - case "Query.shapes": - if e.complexity.Query.Shapes == nil { + case "Query.ErrorBubble": + if e.complexity.Query.ErrorBubble == nil { break } - return e.complexity.Query.Shapes(childComplexity), true + return e.complexity.Query.ErrorBubble(childComplexity), true - case "Query.errorBubble": - if e.complexity.Query.ErrorBubble == nil { + case "Query.Fallback": + if e.complexity.Query.Fallback == nil { break } - return e.complexity.Query.ErrorBubble(childComplexity), true + args, err := ec.field_Query_fallback_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } - case "Query.modelMethods": - if e.complexity.Query.ModelMethods == nil { + return e.complexity.Query.Fallback(childComplexity, args["arg"].(FallbackToStringEncoding)), true + + case "Query.InputSlice": + if e.complexity.Query.InputSlice == nil { break } - return e.complexity.Query.ModelMethods(childComplexity), true + args, err := ec.field_Query_inputSlice_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } - case "Query.valid": - if e.complexity.Query.Valid == nil { + return e.complexity.Query.InputSlice(childComplexity, args["arg"].([]string)), true + + case "Query.InvalidIdentifier": + if e.complexity.Query.InvalidIdentifier == nil { break } - return e.complexity.Query.Valid(childComplexity), true + return e.complexity.Query.InvalidIdentifier(childComplexity), true - case "Query.user": - if e.complexity.Query.User == nil { + case "Query.MapInput": + if e.complexity.Query.MapInput == nil { break } - args, err := field_Query_user_args(rawArgs) + args, err := ec.field_Query_mapInput_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.User(childComplexity, args["id"].(int)), true + return e.complexity.Query.MapInput(childComplexity, args["input"].(map[string]interface{})), true - case "Query.nullableArg": - if e.complexity.Query.NullableArg == nil { + case "Query.MapStringInterface": + if e.complexity.Query.MapStringInterface == nil { break } - args, err := field_Query_nullableArg_args(rawArgs) + args, err := ec.field_Query_mapStringInterface_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.NullableArg(childComplexity, args["arg"].(*int)), true + return e.complexity.Query.MapStringInterface(childComplexity, args["in"].(map[string]interface{})), true + + case "Query.ModelMethods": + if e.complexity.Query.ModelMethods == nil { + break + } - case "Query.keywordArgs": - if e.complexity.Query.KeywordArgs == nil { + return e.complexity.Query.ModelMethods(childComplexity), true + + case "Query.NestedInputs": + if e.complexity.Query.NestedInputs == nil { break } - args, err := field_Query_keywordArgs_args(rawArgs) + args, err := ec.field_Query_nestedInputs_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.KeywordArgs(childComplexity, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)), true + return e.complexity.Query.NestedInputs(childComplexity, args["input"].([][]*OuterInput)), true - case "Rectangle.length": - if e.complexity.Rectangle.Length == nil { + case "Query.NestedOutputs": + if e.complexity.Query.NestedOutputs == nil { break } - return e.complexity.Rectangle.Length(childComplexity), true + return e.complexity.Query.NestedOutputs(childComplexity), true - case "Rectangle.width": - if e.complexity.Rectangle.Width == nil { + case "Query.NullableArg": + if e.complexity.Query.NullableArg == nil { break } - return e.complexity.Rectangle.Width(childComplexity), true - - case "Rectangle.area": - if e.complexity.Rectangle.Area == nil { - break + args, err := ec.field_Query_nullableArg_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.Rectangle.Area(childComplexity), true + return e.complexity.Query.NullableArg(childComplexity, args["arg"].(*int)), true - case "Subscription.updated": - if e.complexity.Subscription.Updated == nil { + case "Query.OptionalUnion": + if e.complexity.Query.OptionalUnion == nil { break } - return e.complexity.Subscription.Updated(childComplexity), true + return e.complexity.Query.OptionalUnion(childComplexity), true - case "Subscription.initPayload": - if e.complexity.Subscription.InitPayload == nil { + case "Query.Overlapping": + if e.complexity.Query.Overlapping == nil { break } - return e.complexity.Subscription.InitPayload(childComplexity), true + return e.complexity.Query.Overlapping(childComplexity), true - case "User.id": - if e.complexity.User.Id == nil { + case "Query.Panics": + if e.complexity.Query.Panics == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.Query.Panics(childComplexity), true - case "User.friends": - if e.complexity.User.Friends == nil { + case "Query.Recursive": + if e.complexity.Query.Recursive == nil { + break + } + + args, err := ec.field_Query_recursive_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Recursive(childComplexity, args["input"].(*RecursiveInputSlice)), true + + case "Query.ShapeUnion": + if e.complexity.Query.ShapeUnion == nil { + break + } + + return e.complexity.Query.ShapeUnion(childComplexity), true + + case "Query.Shapes": + if e.complexity.Query.Shapes == nil { + break + } + + return e.complexity.Query.Shapes(childComplexity), true + + case "Query.Slices": + if e.complexity.Query.Slices == nil { + break + } + + return e.complexity.Query.Slices(childComplexity), true + + case "Query.User": + if e.complexity.Query.User == nil { + break + } + + args, err := ec.field_Query_user_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.User(childComplexity, args["id"].(int)), true + + case "Query.Valid": + if e.complexity.Query.Valid == nil { + break + } + + return e.complexity.Query.Valid(childComplexity), true + + case "Query.ValidType": + if e.complexity.Query.ValidType == nil { + break + } + + return e.complexity.Query.ValidType(childComplexity), true + + case "Rectangle.Area": + if e.complexity.Rectangle.Area == nil { + break + } + + return e.complexity.Rectangle.Area(childComplexity), true + + case "Rectangle.Length": + if e.complexity.Rectangle.Length == nil { + break + } + + return e.complexity.Rectangle.Length(childComplexity), true + + case "Rectangle.Width": + if e.complexity.Rectangle.Width == nil { + break + } + + return e.complexity.Rectangle.Width(childComplexity), true + + case "Slices.Test1": + if e.complexity.Slices.Test1 == nil { + break + } + + return e.complexity.Slices.Test1(childComplexity), true + + case "Slices.Test2": + if e.complexity.Slices.Test2 == nil { + break + } + + return e.complexity.Slices.Test2(childComplexity), true + + case "Slices.Test3": + if e.complexity.Slices.Test3 == nil { + break + } + + return e.complexity.Slices.Test3(childComplexity), true + + case "Slices.Test4": + if e.complexity.Slices.Test4 == nil { + break + } + + return e.complexity.Slices.Test4(childComplexity), true + + case "Subscription.InitPayload": + if e.complexity.Subscription.InitPayload == nil { + break + } + + return e.complexity.Subscription.InitPayload(childComplexity), true + + case "Subscription.Updated": + if e.complexity.Subscription.Updated == nil { + break + } + + return e.complexity.Subscription.Updated(childComplexity), true + + case "User.Created": + if e.complexity.User.Created == nil { + break + } + + return e.complexity.User.Created(childComplexity), true + + case "User.Friends": + if e.complexity.User.Friends == nil { break } return e.complexity.User.Friends(childComplexity), true + case "User.ID": + if e.complexity.User.ID == nil { + break + } + + return e.complexity.User.ID(childComplexity), true + + case "User.Updated": + if e.complexity.User.Updated == nil { + break + } + + return e.complexity.User.Updated(childComplexity), true + + case "ValidType.DifferentCase": + if e.complexity.ValidType.DifferentCase == nil { + break + } + + return e.complexity.ValidType.DifferentCase(childComplexity), true + + case "ValidType.DifferentCaseOld": + if e.complexity.ValidType.DifferentCaseOld == nil { + break + } + + return e.complexity.ValidType.DifferentCaseOld(childComplexity), true + + case "ValidType.ValidArgs": + if e.complexity.ValidType.ValidArgs == nil { + break + } + + args, err := ec.field_ValidType_validArgs_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.ValidType.ValidArgs(childComplexity, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string), args["_"].(string)), true + + case "ValidType.ValidInputKeywords": + if e.complexity.ValidType.ValidInputKeywords == nil { + break + } + + args, err := ec.field_ValidType_validInputKeywords_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.ValidType.ValidInputKeywords(childComplexity, args["input"].(*ValidInput)), true + + case "XXIt.ID": + if e.complexity.XXIt.ID == nil { + break + } + + return e.complexity.XXIt.ID(childComplexity), true + + case "XxIt.ID": + if e.complexity.XxIt.ID == nil { + break + } + + return e.complexity.XxIt.ID(childComplexity), true + + case "asdfIt.ID": + if e.complexity.AsdfIt.ID == nil { + break + } + + return e.complexity.AsdfIt.ID(childComplexity), true + + case "iIt.ID": + if e.complexity.IIt.ID == nil { + break + } + + return e.complexity.IIt.ID(childComplexity), true + } return 0, false } @@ -888,7 +999,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -933,1471 +1045,5640 @@ type executionContext struct { *executableSchema } -var circleImplementors = []string{"Circle", "Shape"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, obj *Circle) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, circleImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Circle") - case "radius": - out.Values[i] = ec._Circle_radius(ctx, field, obj) - case "area": - out.Values[i] = ec._Circle_area(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + rctx := graphql.GetResolverContext(ctx) + for _, d := range rctx.Field.Definition.Directives { + switch d.Name { + case "custom": + if ec.directives.Custom != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.Custom(ctx, obj, n) + } + } + case "length": + if ec.directives.Length != nil { + rawArgs := d.ArgumentMap(ec.Variables) + args, err := ec.dir_length_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return nil + } + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.Length(ctx, obj, n, args["min"].(int), args["max"].(*int)) + } + } + case "range": + if ec.directives.Range != nil { + rawArgs := d.ArgumentMap(ec.Variables) + args, err := ec.dir_range_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return nil + } + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.Range(ctx, obj, n, args["min"].(*int), args["max"].(*int)) + } + } } } - - if invalid { - return graphql.Null + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil } - return out + return res } -// nolint: vetshadow -func (ec *executionContext) _Circle_radius(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Circle", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Radius, nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(float64) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return introspection.WrapSchema(parsedSchema), nil } -// nolint: vetshadow -func (ec *executionContext) _Circle_area(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Circle", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Area(), nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(float64) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var embeddedPointerImplementors = []string{"EmbeddedPointer"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _EmbeddedPointer(ctx context.Context, sel ast.SelectionSet, obj *EmbeddedPointerModel) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, embeddedPointerImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "builtinscalar.graphql", Input: ` +""" +Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ +added to the TypeMap +""" +type Map { + id: ID! +} +`}, + &ast.Source{Name: "complexity.graphql", Input: `extend type Query { + overlapping: OverlappingFields +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("EmbeddedPointer") - case "ID": - out.Values[i] = ec._EmbeddedPointer_ID(ctx, field, obj) - case "Title": - out.Values[i] = ec._EmbeddedPointer_Title(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } +type OverlappingFields { + oneFoo: Int! + twoFoo: Int! + oldFoo: Int! + newFoo: Int! + new_foo: Int! +} +`}, + &ast.Source{Name: "maps.graphql", Input: `extend type Query { + mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType +} - if invalid { - return graphql.Null - } - return out +type MapStringInterfaceType { + a: String + b: Int } -// nolint: vetshadow -func (ec *executionContext) _EmbeddedPointer_ID(ctx context.Context, field graphql.CollectedField, obj *EmbeddedPointerModel) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "EmbeddedPointer", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) +input MapStringInterfaceInput { + a: String + b: Int } - -// nolint: vetshadow -func (ec *executionContext) _EmbeddedPointer_Title(ctx context.Context, field graphql.CollectedField, obj *EmbeddedPointerModel) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "EmbeddedPointer", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Title, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) +`}, + &ast.Source{Name: "panics.graphql", Input: `extend type Query { + panics: Panics } -var errorImplementors = []string{"Error"} +type Panics { + fieldScalarMarshal: [MarshalPanic!]! + fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! + argUnmarshal(u: [MarshalPanic!]!): Boolean! -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, obj *Error) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, errorImplementors) +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +scalar MarshalPanic +`}, + &ast.Source{Name: "scalar_default.graphql", Input: `extend type Query { + defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Error") - case "id": - out.Values[i] = ec._Error_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "errorOnNonRequiredField": - out.Values[i] = ec._Error_errorOnNonRequiredField(ctx, field, obj) - case "errorOnRequiredField": - out.Values[i] = ec._Error_errorOnRequiredField(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "nilOnRequiredField": - out.Values[i] = ec._Error_nilOnRequiredField(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } +""" This doesnt have an implementation in the typemap, so it should act like a string """ +scalar DefaultScalarImplementation - if invalid { - return graphql.Null - } - return out +type EmbeddedDefaultScalar { + value: DefaultScalarImplementation +} +`}, + &ast.Source{Name: "schema.graphql", Input: `type Query { + invalidIdentifier: InvalidIdentifier + collision: It + mapInput(input: Changes): Boolean + recursive(input: RecursiveInputSlice): Boolean + nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean + nestedOutputs: [[OuterObject]] + shapes: [Shape] + errorBubble: Error + modelMethods: ModelMethods + valid: String! + user(id: Int!): User! + nullableArg(arg: Int = 123): String + directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String + directiveInputNullable(arg: InputDirectives): String + directiveInput(arg: InputDirectives!): String + directiveInputType(arg: InnerInput! @custom): String + inputSlice(arg: [String!]!): Boolean! + shapeUnion: ShapeUnion! + autobind: Autobind + deprecatedField: String! @deprecated(reason: "test deprecated directive") } -// nolint: vetshadow -func (ec *executionContext) _Error_id(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Error", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) +type Subscription { + updated: String! + initPayload: String! } -// nolint: vetshadow -func (ec *executionContext) _Error_errorOnNonRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Error", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ErrorOnNonRequiredField() - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) +type User { + id: Int! + friends: [User!]! + created: Time! + updated: Time } -// nolint: vetshadow -func (ec *executionContext) _Error_errorOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Error", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ErrorOnRequiredField() - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) +type Autobind { + int: Int! + int32: Int! + int64: Int! + + idStr: ID! + idInt: ID! } -// nolint: vetshadow -func (ec *executionContext) _Error_nilOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Error", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.NilOnRequiredField(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! +} - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - return graphql.MarshalString(*res) +type ModelMethods { + resolverField: Boolean! + noContext: Boolean! + withContext: Boolean! } -var forcedResolverImplementors = []string{"ForcedResolver"} +type InvalidIdentifier { + id: Int! +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.SelectionSet, obj *ForcedResolver) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, forcedResolverImplementors) +type It { + id: ID! +} - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +input Changes { + a: Int + b: Int +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("ForcedResolver") - case "field": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._ForcedResolver_field(ctx, field, obj) - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out +input RecursiveInputSlice { + self: [RecursiveInputSlice!] } -// nolint: vetshadow -func (ec *executionContext) _ForcedResolver_field(ctx context.Context, field graphql.CollectedField, obj *ForcedResolver) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "ForcedResolver", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.ForcedResolver().Field(rctx, obj) - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*Circle) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +input InnerInput { + id:Int! +} - if res == nil { - return graphql.Null - } +input OuterInput { + inner: InnerInput! +} + +scalar ThirdParty - return ec._Circle(ctx, field.Selections, res) +input InputDirectives { + text: String! @length(min: 0, max: 7, message: "not valid") + inner: InnerDirectives! + innerNullable: InnerDirectives + thirdParty: ThirdParty @length(min: 0, max: 7, message: "not valid") } -var innerObjectImplementors = []string{"InnerObject"} +input InnerDirectives { + message: String! @length(min: 1, message: "not valid") +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionSet, obj *InnerObject) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, innerObjectImplementors) +type OuterObject { + inner: InnerObject! +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +type InnerObject { + id: Int! +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("InnerObject") - case "id": - out.Values[i] = ec._InnerObject_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } +interface Shape { + area: Float +} +type Circle implements Shape { + radius: Float + area: Float +} +type Rectangle implements Shape { + length: Float + width: Float + area: Float +} +union ShapeUnion = Circle | Rectangle - if invalid { - return graphql.Null - } - return out +type ForcedResolver { + field: Circle } -// nolint: vetshadow -func (ec *executionContext) _InnerObject_id(ctx context.Context, field graphql.CollectedField, obj *InnerObject) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "InnerObject", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(int) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) +type EmbeddedPointer { + ID: String + Title: String } -var invalidIdentifierImplementors = []string{"InvalidIdentifier"} +directive @length(min: Int!, max: Int) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION +directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION +directive @custom on ARGUMENT_DEFINITION -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.SelectionSet, obj *invalid_packagename.InvalidIdentifier) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, invalidIdentifierImplementors) +enum Status { + OK + ERROR +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +scalar Time +`}, + &ast.Source{Name: "slices.graphql", Input: `extend type Query { + slices: Slices +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("InvalidIdentifier") - case "id": - out.Values[i] = ec._InvalidIdentifier_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } +type Slices { + test1: [String] + test2: [String!] + test3: [String]! + test4: [String!]! +} +`}, + &ast.Source{Name: "typefallback.graphql", Input: `extend type Query { + fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! +} - if invalid { - return graphql.Null - } - return out +enum FallbackToStringEncoding { + A + B + C +} +`}, + &ast.Source{Name: "useptr.graphql", Input: `type A { + id: ID! } -// nolint: vetshadow -func (ec *executionContext) _InvalidIdentifier_id(ctx context.Context, field graphql.CollectedField, obj *invalid_packagename.InvalidIdentifier) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "InvalidIdentifier", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(int) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) +type B { + id: ID! } -var itImplementors = []string{"It"} +union TestUnion = A | B -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj *introspection1.It) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, itImplementors) +extend type Query { + optionalUnion: TestUnion +} +`}, + &ast.Source{Name: "validtypes.graphql", Input: `extend type Query { + validType: ValidType +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +""" These things are all valid, but without care generate invalid go code """ +type ValidType { + differentCase: String! + different_case: String! + validInputKeywords(input: ValidInput): Boolean! + validArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + _: String!, + ): Boolean! +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("It") - case "id": - out.Values[i] = ec._It_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +input ValidInput { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! + _: String! +} + +`}, + &ast.Source{Name: "weird_type_cases.graphql", Input: `# regression test for https://github.com/99designs/gqlgen/issues/583 + +type asdfIt { id: ID! } +type iIt { id: ID! } +type AIt { id: ID! } +type XXIt { id: ID! } +type AbIt { id: ID! } +type XxIt { id: ID! } +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) dir_length_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["min"]; ok { + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err } } - - if invalid { - return graphql.Null + args["min"] = arg0 + var arg1 *int + if tmp, ok := rawArgs["max"]; ok { + arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["max"] = arg1 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedField, obj *introspection1.It) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "It", - Args: nil, - Field: field, +func (ec *executionContext) dir_range_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["min"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + args["min"] = arg0 + var arg1 *int + if tmp, ok := rawArgs["max"]; ok { + arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + args["max"] = arg1 + return args, nil } -var modelMethodsImplementors = []string{"ModelMethods"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.SelectionSet, obj *ModelMethods) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, modelMethodsImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("ModelMethods") - case "resolverField": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._ModelMethods_resolverField(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "noContext": - out.Values[i] = ec._ModelMethods_noContext(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "withContext": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._ModelMethods_withContext(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) field_Panics_argUnmarshal_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []MarshalPanic + if tmp, ok := rawArgs["u"]; ok { + arg0, err = ec.unmarshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, tmp) + if err != nil { + return nil, err } } - wg.Wait() - if invalid { - return graphql.Null - } - return out + args["u"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "ModelMethods", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.ModelMethods().ResolverField(rctx, obj) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +func (ec *executionContext) field_Panics_fieldFuncMarshal_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []MarshalPanic + if tmp, ok := rawArgs["u"]; ok { + arg0, err = ec.unmarshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, tmp) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + args["u"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "ModelMethods", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.NoContext(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + args["name"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "ModelMethods", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.WithContext(ctx), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +func (ec *executionContext) field_Query_defaultScalar_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalNDefaultScalarImplementation2string(ctx, tmp) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + args["arg"] = arg0 + return args, nil } -var outerObjectImplementors = []string{"OuterObject"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionSet, obj *OuterObject) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, outerObjectImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("OuterObject") - case "inner": - out.Values[i] = ec._OuterObject_inner(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) field_Query_directiveArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["arg"]; ok { + getArg0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalNString2string(ctx, tmp) } + getArg1 := func(ctx context.Context) (res interface{}, err error) { + max := 255 + n := getArg0 + return ec.directives.Length(ctx, tmp, n, 1, &max) } - } - if invalid { - return graphql.Null + tmp, err = getArg1(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.(string); ok { + arg0 = data + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + } } - return out + args["arg"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphql.CollectedField, obj *OuterObject) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "OuterObject", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Inner, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +func (ec *executionContext) field_Query_directiveInputNullable_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *InputDirectives + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalOInputDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx, tmp) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(InnerObject) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._InnerObject(ctx, field.Selections, &res) + args["arg"] = arg0 + return args, nil } -var queryImplementors = []string{"Query"} +func (ec *executionContext) field_Query_directiveInputType_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 InnerInput + if tmp, ok := rawArgs["arg"]; ok { + getArg0 := func(ctx context.Context) (interface{}, error) { + return ec.unmarshalNInnerInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerInput(ctx, tmp) + } + getArg1 := func(ctx context.Context) (res interface{}, err error) { + n := getArg0 + return ec.directives.Custom(ctx, tmp, n) + } -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) + tmp, err = getArg1(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.(InnerInput); ok { + arg0 = data + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be github.com/99designs/gqlgen/codegen/testserver.InnerInput`, tmp) + } + } + args["arg"] = arg0 + return args, nil +} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) +func (ec *executionContext) field_Query_directiveInput_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 InputDirectives + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalNInputDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx, tmp) + if err != nil { + return nil, err + } + } + args["arg"] = arg0 + return args, nil +} - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) field_Query_directiveNullableArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["arg"]; ok { + getArg0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalOInt2ᚖint(ctx, tmp) } + getArg1 := func(ctx context.Context) (res interface{}, err error) { + min := 0 + n := getArg0 + return ec.directives.Range(ctx, tmp, n, &min, nil) + } - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "invalidIdentifier": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_invalidIdentifier(ctx, field) - wg.Done() - }(i, field) - case "collision": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_collision(ctx, field) - wg.Done() - }(i, field) - case "mapInput": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_mapInput(ctx, field) - wg.Done() - }(i, field) - case "recursive": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_recursive(ctx, field) - wg.Done() - }(i, field) - case "nestedInputs": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_nestedInputs(ctx, field) - wg.Done() - }(i, field) - case "nestedOutputs": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_nestedOutputs(ctx, field) - wg.Done() - }(i, field) - case "keywords": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_keywords(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "shapes": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_shapes(ctx, field) - wg.Done() - }(i, field) - case "errorBubble": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_errorBubble(ctx, field) - wg.Done() - }(i, field) - case "modelMethods": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_modelMethods(ctx, field) - wg.Done() - }(i, field) - case "valid": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_valid(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "user": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_user(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "nullableArg": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_nullableArg(ctx, field) - wg.Done() - }(i, field) - case "keywordArgs": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_keywordArgs(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) + tmp, err = getArg1(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.(*int); ok { + arg0 = data + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be *int`, tmp) } } - wg.Wait() - if invalid { - return graphql.Null + args["arg"] = arg0 + var arg1 *int + if tmp, ok := rawArgs["arg2"]; ok { + getArg0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalOInt2ᚖint(ctx, tmp) } + getArg1 := func(ctx context.Context) (res interface{}, err error) { + min := 0 + n := getArg0 + return ec.directives.Range(ctx, tmp, n, &min, nil) + } + + tmp, err = getArg1(ctx) + if err != nil { + return nil, err + } + if data, ok := tmp.(*int); ok { + arg1 = data + } else { + return nil, fmt.Errorf(`unexpected type %T from directive, should be *int`, tmp) + } } - return out + args["arg2"] = arg1 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _Query_invalidIdentifier(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().InvalidIdentifier(rctx) - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) field_Query_fallback_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 FallbackToStringEncoding + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalNFallbackToStringEncoding2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐFallbackToStringEncoding(ctx, tmp) + if err != nil { + return nil, err + } } - res := resTmp.(*invalid_packagename.InvalidIdentifier) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + args["arg"] = arg0 + return args, nil +} - if res == nil { - return graphql.Null +func (ec *executionContext) field_Query_inputSlice_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []string + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalNString2ᚕstring(ctx, tmp) + if err != nil { + return nil, err + } } - - return ec._InvalidIdentifier(ctx, field.Selections, res) + args["arg"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _Query_collision(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, +func (ec *executionContext) field_Query_mapInput_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 map[string]interface{} + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOChanges2map(ctx, tmp) + if err != nil { + return nil, err + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_mapStringInterface_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 map[string]interface{} + if tmp, ok := rawArgs["in"]; ok { + arg0, err = ec.unmarshalOMapStringInterfaceInput2map(ctx, tmp) + if err != nil { + return nil, err + } + } + args["in"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_nestedInputs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 [][]*OuterInput + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOOuterInput2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_nullableArg_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["arg"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["arg"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_recursive_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *RecursiveInputSlice + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalORecursiveInputSlice2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_ValidType_validArgs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["break"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["break"] = arg0 + var arg1 string + if tmp, ok := rawArgs["default"]; ok { + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["default"] = arg1 + var arg2 string + if tmp, ok := rawArgs["func"]; ok { + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["func"] = arg2 + var arg3 string + if tmp, ok := rawArgs["interface"]; ok { + arg3, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["interface"] = arg3 + var arg4 string + if tmp, ok := rawArgs["select"]; ok { + arg4, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["select"] = arg4 + var arg5 string + if tmp, ok := rawArgs["case"]; ok { + arg5, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["case"] = arg5 + var arg6 string + if tmp, ok := rawArgs["defer"]; ok { + arg6, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["defer"] = arg6 + var arg7 string + if tmp, ok := rawArgs["go"]; ok { + arg7, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["go"] = arg7 + var arg8 string + if tmp, ok := rawArgs["map"]; ok { + arg8, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["map"] = arg8 + var arg9 string + if tmp, ok := rawArgs["struct"]; ok { + arg9, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["struct"] = arg9 + var arg10 string + if tmp, ok := rawArgs["chan"]; ok { + arg10, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["chan"] = arg10 + var arg11 string + if tmp, ok := rawArgs["else"]; ok { + arg11, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["else"] = arg11 + var arg12 string + if tmp, ok := rawArgs["goto"]; ok { + arg12, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["goto"] = arg12 + var arg13 string + if tmp, ok := rawArgs["package"]; ok { + arg13, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["package"] = arg13 + var arg14 string + if tmp, ok := rawArgs["switch"]; ok { + arg14, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["switch"] = arg14 + var arg15 string + if tmp, ok := rawArgs["const"]; ok { + arg15, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["const"] = arg15 + var arg16 string + if tmp, ok := rawArgs["fallthrough"]; ok { + arg16, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["fallthrough"] = arg16 + var arg17 string + if tmp, ok := rawArgs["if"]; ok { + arg17, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["if"] = arg17 + var arg18 string + if tmp, ok := rawArgs["range"]; ok { + arg18, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["range"] = arg18 + var arg19 string + if tmp, ok := rawArgs["type"]; ok { + arg19, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["type"] = arg19 + var arg20 string + if tmp, ok := rawArgs["continue"]; ok { + arg20, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["continue"] = arg20 + var arg21 string + if tmp, ok := rawArgs["for"]; ok { + arg21, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["for"] = arg21 + var arg22 string + if tmp, ok := rawArgs["import"]; ok { + arg22, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["import"] = arg22 + var arg23 string + if tmp, ok := rawArgs["return"]; ok { + arg23, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["return"] = arg23 + var arg24 string + if tmp, ok := rawArgs["var"]; ok { + arg24, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["var"] = arg24 + var arg25 string + if tmp, ok := rawArgs["_"]; ok { + arg25, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["_"] = arg25 + return args, nil +} + +func (ec *executionContext) field_ValidType_validInputKeywords_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *ValidInput + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOValidInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _A_id(ctx context.Context, field graphql.CollectedField, obj *A) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "A", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _AIt_id(ctx context.Context, field graphql.CollectedField, obj *AIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "AIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _AbIt_id(ctx context.Context, field graphql.CollectedField, obj *AbIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "AbIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Autobind_int(ctx context.Context, field graphql.CollectedField, obj *Autobind) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Autobind", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Int, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _Autobind_int32(ctx context.Context, field graphql.CollectedField, obj *Autobind) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Autobind", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Int32, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int32) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int32(ctx, field.Selections, res) +} + +func (ec *executionContext) _Autobind_int64(ctx context.Context, field graphql.CollectedField, obj *Autobind) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Autobind", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Int64, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Autobind_idStr(ctx context.Context, field graphql.CollectedField, obj *Autobind) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Autobind", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IdStr, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Autobind_idInt(ctx context.Context, field graphql.CollectedField, obj *Autobind) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Autobind", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IdInt, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _B_id(ctx context.Context, field graphql.CollectedField, obj *B) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "B", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Circle_radius(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Circle", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Radius, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Circle_area(ctx context.Context, field graphql.CollectedField, obj *Circle) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Circle", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Area(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _EmbeddedDefaultScalar_value(ctx context.Context, field graphql.CollectedField, obj *EmbeddedDefaultScalar) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "EmbeddedDefaultScalar", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Value, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalODefaultScalarImplementation2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _EmbeddedPointer_ID(ctx context.Context, field graphql.CollectedField, obj *EmbeddedPointerModel) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "EmbeddedPointer", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _EmbeddedPointer_Title(ctx context.Context, field graphql.CollectedField, obj *EmbeddedPointerModel) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "EmbeddedPointer", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Title, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Error_id(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Error", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Error_errorOnNonRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Error", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ErrorOnNonRequiredField() + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Error_errorOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Error", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ErrorOnRequiredField() + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Error_nilOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Error", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NilOnRequiredField(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _ForcedResolver_field(ctx context.Context, field graphql.CollectedField, obj *ForcedResolver) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ForcedResolver", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.ForcedResolver().Field(rctx, obj) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Circle) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCircle2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐCircle(ctx, field.Selections, res) +} + +func (ec *executionContext) _InnerObject_id(ctx context.Context, field graphql.CollectedField, obj *InnerObject) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "InnerObject", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _InvalidIdentifier_id(ctx context.Context, field graphql.CollectedField, obj *invalid_packagename.InvalidIdentifier) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "InvalidIdentifier", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedField, obj *introspection1.It) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "It", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Map_id(ctx context.Context, field graphql.CollectedField, obj *Map) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Map", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _MapStringInterfaceType_a(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MapStringInterfaceType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + switch v := obj["a"].(type) { + case *string: + return v, nil + case string: + return &v, nil + case nil: + return (*string)(nil), nil + default: + return nil, fmt.Errorf("unexpected type %T for field %s", v, "a") + } + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MapStringInterfaceType_b(ctx context.Context, field graphql.CollectedField, obj map[string]interface{}) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MapStringInterfaceType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + switch v := obj["b"].(type) { + case *int: + return v, nil + case int: + return &v, nil + case nil: + return (*int)(nil), nil + default: + return nil, fmt.Errorf("unexpected type %T for field %s", v, "b") + } + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOInt2ᚖint(ctx, field.Selections, res) +} + +func (ec *executionContext) _ModelMethods_resolverField(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.ModelMethods().ResolverField(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _ModelMethods_noContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NoContext(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _ModelMethods_withContext(ctx context.Context, field graphql.CollectedField, obj *ModelMethods) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ModelMethods", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.WithContext(ctx), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphql.CollectedField, obj *OuterObject) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OuterObject", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Inner, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(InnerObject) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInnerObject2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerObject(ctx, field.Selections, res) +} + +func (ec *executionContext) _OverlappingFields_oneFoo(ctx context.Context, field graphql.CollectedField, obj *OverlappingFields) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OverlappingFields", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Foo, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _OverlappingFields_twoFoo(ctx context.Context, field graphql.CollectedField, obj *OverlappingFields) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OverlappingFields", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Foo, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _OverlappingFields_oldFoo(ctx context.Context, field graphql.CollectedField, obj *OverlappingFields) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OverlappingFields", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.OverlappingFields().OldFoo(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _OverlappingFields_newFoo(ctx context.Context, field graphql.CollectedField, obj *OverlappingFields) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OverlappingFields", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NewFoo, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _OverlappingFields_new_foo(ctx context.Context, field graphql.CollectedField, obj *OverlappingFields) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "OverlappingFields", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NewFoo, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _Panics_fieldScalarMarshal(ctx context.Context, field graphql.CollectedField, obj *Panics) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Panics", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Panics().FieldScalarMarshal(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]MarshalPanic) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, field.Selections, res) +} + +func (ec *executionContext) _Panics_fieldFuncMarshal(ctx context.Context, field graphql.CollectedField, obj *Panics) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Panics", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Panics_fieldFuncMarshal_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.FieldFuncMarshal(ctx, args["u"].([]MarshalPanic)), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]MarshalPanic) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, field.Selections, res) +} + +func (ec *executionContext) _Panics_argUnmarshal(ctx context.Context, field graphql.CollectedField, obj *Panics) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Panics", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Panics_argUnmarshal_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Panics().ArgUnmarshal(rctx, obj, args["u"].([]MarshalPanic)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_invalidIdentifier(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().InvalidIdentifier(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*invalid_packagename.InvalidIdentifier) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOInvalidIdentifier2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋinvalidᚑpackagenameᚐInvalidIdentifier(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_collision(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Collision(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection1.It) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOIt2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋintrospectionᚐIt(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_mapInput_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().MapInput(rctx, args["input"].(map[string]interface{})) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_recursive_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Recursive(rctx, args["input"].(*RecursiveInputSlice)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_nestedInputs_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().NestedInputs(rctx, args["input"].([][]*OuterInput)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().NestedOutputs(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([][]*OuterObject) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOOuterObject2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Shapes(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Shape) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOShape2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShape(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ErrorBubble(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Error) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ModelMethods(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ModelMethods) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOModelMethods2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐModelMethods(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Valid(rctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_user_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().User(rctx, args["id"].(int)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*User) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_nullableArg(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_nullableArg_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().NullableArg(rctx, args["arg"].(*int)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_directiveArg(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_directiveArg_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DirectiveArg(rctx, args["arg"].(string)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_directiveNullableArg(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_directiveNullableArg_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DirectiveNullableArg(rctx, args["arg"].(*int), args["arg2"].(*int)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_directiveInputNullable(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_directiveInputNullable_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DirectiveInputNullable(rctx, args["arg"].(*InputDirectives)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_directiveInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_directiveInput_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DirectiveInput(rctx, args["arg"].(InputDirectives)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_directiveInputType(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_directiveInputType_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DirectiveInputType(rctx, args["arg"].(InnerInput)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_inputSlice(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_inputSlice_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().InputSlice(rctx, args["arg"].([]string)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_shapeUnion(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ShapeUnion(rctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(ShapeUnion) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNShapeUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShapeUnion(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_autobind(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Autobind(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Autobind) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOAutobind2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐAutobind(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_deprecatedField(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DeprecatedField(rctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_overlapping(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Overlapping(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*OverlappingFields) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOOverlappingFields2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOverlappingFields(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_mapStringInterface(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_mapStringInterface_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().MapStringInterface(rctx, args["in"].(map[string]interface{})) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(map[string]interface{}) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOMapStringInterfaceType2map(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_panics(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Panics(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Panics) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOPanics2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPanics(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_defaultScalar(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_defaultScalar_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DefaultScalar(rctx, args["arg"].(string)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNDefaultScalarImplementation2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_slices(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Slices(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Slices) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOSlices2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐSlices(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_fallback(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_fallback_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Fallback(rctx, args["arg"].(FallbackToStringEncoding)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(FallbackToStringEncoding) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNFallbackToStringEncoding2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐFallbackToStringEncoding(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_optionalUnion(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().OptionalUnion(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(TestUnion) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOTestUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐTestUnion(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_validType(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ValidType(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ValidType) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOValidType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query___type_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(args["name"].(string)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) _Rectangle_length(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Rectangle", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Length, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Rectangle_width(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Rectangle", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Width, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Rectangle_area(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Rectangle", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Area(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Slices_test1(ctx context.Context, field graphql.CollectedField, obj *Slices) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Slices", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Test1, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚕᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Slices_test2(ctx context.Context, field graphql.CollectedField, obj *Slices) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Slices", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Test2, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚕstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Slices_test3(ctx context.Context, field graphql.CollectedField, obj *Slices) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Slices", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Test3, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2ᚕᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Slices_test4(ctx context.Context, field graphql.CollectedField, obj *Slices) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Slices", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Test4, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2ᚕstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Subscription_updated(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Field: field, + Args: nil, + }) + // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 + // and Tracer stack + rctx := ctx + results, err := ec.resolvers.Subscription().Updated(rctx) + if err != nil { + ec.Error(ctx, err) + return nil + } + return func() graphql.Marshaler { + res, ok := <-results + if !ok { + return nil + } + return graphql.WriterFunc(func(w io.Writer) { + w.Write([]byte{'{'}) + graphql.MarshalString(field.Alias).MarshalGQL(w) + w.Write([]byte{':'}) + ec.marshalNString2string(ctx, field.Selections, res).MarshalGQL(w) + w.Write([]byte{'}'}) + }) + } +} + +func (ec *executionContext) _Subscription_initPayload(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Field: field, + Args: nil, + }) + // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 + // and Tracer stack + rctx := ctx + results, err := ec.resolvers.Subscription().InitPayload(rctx) + if err != nil { + ec.Error(ctx, err) + return nil + } + return func() graphql.Marshaler { + res, ok := <-results + if !ok { + return nil + } + return graphql.WriterFunc(func(w io.Writer) { + w.Write([]byte{'{'}) + graphql.MarshalString(field.Alias).MarshalGQL(w) + w.Write([]byte{':'}) + ec.marshalNString2string(ctx, field.Selections, res).MarshalGQL(w) + w.Write([]byte{'}'}) + }) + } +} + +func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "User", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _User_friends(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "User", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.User().Friends(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]User) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNUser2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) _User_created(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "User", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Created, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(time.Time) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) _User_updated(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "User", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Updated, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*time.Time) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOTime2ᚖtimeᚐTime(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_differentCase(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DifferentCase, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_different_case(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DifferentCaseOld, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_validInputKeywords(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_ValidType_validInputKeywords_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ValidInputKeywords, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _ValidType_validArgs(ctx context.Context, field graphql.CollectedField, obj *ValidType) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "ValidType", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_ValidType_validArgs_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ValidArgs, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _XXIt_id(ctx context.Context, field graphql.CollectedField, obj *XXIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "XXIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _XxIt_id(ctx context.Context, field graphql.CollectedField, obj *XxIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "XxIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Locations, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DefaultValue, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.QueryType(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MutationType(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SubscriptionType(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Directives(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Directive) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Collision(rctx) + return obj.Name(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_fields_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Fields(args["includeDeprecated"].(bool)), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Field) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Interfaces(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PossibleTypes(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EnumValues(args["includeDeprecated"].(bool)), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.EnumValue) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) _asdfIt_id(ctx context.Context, field graphql.CollectedField, obj *AsdfIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "asdfIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _iIt_id(ctx context.Context, field graphql.CollectedField, obj *IIt) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "iIt", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*introspection1.It) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +func (ec *executionContext) unmarshalInputInnerDirectives(ctx context.Context, v interface{}) (InnerDirectives, error) { + var it InnerDirectives + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "message": + var err error + getField0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalNString2string(ctx, v) } + getField1 := func(ctx context.Context) (res interface{}, err error) { + n := getField0 + return ec.directives.Length(ctx, it, n, 1, nil) + } + + tmp, err := getField1(ctx) + if err != nil { + return it, err + } + if data, ok := tmp.(string); ok { + it.Message = data + } else { + return it, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputInnerInput(ctx context.Context, v interface{}) (InnerInput, error) { + var it InnerInput + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "id": + var err error + it.ID, err = ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputInputDirectives(ctx context.Context, v interface{}) (InputDirectives, error) { + var it InputDirectives + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "text": + var err error + getField0 := func(ctx context.Context) (interface{}, error) { return ec.unmarshalNString2string(ctx, v) } + getField1 := func(ctx context.Context) (res interface{}, err error) { + max := 7 + n := getField0 + return ec.directives.Length(ctx, it, n, 0, &max) + } + + tmp, err := getField1(ctx) + if err != nil { + return it, err + } + if data, ok := tmp.(string); ok { + it.Text = data + } else { + return it, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp) + } + case "inner": + var err error + it.Inner, err = ec.unmarshalNInnerDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx, v) + if err != nil { + return it, err + } + case "innerNullable": + var err error + it.InnerNullable, err = ec.unmarshalOInnerDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx, v) + if err != nil { + return it, err + } + case "thirdParty": + var err error + getField0 := func(ctx context.Context) (interface{}, error) { + return ec.unmarshalOThirdParty2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx, v) + } + getField1 := func(ctx context.Context) (res interface{}, err error) { + max := 7 + n := getField0 + return ec.directives.Length(ctx, it, n, 0, &max) + } + + tmp, err := getField1(ctx) + if err != nil { + return it, err + } + if data, ok := tmp.(*ThirdParty); ok { + it.ThirdParty = data + } else { + return it, fmt.Errorf(`unexpected type %T from directive, should be *github.com/99designs/gqlgen/codegen/testserver.ThirdParty`, tmp) + } + } + } - if res == nil { - return graphql.Null + return it, nil +} + +func (ec *executionContext) unmarshalInputOuterInput(ctx context.Context, v interface{}) (OuterInput, error) { + var it OuterInput + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "inner": + var err error + it.Inner, err = ec.unmarshalNInnerInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerInput(ctx, v) + if err != nil { + return it, err + } + } } - return ec._It(ctx, field.Selections, res) + return it, nil } -// nolint: vetshadow -func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_mapInput_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null +func (ec *executionContext) unmarshalInputRecursiveInputSlice(ctx context.Context, v interface{}) (RecursiveInputSlice, error) { + var it RecursiveInputSlice + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "self": + var err error + it.Self, err = ec.unmarshalORecursiveInputSlice2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, v) + if err != nil { + return it, err + } + } } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + + return it, nil +} + +func (ec *executionContext) unmarshalInputValidInput(ctx context.Context, v interface{}) (ValidInput, error) { + var it ValidInput + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "break": + var err error + it.Break, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "default": + var err error + it.Default, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "func": + var err error + it.Func, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "interface": + var err error + it.Interface, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "select": + var err error + it.Select, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "case": + var err error + it.Case, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "defer": + var err error + it.Defer, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "go": + var err error + it.Go, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "map": + var err error + it.Map, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "struct": + var err error + it.Struct, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "chan": + var err error + it.Chan, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "else": + var err error + it.Else, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "goto": + var err error + it.Goto, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "package": + var err error + it.Package, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "switch": + var err error + it.Switch, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "const": + var err error + it.Const, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "fallthrough": + var err error + it.Fallthrough, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "if": + var err error + it.If, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "range": + var err error + it.Range, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "type": + var err error + it.Type, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "continue": + var err error + it.Continue, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "for": + var err error + it.For, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "import": + var err error + it.Import, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "return": + var err error + it.Return, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "var": + var err error + it.Var, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "_": + var err error + it.Underscore, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().MapInput(rctx, args["input"].(*map[string]interface{})) - }) - if resTmp == nil { + + return it, nil +} + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +func (ec *executionContext) _Shape(ctx context.Context, sel ast.SelectionSet, obj *Shape) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: return graphql.Null + case *Circle: + return ec._Circle(ctx, sel, obj) + case *Rectangle: + return ec._Rectangle(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) } - res := resTmp.(*bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +} - if res == nil { +func (ec *executionContext) _ShapeUnion(ctx context.Context, sel ast.SelectionSet, obj *ShapeUnion) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: return graphql.Null + case *Circle: + return ec._Circle(ctx, sel, obj) + case *Rectangle: + return ec._Rectangle(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) } - return graphql.MarshalBoolean(*res) } -// nolint: vetshadow -func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_recursive_args(rawArgs) - if err != nil { - ec.Error(ctx, err) +func (ec *executionContext) _TestUnion(ctx context.Context, sel ast.SelectionSet, obj *TestUnion) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: return graphql.Null + case A: + return ec._A(ctx, sel, &obj) + case *A: + return ec._A(ctx, sel, obj) + case B: + return ec._B(ctx, sel, &obj) + case *B: + return ec._B(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Recursive(rctx, args["input"].(*RecursiveInputSlice)) - }) - if resTmp == nil { - return graphql.Null +} + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var aImplementors = []string{"A", "TestUnion"} + +func (ec *executionContext) _A(ctx context.Context, sel ast.SelectionSet, obj *A) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, aImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("A") + case "id": + out.Values[i] = ec._A_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - res := resTmp.(*bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalBoolean(*res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_nestedInputs_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, +var aItImplementors = []string{"AIt"} + +func (ec *executionContext) _AIt(ctx context.Context, sel ast.SelectionSet, obj *AIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, aItImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("AIt") + case "id": + out.Values[i] = ec._AIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().NestedInputs(rctx, args["input"].([][]*OuterInput)) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} + +var abItImplementors = []string{"AbIt"} - if res == nil { +func (ec *executionContext) _AbIt(ctx context.Context, sel ast.SelectionSet, obj *AbIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, abItImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("AbIt") + case "id": + out.Values[i] = ec._AbIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalBoolean(*res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, +var autobindImplementors = []string{"Autobind"} + +func (ec *executionContext) _Autobind(ctx context.Context, sel ast.SelectionSet, obj *Autobind) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, autobindImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Autobind") + case "int": + out.Values[i] = ec._Autobind_int(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "int32": + out.Values[i] = ec._Autobind_int32(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "int64": + out.Values[i] = ec._Autobind_int64(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "idStr": + out.Values[i] = ec._Autobind_idStr(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "idInt": + out.Values[i] = ec._Autobind_idInt(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().NestedOutputs(rctx) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.([][]*OuterObject) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +var bImplementors = []string{"B", "TestUnion"} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } +func (ec *executionContext) _B(ctx context.Context, sel ast.SelectionSet, obj *B) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, bImplementors) - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("B") + case "id": + out.Values[i] = ec._B_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - arr1[idx1] = func() graphql.Marshaler { + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} - arr2 := make(graphql.Array, len(res[idx1])) +var circleImplementors = []string{"Circle", "Shape", "ShapeUnion"} - isLen1 := len(res[idx1]) == 1 - if !isLen1 { - wg.Add(len(res[idx1])) - } +func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, obj *Circle) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, circleImplementors) - for idx2 := range res[idx1] { - idx2 := idx2 - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: res[idx1][idx2], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx2 int) { - if !isLen1 { - defer wg.Done() - } - arr2[idx2] = func() graphql.Marshaler { - - if res[idx1][idx2] == nil { - return graphql.Null - } - - return ec._OuterObject(ctx, field.Selections, res[idx1][idx2]) - }() - } - if isLen1 { - f(idx2) - } else { - go f(idx2) - } + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Circle") + case "radius": + out.Values[i] = ec._Circle_radius(ctx, field, obj) + case "area": + out.Values[i] = ec._Circle_area(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} - } +var embeddedDefaultScalarImplementors = []string{"EmbeddedDefaultScalar"} - return arr2 - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } +func (ec *executionContext) _EmbeddedDefaultScalar(ctx context.Context, sel ast.SelectionSet, obj *EmbeddedDefaultScalar) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, embeddedDefaultScalarImplementors) + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("EmbeddedDefaultScalar") + case "value": + out.Values[i] = ec._EmbeddedDefaultScalar_value(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - wg.Wait() - return arr1 + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_keywords(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_keywords_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null +var embeddedPointerImplementors = []string{"EmbeddedPointer"} + +func (ec *executionContext) _EmbeddedPointer(ctx context.Context, sel ast.SelectionSet, obj *EmbeddedPointerModel) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, embeddedPointerImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("EmbeddedPointer") + case "ID": + out.Values[i] = ec._EmbeddedPointer_ID(ctx, field, obj) + case "Title": + out.Values[i] = ec._EmbeddedPointer_Title(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + out.Dispatch() + if invalid { + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Keywords(rctx, args["input"].(*Keywords)) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + return out +} + +var errorImplementors = []string{"Error"} + +func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, obj *Error) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, errorImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Error") + case "id": + out.Values[i] = ec._Error_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "errorOnNonRequiredField": + out.Values[i] = ec._Error_errorOnNonRequiredField(ctx, field, obj) + case "errorOnRequiredField": + out.Values[i] = ec._Error_errorOnRequiredField(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "nilOnRequiredField": + out.Values[i] = ec._Error_nilOnRequiredField(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, +var forcedResolverImplementors = []string{"ForcedResolver"} + +func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.SelectionSet, obj *ForcedResolver) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, forcedResolverImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ForcedResolver") + case "field": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._ForcedResolver_field(ctx, field, obj) + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Shapes(rctx) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.([]*Shape) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +var innerObjectImplementors = []string{"InnerObject"} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } +func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionSet, obj *InnerObject) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, innerObjectImplementors) - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("InnerObject") + case "id": + out.Values[i] = ec._InnerObject_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - arr1[idx1] = func() graphql.Marshaler { - - if res[idx1] == nil { - return graphql.Null - } - - return ec._Shape(ctx, field.Selections, res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) + default: + panic("unknown field " + strconv.Quote(field.Name)) } - } - wg.Wait() - return arr1 + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, +var invalidIdentifierImplementors = []string{"InvalidIdentifier"} + +func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.SelectionSet, obj *invalid_packagename.InvalidIdentifier) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, invalidIdentifierImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("InvalidIdentifier") + case "id": + out.Values[i] = ec._InvalidIdentifier_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().ErrorBubble(rctx) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*Error) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - if res == nil { - return graphql.Null - } +var itImplementors = []string{"It"} - return ec._Error(ctx, field.Selections, res) -} +func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj *introspection1.It) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, itImplementors) -// nolint: vetshadow -func (ec *executionContext) _Query_modelMethods(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("It") + case "id": + out.Values[i] = ec._It_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().ModelMethods(rctx) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*ModelMethods) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - if res == nil { - return graphql.Null - } +var mapImplementors = []string{"Map"} - return ec._ModelMethods(ctx, field.Selections, res) -} +func (ec *executionContext) _Map(ctx context.Context, sel ast.SelectionSet, obj *Map) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, mapImplementors) -// nolint: vetshadow -func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Valid(rctx) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Map") + case "id": + out.Values[i] = ec._Map_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_user_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().User(rctx, args["id"].(int)) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +var mapStringInterfaceTypeImplementors = []string{"MapStringInterfaceType"} + +func (ec *executionContext) _MapStringInterfaceType(ctx context.Context, sel ast.SelectionSet, obj map[string]interface{}) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, mapStringInterfaceTypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("MapStringInterfaceType") + case "a": + out.Values[i] = ec._MapStringInterfaceType_a(ctx, field, obj) + case "b": + out.Values[i] = ec._MapStringInterfaceType_b(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(User) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._User(ctx, field.Selections, &res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_nullableArg(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_nullableArg_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, +var modelMethodsImplementors = []string{"ModelMethods"} + +func (ec *executionContext) _ModelMethods(ctx context.Context, sel ast.SelectionSet, obj *ModelMethods) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, modelMethodsImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ModelMethods") + case "resolverField": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._ModelMethods_resolverField(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "noContext": + out.Values[i] = ec._ModelMethods_noContext(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "withContext": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._ModelMethods_withContext(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().NullableArg(rctx, args["arg"].(*int)) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { + return out +} + +var outerObjectImplementors = []string{"OuterObject"} + +func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionSet, obj *OuterObject) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, outerObjectImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("OuterObject") + case "inner": + out.Values[i] = ec._OuterObject_inner(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalString(*res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_keywordArgs_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().KeywordArgs(rctx, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +var overlappingFieldsImplementors = []string{"OverlappingFields"} + +func (ec *executionContext) _OverlappingFields(ctx context.Context, sel ast.SelectionSet, obj *OverlappingFields) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, overlappingFieldsImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("OverlappingFields") + case "oneFoo": + out.Values[i] = ec._OverlappingFields_oneFoo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "twoFoo": + out.Values[i] = ec._OverlappingFields_twoFoo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "oldFoo": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._OverlappingFields_oldFoo(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "newFoo": + out.Values[i] = ec._OverlappingFields_newFoo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "new_foo": + out.Values[i] = ec._OverlappingFields_new_foo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return out } -// nolint: vetshadow -func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, +var panicsImplementors = []string{"Panics"} + +func (ec *executionContext) _Panics(ctx context.Context, sel ast.SelectionSet, obj *Panics) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, panicsImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Panics") + case "fieldScalarMarshal": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Panics_fieldScalarMarshal(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "fieldFuncMarshal": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Panics_fieldFuncMarshal(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "argUnmarshal": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Panics_argUnmarshal(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.introspectType(args["name"].(string)) - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - if res == nil { - return graphql.Null - } +var queryImplementors = []string{"Query"} - return ec.___Type(ctx, field.Selections, res) -} +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) -// nolint: vetshadow -func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Object: "Query", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.introspectSchema() }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*introspection.Schema) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - if res == nil { + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "invalidIdentifier": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_invalidIdentifier(ctx, field) + return res + }) + case "collision": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_collision(ctx, field) + return res + }) + case "mapInput": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_mapInput(ctx, field) + return res + }) + case "recursive": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_recursive(ctx, field) + return res + }) + case "nestedInputs": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_nestedInputs(ctx, field) + return res + }) + case "nestedOutputs": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_nestedOutputs(ctx, field) + return res + }) + case "shapes": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_shapes(ctx, field) + return res + }) + case "errorBubble": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_errorBubble(ctx, field) + return res + }) + case "modelMethods": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_modelMethods(ctx, field) + return res + }) + case "valid": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_valid(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "user": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_user(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "nullableArg": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_nullableArg(ctx, field) + return res + }) + case "directiveArg": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_directiveArg(ctx, field) + return res + }) + case "directiveNullableArg": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_directiveNullableArg(ctx, field) + return res + }) + case "directiveInputNullable": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_directiveInputNullable(ctx, field) + return res + }) + case "directiveInput": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_directiveInput(ctx, field) + return res + }) + case "directiveInputType": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_directiveInputType(ctx, field) + return res + }) + case "inputSlice": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_inputSlice(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "shapeUnion": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_shapeUnion(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "autobind": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_autobind(ctx, field) + return res + }) + case "deprecatedField": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_deprecatedField(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "overlapping": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_overlapping(ctx, field) + return res + }) + case "mapStringInterface": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_mapStringInterface(ctx, field) + return res + }) + case "panics": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_panics(ctx, field) + return res + }) + case "defaultScalar": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_defaultScalar(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "slices": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_slices(ctx, field) + return res + }) + case "fallback": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_fallback(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "optionalUnion": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_optionalUnion(ctx, field) + return res + }) + case "validType": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_validType(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } - - return ec.___Schema(ctx, field.Selections, res) + return out } -var rectangleImplementors = []string{"Rectangle", "Shape"} +var rectangleImplementors = []string{"Rectangle", "Shape", "ShapeUnion"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet, obj *Rectangle) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, rectangleImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Rectangle") @@ -2411,88 +6692,51 @@ func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) _Rectangle_length(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Rectangle", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Length, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(float64) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) -} +var slicesImplementors = []string{"Slices"} -// nolint: vetshadow -func (ec *executionContext) _Rectangle_width(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Rectangle", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Width, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(float64) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) -} +func (ec *executionContext) _Slices(ctx context.Context, sel ast.SelectionSet, obj *Slices) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, slicesImplementors) -// nolint: vetshadow -func (ec *executionContext) _Rectangle_area(ctx context.Context, field graphql.CollectedField, obj *Rectangle) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Rectangle", - Args: nil, - Field: field, + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Slices") + case "test1": + out.Values[i] = ec._Slices_test1(ctx, field, obj) + case "test2": + out.Values[i] = ec._Slices_test2(ctx, field, obj) + case "test3": + out.Values[i] = ec._Slices_test3(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "test4": + out.Values[i] = ec._Slices_test4(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Area(), nil - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(float64) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return out } var subscriptionImplementors = []string{"Subscription"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) _Subscription(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, subscriptionImplementors) ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ @@ -2513,64 +6757,14 @@ func (ec *executionContext) _Subscription(ctx context.Context, sel ast.Selection } } -func (ec *executionContext) _Subscription_updated(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Field: field, - }) - // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 - // and Tracer stack - rctx := ctx - results, err := ec.resolvers.Subscription().Updated(rctx) - if err != nil { - ec.Error(ctx, err) - return nil - } - return func() graphql.Marshaler { - res, ok := <-results - if !ok { - return nil - } - var out graphql.OrderedMap - out.Add(field.Alias, func() graphql.Marshaler { return graphql.MarshalString(res) }()) - return &out - } -} - -func (ec *executionContext) _Subscription_initPayload(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Field: field, - }) - // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 - // and Tracer stack - rctx := ctx - results, err := ec.resolvers.Subscription().InitPayload(rctx) - if err != nil { - ec.Error(ctx, err) - return nil - } - return func() graphql.Marshaler { - res, ok := <-results - if !ok { - return nil - } - var out graphql.OrderedMap - out.Add(field.Alias, func() graphql.Marshaler { return graphql.MarshalString(res) }()) - return &out - } -} - var userImplementors = []string{"User"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *User) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, userImplementors) - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("User") @@ -2580,140 +6774,65 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj invalid = true } case "friends": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._User_friends(ctx, field, obj) - if out.Values[i] == graphql.Null { + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._User_friends(ctx, field, obj) + if res == graphql.Null { invalid = true } - wg.Done() - }(i, field) + return res + }) + case "created": + out.Values[i] = ec._User_created(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "updated": + out.Values[i] = ec._User_updated(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } } - wg.Wait() + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(int) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) -} - -// nolint: vetshadow -func (ec *executionContext) _User_friends(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.User().Friends(rctx, obj) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]User) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._User(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __DirectiveImplementors = []string{"__Directive"} +var validTypeImplementors = []string{"ValidType"} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) +func (ec *executionContext) _ValidType(ctx context.Context, sel ast.SelectionSet, obj *ValidType) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, validTypeImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) + out.Values[i] = graphql.MarshalString("ValidType") + case "differentCase": + out.Values[i] = ec._ValidType_differentCase(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) + case "different_case": + out.Values[i] = ec._ValidType_different_case(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) + case "validInputKeywords": + out.Values[i] = ec._ValidType_validInputKeywords(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "validArgs": + out.Values[i] = ec._ValidType_validArgs(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } @@ -2721,171 +6840,114 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +var xXItImplementors = []string{"XXIt"} -// nolint: vetshadow -func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +func (ec *executionContext) _XXIt(ctx context.Context, sel ast.SelectionSet, obj *XXIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, xXItImplementors) -// nolint: vetshadow -func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Locations, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("XXIt") + case "id": + out.Values[i] = ec._XXIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.([]string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) + return out +} - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } +var xxItImplementors = []string{"XxIt"} - return arr1 -} +func (ec *executionContext) _XxIt(ctx context.Context, sel ast.SelectionSet, obj *XxIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, xxItImplementors) -// nolint: vetshadow -func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Args, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("XxIt") + case "id": + out.Values[i] = ec._XxIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +var __DirectiveImplementors = []string{"__Directive"} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } - } - wg.Wait() - return arr1 + out.Dispatch() + if invalid { + return graphql.Null + } + return out } var __EnumValueImplementors = []string{"__EnumValue"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") @@ -2907,130 +6969,21 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.IsDeprecated(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DeprecationReason(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - var __FieldImplementors = []string{"__Field"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") @@ -3051,236 +7004,32 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, if out.Values[i] == graphql.Null { invalid = true } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Args, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Type, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.IsDeprecated(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) } - return graphql.Null - } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DeprecationReason(), nil - }) - if resTmp == nil { - return graphql.Null } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalString(*res) + return out } var __InputValueImplementors = []string{"__InputValue"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") @@ -3302,1269 +7051,1428 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection panic("unknown field " + strconv.Quote(field.Name)) } } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var asdfItImplementors = []string{"asdfIt"} + +func (ec *executionContext) _asdfIt(ctx context.Context, sel ast.SelectionSet, obj *AsdfIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, asdfItImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("asdfIt") + case "id": + out.Values[i] = ec._asdfIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return out } -// nolint: vetshadow -func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, +var iItImplementors = []string{"iIt"} + +func (ec *executionContext) _iIt(ctx context.Context, sel ast.SelectionSet, obj *IIt) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, iItImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("iIt") + case "id": + out.Values[i] = ec._iIt_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return out } -// nolint: vetshadow -func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNDefaultScalarImplementation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNDefaultScalarImplementation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNFallbackToStringEncoding2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐFallbackToStringEncoding(ctx context.Context, v interface{}) (FallbackToStringEncoding, error) { + tmp, err := graphql.UnmarshalString(v) + return FallbackToStringEncoding(tmp), err +} + +func (ec *executionContext) marshalNFallbackToStringEncoding2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐFallbackToStringEncoding(ctx context.Context, sel ast.SelectionSet, v FallbackToStringEncoding) graphql.Marshaler { + return graphql.MarshalString(string(v)) +} + +func (ec *executionContext) unmarshalNID2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalIntID(v) +} + +func (ec *executionContext) marshalNID2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalIntID(v) +} + +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) +} + +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) +} + +func (ec *executionContext) unmarshalNInnerDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx context.Context, v interface{}) (InnerDirectives, error) { + return ec.unmarshalInputInnerDirectives(ctx, v) +} + +func (ec *executionContext) unmarshalNInnerInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerInput(ctx context.Context, v interface{}) (InnerInput, error) { + return ec.unmarshalInputInnerInput(ctx, v) +} + +func (ec *executionContext) marshalNInnerObject2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerObject(ctx context.Context, sel ast.SelectionSet, v InnerObject) graphql.Marshaler { + return ec._InnerObject(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNInputDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx context.Context, v interface{}) (InputDirectives, error) { + return ec.unmarshalInputInputDirectives(ctx, v) +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalNInt2int32(ctx context.Context, v interface{}) (int32, error) { + return graphql.UnmarshalInt32(v) +} + +func (ec *executionContext) marshalNInt2int32(ctx context.Context, sel ast.SelectionSet, v int32) graphql.Marshaler { + return graphql.MarshalInt32(v) +} + +func (ec *executionContext) unmarshalNInt2int64(ctx context.Context, v interface{}) (int64, error) { + return graphql.UnmarshalInt64(v) +} + +func (ec *executionContext) marshalNInt2int64(ctx context.Context, sel ast.SelectionSet, v int64) graphql.Marshaler { + return graphql.MarshalInt64(v) +} + +func (ec *executionContext) unmarshalNMarshalPanic2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx context.Context, v interface{}) (MarshalPanic, error) { + var res MarshalPanic + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNMarshalPanic2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx context.Context, sel ast.SelectionSet, v MarshalPanic) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx context.Context, v interface{}) ([]MarshalPanic, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Type, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + var err error + res := make([]MarshalPanic, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNMarshalPanic2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalNMarshalPanic2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx context.Context, sel ast.SelectionSet, v []MarshalPanic) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNMarshalPanic2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐMarshalPanic(ctx, sel, v[i]) + } + + return ret +} + +func (ec *executionContext) unmarshalNRecursiveInputSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx context.Context, v interface{}) (RecursiveInputSlice, error) { + return ec.unmarshalInputRecursiveInputSlice(ctx, v) +} + +func (ec *executionContext) marshalNShapeUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShapeUnion(ctx context.Context, sel ast.SelectionSet, v ShapeUnion) graphql.Marshaler { + return ec._ShapeUnion(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNString2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return res, nil +} - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) marshalNString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNString2string(ctx, sel, v[i]) } - return ec.___Type(ctx, field.Selections, res) + return ret } -// nolint: vetshadow -func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DefaultValue, nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) unmarshalNString2ᚕᚖstring(ctx context.Context, v interface{}) ([]*string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null + var err error + res := make([]*string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalOString2ᚖstring(ctx, vSlice[i]) + if err != nil { + return nil, err + } } - return graphql.MarshalString(*res) + return res, nil } -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) +func (ec *executionContext) marshalNString2ᚕᚖstring(ctx context.Context, sel ast.SelectionSet, v []*string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalOString2ᚖstring(ctx, sel, v[i]) + } - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias + return ret +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } +func (ec *executionContext) unmarshalNString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil } + res, err := ec.unmarshalNString2string(ctx, v) + return &res, err +} - if invalid { +func (ec *executionContext) marshalNString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return out + return ec.marshalNString2string(ctx, sel, *v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { +func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) +} + +func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + if !ec.HasError(graphql.GetResolverContext(ctx)) { ec.Errorf(ctx, "must not be null") } return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return graphql.MarshalTime(v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx context.Context, sel ast.SelectionSet, v User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} - isLen1 := len(res) == 1 +func (ec *executionContext) marshalNUser2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx context.Context, sel ast.SelectionSet, v []User) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.QueryType(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { +func (ec *executionContext) marshalNUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUser(ctx context.Context, sel ast.SelectionSet, v *User) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { ec.Errorf(ctx, "must not be null") } return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec._User(ctx, sel, v) +} - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } - return graphql.Null + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + } + wg.Wait() + return ret +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.MutationType(), nil - }) - if resTmp == nil { - return graphql.Null + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return res, nil +} - if res == nil { - return graphql.Null +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - return ec.___Type(ctx, field.Selections, res) + } + wg.Wait() + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.SubscriptionType(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} - if res == nil { - return graphql.Null - } +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Directives(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } - return graphql.Null + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + } - res := resTmp.([]introspection.Directive) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + wg.Wait() + return ret +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} - isLen1 := len(res) == 1 +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } +func (ec *executionContext) marshalOAutobind2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐAutobind(ctx context.Context, sel ast.SelectionSet, v Autobind) graphql.Marshaler { + return ec._Autobind(ctx, sel, &v) +} +func (ec *executionContext) marshalOAutobind2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐAutobind(ctx context.Context, sel ast.SelectionSet, v *Autobind) graphql.Marshaler { + if v == nil { + return graphql.Null } - wg.Wait() - return arr1 + return ec._Autobind(ctx, sel, v) } -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} - if invalid { +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { return graphql.Null } - return out + return ec.marshalOBoolean2bool(ctx, sel, *v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalOChanges2map(ctx context.Context, v interface{}) (map[string]interface{}, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Kind(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } + return v.(map[string]interface{}), nil +} + +func (ec *executionContext) marshalOCircle2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐCircle(ctx context.Context, sel ast.SelectionSet, v Circle) graphql.Marshaler { + return ec._Circle(ctx, sel, &v) +} + +func (ec *executionContext) marshalOCircle2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐCircle(ctx context.Context, sel ast.SelectionSet, v *Circle) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec._Circle(ctx, sel, v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalODefaultScalarImplementation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalODefaultScalarImplementation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalODefaultScalarImplementation2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name(), nil - }) - if resTmp == nil { + res, err := ec.unmarshalODefaultScalarImplementation2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalODefaultScalarImplementation2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalODefaultScalarImplementation2string(ctx, sel, *v) +} - if res == nil { +func (ec *executionContext) marshalOError2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx context.Context, sel ast.SelectionSet, v Error) graphql.Marshaler { + return ec._Error(ctx, sel, &v) +} + +func (ec *executionContext) marshalOError2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐError(ctx context.Context, sel ast.SelectionSet, v *Error) graphql.Marshaler { + if v == nil { return graphql.Null } - return graphql.MarshalString(*res) + return ec._Error(ctx, sel, v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description(), nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) unmarshalOFloat2float64(ctx context.Context, v interface{}) (float64, error) { + return graphql.UnmarshalFloat(v) +} + +func (ec *executionContext) marshalOFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { + return graphql.MarshalFloat(v) +} + +func (ec *executionContext) unmarshalOInnerDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx context.Context, v interface{}) (InnerDirectives, error) { + return ec.unmarshalInputInnerDirectives(ctx, v) +} + +func (ec *executionContext) unmarshalOInnerDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx context.Context, v interface{}) (*InnerDirectives, error) { + if v == nil { + return nil, nil } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + res, err := ec.unmarshalOInnerDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInnerDirectives(ctx, v) + return &res, err } -// nolint: vetshadow -func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null +func (ec *executionContext) unmarshalOInputDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx context.Context, v interface{}) (InputDirectives, error) { + return ec.unmarshalInputInputDirectives(ctx, v) +} + +func (ec *executionContext) unmarshalOInputDirectives2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx context.Context, v interface{}) (*InputDirectives, error) { + if v == nil { + return nil, nil } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, + res, err := ec.unmarshalOInputDirectives2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐInputDirectives(ctx, v) + return &res, err +} + +func (ec *executionContext) unmarshalOInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalOInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Fields(args["includeDeprecated"].(bool)), nil - }) - if resTmp == nil { + res, err := ec.unmarshalOInt2int(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Field) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOInt2int(ctx, sel, *v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalOInvalidIdentifier2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋinvalidᚑpackagenameᚐInvalidIdentifier(ctx context.Context, sel ast.SelectionSet, v invalid_packagename.InvalidIdentifier) graphql.Marshaler { + return ec._InvalidIdentifier(ctx, sel, &v) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) marshalOInvalidIdentifier2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋinvalidᚑpackagenameᚐInvalidIdentifier(ctx context.Context, sel ast.SelectionSet, v *invalid_packagename.InvalidIdentifier) graphql.Marshaler { + if v == nil { + return graphql.Null } + return ec._InvalidIdentifier(ctx, sel, v) +} - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } +func (ec *executionContext) marshalOIt2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋintrospectionᚐIt(ctx context.Context, sel ast.SelectionSet, v introspection1.It) graphql.Marshaler { + return ec._It(ctx, sel, &v) +} +func (ec *executionContext) marshalOIt2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋintrospectionᚐIt(ctx context.Context, sel ast.SelectionSet, v *introspection1.It) graphql.Marshaler { + if v == nil { + return graphql.Null } - wg.Wait() - return arr1 + return ec._It(ctx, sel, v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalOMapStringInterfaceInput2map(ctx context.Context, v interface{}) (map[string]interface{}, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Interfaces(), nil - }) - if resTmp == nil { + return v.(map[string]interface{}), nil +} + +func (ec *executionContext) marshalOMapStringInterfaceType2map(ctx context.Context, sel ast.SelectionSet, v map[string]interface{}) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec._MapStringInterfaceType(ctx, sel, v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalOModelMethods2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐModelMethods(ctx context.Context, sel ast.SelectionSet, v ModelMethods) graphql.Marshaler { + return ec._ModelMethods(ctx, sel, &v) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) marshalOModelMethods2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐModelMethods(ctx context.Context, sel ast.SelectionSet, v *ModelMethods) graphql.Marshaler { + if v == nil { + return graphql.Null } + return ec._ModelMethods(ctx, sel, v) +} - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { +func (ec *executionContext) unmarshalOOuterInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx context.Context, v interface{}) (OuterInput, error) { + return ec.unmarshalInputOuterInput(ctx, v) +} - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) +func (ec *executionContext) unmarshalOOuterInput2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx context.Context, v interface{}) ([][]*OuterInput, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 } else { - go f(idx1) + vSlice = []interface{}{v} + } + } + var err error + res := make([][]*OuterInput, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalOOuterInput2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, vSlice[i]) + if err != nil { + return nil, err } + } + return res, nil +} +func (ec *executionContext) unmarshalOOuterInput2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx context.Context, v interface{}) ([]*OuterInput, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - wg.Wait() - return arr1 + var err error + res := make([]*OuterInput, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalOOuterInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil } -// nolint: vetshadow -func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalOOuterInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx context.Context, v interface{}) (*OuterInput, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.PossibleTypes(), nil - }) - if resTmp == nil { + res, err := ec.unmarshalOOuterInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterInput(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOOuterObject2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx context.Context, sel ast.SelectionSet, v OuterObject) graphql.Marshaler { + return ec._OuterObject(ctx, sel, &v) +} + +func (ec *executionContext) marshalOOuterObject2ᚕᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx context.Context, sel ast.SelectionSet, v [][]*OuterObject) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) + ret := make(graphql.Array, len(v)) var wg sync.WaitGroup - - isLen1 := len(res) == 1 + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalOOuterObject2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.EnumValues(args["includeDeprecated"].(bool)), nil - }) - if resTmp == nil { +func (ec *executionContext) marshalOOuterObject2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx context.Context, sel ast.SelectionSet, v []*OuterObject) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.EnumValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) + ret := make(graphql.Array, len(v)) var wg sync.WaitGroup - - isLen1 := len(res) == 1 + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalOOuterObject2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) marshalOOuterObject2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOuterObject(ctx context.Context, sel ast.SelectionSet, v *OuterObject) graphql.Marshaler { + if v == nil { + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.InputFields(), nil - }) - if resTmp == nil { + return ec._OuterObject(ctx, sel, v) +} + +func (ec *executionContext) marshalOOverlappingFields2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOverlappingFields(ctx context.Context, sel ast.SelectionSet, v OverlappingFields) graphql.Marshaler { + return ec._OverlappingFields(ctx, sel, &v) +} + +func (ec *executionContext) marshalOOverlappingFields2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐOverlappingFields(ctx context.Context, sel ast.SelectionSet, v *OverlappingFields) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec._OverlappingFields(ctx, sel, v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalOPanics2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPanics(ctx context.Context, sel ast.SelectionSet, v Panics) graphql.Marshaler { + return ec._Panics(ctx, sel, &v) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) marshalOPanics2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPanics(ctx context.Context, sel ast.SelectionSet, v *Panics) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Panics(ctx, sel, v) +} + +func (ec *executionContext) unmarshalORecursiveInputSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx context.Context, v interface{}) (RecursiveInputSlice, error) { + return ec.unmarshalInputRecursiveInputSlice(ctx, v) +} + +func (ec *executionContext) unmarshalORecursiveInputSlice2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx context.Context, v interface{}) ([]RecursiveInputSlice, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]RecursiveInputSlice, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNRecursiveInputSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) unmarshalORecursiveInputSlice2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx context.Context, v interface{}) (*RecursiveInputSlice, error) { + if v == nil { + return nil, nil } + res, err := ec.unmarshalORecursiveInputSlice2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSlice(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOShape2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShape(ctx context.Context, sel ast.SelectionSet, v Shape) graphql.Marshaler { + return ec._Shape(ctx, sel, &v) +} - for idx1 := range res { - idx1 := idx1 +func (ec *executionContext) marshalOShape2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShape(ctx context.Context, sel ast.SelectionSet, v []Shape) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalOShape2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐShape(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.OfType(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) marshalOSlices2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐSlices(ctx context.Context, sel ast.SelectionSet, v Slices) graphql.Marshaler { + return ec._Slices(ctx, sel, &v) } -func (ec *executionContext) _Shape(ctx context.Context, sel ast.SelectionSet, obj *Shape) graphql.Marshaler { - switch obj := (*obj).(type) { - case nil: +func (ec *executionContext) marshalOSlices2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐSlices(ctx context.Context, sel ast.SelectionSet, v *Slices) graphql.Marshaler { + if v == nil { return graphql.Null - case *Circle: - return ec._Circle(ctx, sel, obj) - case *Rectangle: - return ec._Rectangle(ctx, sel, obj) - default: - panic(fmt.Errorf("unexpected type %T", obj)) } + return ec._Slices(ctx, sel, v) } -func (ec *executionContext) _ShapeUnion(ctx context.Context, sel ast.SelectionSet, obj *ShapeUnion) graphql.Marshaler { - switch obj := (*obj).(type) { - case nil: - return graphql.Null - case *Circle: - return ec._Circle(ctx, sel, obj) - case *Rectangle: - return ec._Rectangle(ctx, sel, obj) - default: - panic(fmt.Errorf("unexpected type %T", obj)) - } +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) } -func UnmarshalInnerInput(v interface{}) (InnerInput, error) { - var it InnerInput - var asMap = v.(map[string]interface{}) +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} - for k, v := range asMap { - switch k { - case "id": - var err error - it.ID, err = graphql.UnmarshalInt(v) - if err != nil { - return it, err - } +func (ec *executionContext) unmarshalOString2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} } } - - return it, nil + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil } -func UnmarshalKeywords(v interface{}) (Keywords, error) { - var it Keywords - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "break": - var err error - it.Break, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "default": - var err error - it.Default, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "func": - var err error - it.Func, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "interface": - var err error - it.Interface, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "select": - var err error - it.Select, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "case": - var err error - it.Case, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "defer": - var err error - it.Defer, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "go": - var err error - it.Go, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "map": - var err error - it.Map, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "struct": - var err error - it.Struct, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "chan": - var err error - it.Chan, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "else": - var err error - it.Else, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "goto": - var err error - it.Goto, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "package": - var err error - it.Package, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "switch": - var err error - it.Switch, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "const": - var err error - it.Const, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "fallthrough": - var err error - it.Fallthrough, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "if": - var err error - it.If, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "range": - var err error - it.Range, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "type": - var err error - it.Type, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "continue": - var err error - it.Continue, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "for": - var err error - it.For, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "import": - var err error - it.Import, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "return": - var err error - it.Return, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - case "var": - var err error - it.Var, err = graphql.UnmarshalString(v) - if err != nil { - return it, err - } - } +func (ec *executionContext) marshalOString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNString2string(ctx, sel, v[i]) } - return it, nil + return ret } -func UnmarshalOuterInput(v interface{}) (OuterInput, error) { - var it OuterInput - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "inner": - var err error - it.Inner, err = UnmarshalInnerInput(v) - if err != nil { - return it, err - } +func (ec *executionContext) unmarshalOString2ᚕᚖstring(ctx context.Context, v interface{}) ([]*string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]*string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalOString2ᚖstring(ctx, vSlice[i]) + if err != nil { + return nil, err } } - - return it, nil + return res, nil } -func UnmarshalRecursiveInputSlice(v interface{}) (RecursiveInputSlice, error) { - var it RecursiveInputSlice - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "self": - var err error - var rawIf1 []interface{} - if v != nil { - if tmp1, ok := v.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{v} - } - } - it.Self = make([]RecursiveInputSlice, len(rawIf1)) - for idx1 := range rawIf1 { - it.Self[idx1], err = UnmarshalRecursiveInputSlice(rawIf1[idx1]) - } - if err != nil { - return it, err - } - } +func (ec *executionContext) marshalOString2ᚕᚖstring(ctx context.Context, sel ast.SelectionSet, v []*string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalOString2ᚖstring(ctx, sel, v[i]) } - return it, nil + return ret } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil } - return res + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null } - return introspection.WrapSchema(parsedSchema), nil + return ec.marshalOString2string(ctx, sel, *v) } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") - } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +func (ec *executionContext) marshalOTestUnion2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐTestUnion(ctx context.Context, sel ast.SelectionSet, v TestUnion) graphql.Marshaler { + return ec._TestUnion(ctx, sel, &v) } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `type Query { - invalidIdentifier: InvalidIdentifier - collision: It - mapInput(input: Changes): Boolean - recursive(input: RecursiveInputSlice): Boolean - nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean - nestedOutputs: [[OuterObject]] - keywords(input: Keywords): Boolean! - shapes: [Shape] - errorBubble: Error - modelMethods: ModelMethods - valid: String! - user(id: Int!): User! - nullableArg(arg: Int = 123): String +func (ec *executionContext) unmarshalOThirdParty2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx context.Context, v interface{}) (ThirdParty, error) { + return UnmarshalThirdParty(v) } -type Subscription { - updated: String! - initPayload: String! +func (ec *executionContext) marshalOThirdParty2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx context.Context, sel ast.SelectionSet, v ThirdParty) graphql.Marshaler { + return MarshalThirdParty(v) } -type User { - id: Int! - friends: [User!]! +func (ec *executionContext) unmarshalOThirdParty2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx context.Context, v interface{}) (*ThirdParty, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOThirdParty2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx, v) + return &res, err } -type Error { - id: ID! - errorOnNonRequiredField: String - errorOnRequiredField: String! - nilOnRequiredField: String! +func (ec *executionContext) marshalOThirdParty2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx context.Context, sel ast.SelectionSet, v *ThirdParty) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOThirdParty2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐThirdParty(ctx, sel, *v) } -type ModelMethods { - resolverField: Boolean! - noContext: Boolean! - withContext: Boolean! +func (ec *executionContext) unmarshalOTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) } -type InvalidIdentifier { - id: Int! +func (ec *executionContext) marshalOTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + return graphql.Null + } + return graphql.MarshalTime(v) } -type It { - id: ID! +func (ec *executionContext) unmarshalOTime2ᚖtimeᚐTime(ctx context.Context, v interface{}) (*time.Time, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOTime2timeᚐTime(ctx, v) + return &res, err } -input Changes { - a: Int - b: Int +func (ec *executionContext) marshalOTime2ᚖtimeᚐTime(ctx context.Context, sel ast.SelectionSet, v *time.Time) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOTime2timeᚐTime(ctx, sel, *v) } -input RecursiveInputSlice { - self: [RecursiveInputSlice!] +func (ec *executionContext) unmarshalOValidInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx context.Context, v interface{}) (ValidInput, error) { + return ec.unmarshalInputValidInput(ctx, v) } -input InnerInput { - id:Int! +func (ec *executionContext) unmarshalOValidInput2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx context.Context, v interface{}) (*ValidInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOValidInput2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidInput(ctx, v) + return &res, err } -input OuterInput { - inner: InnerInput! +func (ec *executionContext) marshalOValidType2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx context.Context, sel ast.SelectionSet, v ValidType) graphql.Marshaler { + return ec._ValidType(ctx, sel, &v) } -type OuterObject { - inner: InnerObject! +func (ec *executionContext) marshalOValidType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐValidType(ctx context.Context, sel ast.SelectionSet, v *ValidType) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ValidType(ctx, sel, v) } -type InnerObject { - id: Int! +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -input Keywords { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -extend type Query { - keywordArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - ): Boolean! +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -interface Shape { - area: Float +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) } -type Circle implements Shape { - radius: Float - area: Float + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) } -type Rectangle implements Shape { - length: Float - width: Float - area: Float + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) } -union ShapeUnion = Circle | Rectangle -type ForcedResolver { - field: Circle +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -type EmbeddedPointer { - ID: String - Title: String +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) } -`}, -) + +// endregion ***************************** type.gotpl ***************************** diff --git a/codegen/testserver/generated_test.go b/codegen/testserver/generated_test.go index 704869a081..bcc00d21e5 100644 --- a/codegen/testserver/generated_test.go +++ b/codegen/testserver/generated_test.go @@ -1,26 +1,17 @@ //go:generate rm -f resolver.go -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go -stub stub.go package testserver import ( "context" - "fmt" "net/http" "net/http/httptest" "reflect" - "runtime" - "sort" - "sync" "testing" - "time" - - "github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/client" - "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/handler" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -36,731 +27,57 @@ func TestForcedResolverFieldIsPointer(t *testing.T) { require.Equal(t, "*testserver.Circle", field.Type.Out(0).String()) } -func TestGeneratedServer(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { - path, _ := ctx.Value("path").([]int) - return next(context.WithValue(ctx, "path", append(path, 1))) - }), - handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { - path, _ := ctx.Value("path").([]int) - return next(context.WithValue(ctx, "path", append(path, 2))) - }), - )) - c := client.New(srv.URL) - - t.Run("null bubbling", func(t *testing.T) { - t.Run("when function errors on non required field", func(t *testing.T) { - var resp struct { - Valid string - ErrorBubble *struct { - Id string - ErrorOnNonRequiredField *string - } - } - err := c.Post(`query { valid, errorBubble { id, errorOnNonRequiredField } }`, &resp) - - require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnNonRequiredField"]}]`) - require.Equal(t, "E1234", resp.ErrorBubble.Id) - require.Nil(t, resp.ErrorBubble.ErrorOnNonRequiredField) - require.Equal(t, "Ok", resp.Valid) - }) - - t.Run("when function errors", func(t *testing.T) { - var resp struct { - Valid string - ErrorBubble *struct { - NilOnRequiredField string - } - } - err := c.Post(`query { valid, errorBubble { id, errorOnRequiredField } }`, &resp) - - require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnRequiredField"]}]`) - require.Nil(t, resp.ErrorBubble) - require.Equal(t, "Ok", resp.Valid) - }) - - t.Run("when user returns null on required field", func(t *testing.T) { - var resp struct { - Valid string - ErrorBubble *struct { - NilOnRequiredField string - } - } - err := c.Post(`query { valid, errorBubble { id, nilOnRequiredField } }`, &resp) - - require.EqualError(t, err, `[{"message":"must not be null","path":["errorBubble","nilOnRequiredField"]}]`) - require.Nil(t, resp.ErrorBubble) - require.Equal(t, "Ok", resp.Valid) - }) - - }) - - t.Run("middleware", func(t *testing.T) { - var resp struct { - User struct { - ID int - Friends []struct { - ID int - } - } - } - - called := false - resolvers.userFriends = func(ctx context.Context, obj *User) ([]User, error) { - assert.Equal(t, []int{1, 2, 1, 2}, ctx.Value("path")) - called = true - return []User{}, nil - } - - err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) - - require.NoError(t, err) - require.True(t, called) - }) - - t.Run("subscriptions", func(t *testing.T) { - t.Run("wont leak goroutines", func(t *testing.T) { - initialGoroutineCount := runtime.NumGoroutine() - - sub := c.Websocket(`subscription { updated }`) - - resolvers.tick <- "message" - - var msg struct { - resp struct { - Updated string - } - } - - err := sub.Next(&msg.resp) - require.NoError(t, err) - require.Equal(t, "message", msg.resp.Updated) - sub.Close() - - // need a little bit of time for goroutines to settle - start := time.Now() - for time.Since(start).Seconds() < 2 && initialGoroutineCount != runtime.NumGoroutine() { - time.Sleep(5 * time.Millisecond) - } - - require.Equal(t, initialGoroutineCount, runtime.NumGoroutine()) - }) - - t.Run("will parse init payload", func(t *testing.T) { - sub := c.WebsocketWithPayload(`subscription { initPayload }`, map[string]interface{}{ - "Authorization": "Bearer of the curse", - "number": 32, - "strings": []string{"hello", "world"}, - }) - - var msg struct { - resp struct { - InitPayload string - } - } - - err := sub.Next(&msg.resp) - require.NoError(t, err) - require.Equal(t, "AUTH:Bearer of the curse", msg.resp.InitPayload) - err = sub.Next(&msg.resp) - require.NoError(t, err) - require.Equal(t, "Authorization = \"Bearer of the curse\"", msg.resp.InitPayload) - err = sub.Next(&msg.resp) - require.NoError(t, err) - require.Equal(t, "number = 32", msg.resp.InitPayload) - err = sub.Next(&msg.resp) - require.NoError(t, err) - require.Equal(t, "strings = []interface {}{\"hello\", \"world\"}", msg.resp.InitPayload) - sub.Close() - }) - }) - - t.Run("null args", func(t *testing.T) { - var resp struct { - NullableArg *string - } - err := c.Post(`query { nullableArg(arg: null) }`, &resp) - require.Nil(t, err) - require.Equal(t, "Ok", *resp.NullableArg) - }) -} - -func TestIntrospection(t *testing.T) { - t.Run("disabled", func(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - handler.IntrospectionEnabled(false), - ), - ) - - c := client.New(srv.URL) - - var resp interface{} - err := c.Post(introspection.Query, &resp) - require.EqualError(t, err, "[{\"message\":\"introspection disabled\",\"path\":[\"__schema\"]}]") - }) - - t.Run("enabled by default", func(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - ), - ) - - c := client.New(srv.URL) - - var resp interface{} - err := c.Post(introspection.Query, &resp) - require.NoError(t, err) - - t.Run("does not return empty deprecation strings", func(t *testing.T) { - q := `{ - __type(name:"InnerObject") { - fields { - name - deprecationReason - } - } - }` - - c := client.New(srv.URL) - var resp struct { - Type struct { - Fields []struct { - Name string - DeprecationReason *string - } - } `json:"__type"` - } - err := c.Post(q, &resp) - require.NoError(t, err) - - require.Equal(t, "id", resp.Type.Fields[0].Name) - require.Nil(t, resp.Type.Fields[0].DeprecationReason) - }) - }) - - t.Run("disabled by middleware", func(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - handler.RequestMiddleware(func(ctx context.Context, next func(ctx context.Context) []byte) []byte { - graphql.GetRequestContext(ctx).DisableIntrospection = true - - return next(ctx) - }), - ), - ) - - c := client.New(srv.URL) - - var resp interface{} - err := c.Post(introspection.Query, &resp) - require.EqualError(t, err, "[{\"message\":\"introspection disabled\",\"path\":[\"__schema\"]}]") +func TestEnums(t *testing.T) { + t.Run("list of enums", func(t *testing.T) { + require.Equal(t, StatusOk, AllStatus[0]) + require.Equal(t, StatusError, AllStatus[1]) }) - -} - -var _ graphql.Tracer = (*testTracer)(nil) - -type testTracer struct { - id int - append func(string) -} - -func (tt *testTracer) StartOperationParsing(ctx context.Context) context.Context { - line := fmt.Sprintf("op:p:start:%d", tt.id) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) EndOperationParsing(ctx context.Context) { - tt.append(fmt.Sprintf("op:p:end:%d", tt.id)) -} - -func (tt *testTracer) StartOperationValidation(ctx context.Context) context.Context { - line := fmt.Sprintf("op:v:start:%d", tt.id) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) EndOperationValidation(ctx context.Context) { - tt.append(fmt.Sprintf("op:v:end:%d", tt.id)) -} - -func (tt *testTracer) StartOperationExecution(ctx context.Context) context.Context { - line := fmt.Sprintf("op:e:start:%d", tt.id) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) StartFieldExecution(ctx context.Context, field graphql.CollectedField) context.Context { - line := fmt.Sprintf("field'a:e:start:%d:%s", tt.id, field.Name) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) StartFieldResolverExecution(ctx context.Context, rc *graphql.ResolverContext) context.Context { - line := fmt.Sprintf("field'b:e:start:%d:%v", tt.id, rc.Path()) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) StartFieldChildExecution(ctx context.Context) context.Context { - line := fmt.Sprintf("field'c:e:start:%d", tt.id) - - tracerLogs, _ := ctx.Value("tracer").([]string) - ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) - tt.append(line) - - return ctx -} - -func (tt *testTracer) EndFieldExecution(ctx context.Context) { - tt.append(fmt.Sprintf("field:e:end:%d", tt.id)) -} - -func (tt *testTracer) EndOperationExecution(ctx context.Context) { - tt.append(fmt.Sprintf("op:e:end:%d", tt.id)) -} - -var _ graphql.Tracer = (*configurableTracer)(nil) - -type configurableTracer struct { - StartOperationParsingCallback func(ctx context.Context) context.Context - EndOperationParsingCallback func(ctx context.Context) - StartOperationValidationCallback func(ctx context.Context) context.Context - EndOperationValidationCallback func(ctx context.Context) - StartOperationExecutionCallback func(ctx context.Context) context.Context - StartFieldExecutionCallback func(ctx context.Context, field graphql.CollectedField) context.Context - StartFieldResolverExecutionCallback func(ctx context.Context, rc *graphql.ResolverContext) context.Context - StartFieldChildExecutionCallback func(ctx context.Context) context.Context - EndFieldExecutionCallback func(ctx context.Context) - EndOperationExecutionCallback func(ctx context.Context) } -func (ct *configurableTracer) StartOperationParsing(ctx context.Context) context.Context { - if f := ct.StartOperationParsingCallback; f != nil { - ctx = f(ctx) +func TestUnionFragments(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.ShapeUnion = func(ctx context.Context) (ShapeUnion, error) { + return &Circle{Radius: 32}, nil } - return ctx -} - -func (ct *configurableTracer) EndOperationParsing(ctx context.Context) { - if f := ct.EndOperationParsingCallback; f != nil { - f(ctx) - } -} - -func (ct *configurableTracer) StartOperationValidation(ctx context.Context) context.Context { - if f := ct.StartOperationValidationCallback; f != nil { - ctx = f(ctx) - } - return ctx -} -func (ct *configurableTracer) EndOperationValidation(ctx context.Context) { - if f := ct.EndOperationValidationCallback; f != nil { - f(ctx) - } -} - -func (ct *configurableTracer) StartOperationExecution(ctx context.Context) context.Context { - if f := ct.StartOperationExecutionCallback; f != nil { - ctx = f(ctx) - } - return ctx -} - -func (ct *configurableTracer) StartFieldExecution(ctx context.Context, field graphql.CollectedField) context.Context { - if f := ct.StartFieldExecutionCallback; f != nil { - ctx = f(ctx, field) - } - return ctx -} - -func (ct *configurableTracer) StartFieldResolverExecution(ctx context.Context, rc *graphql.ResolverContext) context.Context { - if f := ct.StartFieldResolverExecutionCallback; f != nil { - ctx = f(ctx, rc) - } - return ctx -} - -func (ct *configurableTracer) StartFieldChildExecution(ctx context.Context) context.Context { - if f := ct.StartFieldChildExecutionCallback; f != nil { - ctx = f(ctx) - } - return ctx -} - -func (ct *configurableTracer) EndFieldExecution(ctx context.Context) { - if f := ct.EndFieldExecutionCallback; f != nil { - f(ctx) - } -} - -func (ct *configurableTracer) EndOperationExecution(ctx context.Context) { - if f := ct.EndOperationExecutionCallback; f != nil { - f(ctx) - } -} - -func TestTracer(t *testing.T) { - t.Run("called in the correct order", func(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - var tracerLog []string - var mu sync.Mutex - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { - path, _ := ctx.Value("path").([]int) - return next(context.WithValue(ctx, "path", append(path, 1))) - }), - handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { - path, _ := ctx.Value("path").([]int) - return next(context.WithValue(ctx, "path", append(path, 2))) - }), - handler.Tracer(&testTracer{ - id: 1, - append: func(s string) { - mu.Lock() - defer mu.Unlock() - tracerLog = append(tracerLog, s) - }, - }), - handler.Tracer(&testTracer{ - id: 2, - append: func(s string) { - mu.Lock() - defer mu.Unlock() - tracerLog = append(tracerLog, s) - }, - }), - )) - defer srv.Close() - c := client.New(srv.URL) + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + t.Run("inline fragment on union", func(t *testing.T) { var resp struct { - User struct { - ID int - Friends []struct { - ID int - } + ShapeUnion struct { + Radius float64 } } - - called := false - resolvers.userFriends = func(ctx context.Context, obj *User) ([]User, error) { - assert.Equal(t, []string{ - "op:p:start:1", "op:p:start:2", - "op:v:start:1", "op:v:start:2", - "op:e:start:1", "op:e:start:2", - "field'a:e:start:1:user", "field'a:e:start:2:user", - "field'b:e:start:1:[user]", "field'b:e:start:2:[user]", - "field'c:e:start:1", "field'c:e:start:2", - "field'a:e:start:1:friends", "field'a:e:start:2:friends", - "field'b:e:start:1:[user friends]", "field'b:e:start:2:[user friends]", - }, ctx.Value("tracer")) - called = true - return []User{}, nil - } - - err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) - - require.NoError(t, err) - require.True(t, called) - mu.Lock() - defer mu.Unlock() - assert.Equal(t, []string{ - "op:p:start:1", "op:p:start:2", - "op:p:end:2", "op:p:end:1", - - "op:v:start:1", "op:v:start:2", - "op:v:end:2", "op:v:end:1", - - "op:e:start:1", "op:e:start:2", - - "field'a:e:start:1:user", "field'a:e:start:2:user", - "field'b:e:start:1:[user]", "field'b:e:start:2:[user]", - "field'c:e:start:1", "field'c:e:start:2", - "field'a:e:start:1:id", "field'a:e:start:2:id", - "field'b:e:start:1:[user id]", "field'b:e:start:2:[user id]", - "field'c:e:start:1", "field'c:e:start:2", - "field:e:end:2", "field:e:end:1", - "field'a:e:start:1:friends", "field'a:e:start:2:friends", - "field'b:e:start:1:[user friends]", "field'b:e:start:2:[user friends]", - "field'c:e:start:1", "field'c:e:start:2", - "field:e:end:2", "field:e:end:1", - "field:e:end:2", "field:e:end:1", - - "op:e:end:2", "op:e:end:1", - }, tracerLog) - }) - - t.Run("take ctx over from prev step", func(t *testing.T) { - resolvers := &testResolver{tick: make(chan string, 1)} - - configurableTracer := &configurableTracer{ - StartOperationParsingCallback: func(ctx context.Context) context.Context { - return context.WithValue(ctx, "StartOperationParsing", true) - }, - EndOperationParsingCallback: func(ctx context.Context) { - assert.NotNil(t, ctx.Value("StartOperationParsing")) - }, - - StartOperationValidationCallback: func(ctx context.Context) context.Context { - return context.WithValue(ctx, "StartOperationValidation", true) - }, - EndOperationValidationCallback: func(ctx context.Context) { - assert.NotNil(t, ctx.Value("StartOperationParsing")) - assert.NotNil(t, ctx.Value("StartOperationValidation")) - }, - - StartOperationExecutionCallback: func(ctx context.Context) context.Context { - return context.WithValue(ctx, "StartOperationExecution", true) - }, - StartFieldExecutionCallback: func(ctx context.Context, field graphql.CollectedField) context.Context { - return context.WithValue(ctx, "StartFieldExecution", true) - }, - StartFieldResolverExecutionCallback: func(ctx context.Context, rc *graphql.ResolverContext) context.Context { - return context.WithValue(ctx, "StartFieldResolverExecution", true) - }, - StartFieldChildExecutionCallback: func(ctx context.Context) context.Context { - return context.WithValue(ctx, "StartFieldChildExecution", true) - }, - EndFieldExecutionCallback: func(ctx context.Context) { - assert.NotNil(t, ctx.Value("StartOperationParsing")) - assert.NotNil(t, ctx.Value("StartOperationValidation")) - assert.NotNil(t, ctx.Value("StartOperationExecution")) - assert.NotNil(t, ctx.Value("StartFieldExecution")) - assert.NotNil(t, ctx.Value("StartFieldResolverExecution")) - assert.NotNil(t, ctx.Value("StartFieldChildExecution")) - }, - - EndOperationExecutionCallback: func(ctx context.Context) { - assert.NotNil(t, ctx.Value("StartOperationParsing")) - assert.NotNil(t, ctx.Value("StartOperationValidation")) - assert.NotNil(t, ctx.Value("StartOperationExecution")) - }, - } - - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: resolvers}), - handler.Tracer(configurableTracer), - )) - defer srv.Close() - c := client.New(srv.URL) - - var resp struct { - User struct { - ID int - Friends []struct { - ID int + c.MustPost(`query { + shapeUnion { + ... on Circle { + radius } } } - - called := false - resolvers.userFriends = func(ctx context.Context, obj *User) ([]User, error) { - called = true - return []User{}, nil - } - - err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) - - require.NoError(t, err) - require.True(t, called) + `, &resp) + require.NotEmpty(t, resp.ShapeUnion.Radius) }) - t.Run("model methods", func(t *testing.T) { - srv := httptest.NewServer( - handler.GraphQL( - NewExecutableSchema(Config{Resolvers: &testResolver{}}), - )) - defer srv.Close() - c := client.New(srv.URL) - t.Run("without context", func(t *testing.T) { - var resp struct { - ModelMethods struct { - NoContext bool - } - } - err := c.Post(`query { modelMethods{ noContext } }`, &resp) - require.NoError(t, err) - require.True(t, resp.ModelMethods.NoContext) - }) - t.Run("with context", func(t *testing.T) { - var resp struct { - ModelMethods struct { - WithContext bool - } + t.Run("named fragment", func(t *testing.T) { + var resp struct { + ShapeUnion struct { + Radius float64 } - err := c.Post(`query { modelMethods{ withContext } }`, &resp) - require.NoError(t, err) - require.True(t, resp.ModelMethods.WithContext) - }) - }) -} - -func TestResponseExtension(t *testing.T) { - srv := httptest.NewServer(handler.GraphQL( - NewExecutableSchema(Config{ - Resolvers: &testResolver{}, - }), - handler.RequestMiddleware(func(ctx context.Context, next func(ctx context.Context) []byte) []byte { - rctx := graphql.GetRequestContext(ctx) - if err := rctx.RegisterExtension("example", "value"); err != nil { - panic(err) + } + c.MustPost(`query { + shapeUnion { + ...C } - return next(ctx) - }), - )) - c := client.New(srv.URL) - - raw, _ := c.RawPost(`query { valid }`) - require.Equal(t, raw.Extensions["example"], "value") -} - -type testResolver struct { - tick chan string - userFriends func(ctx context.Context, obj *User) ([]User, error) -} - -func (r *testResolver) ForcedResolver() ForcedResolverResolver { - return &forcedResolverResolver{nil} -} - -func (r *testResolver) User() UserResolver { - return &testUserResolver{r} -} - -func (r *testResolver) Query() QueryResolver { - return &testQueryResolver{} -} -func (r *testResolver) ModelMethods() ModelMethodsResolver { - return &testModelMethodsResolver{} -} - -type testModelMethodsResolver struct{} - -func (r *testModelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { - return true, nil -} - -type testQueryResolver struct{ queryResolver } - -func (r *testQueryResolver) ErrorBubble(ctx context.Context) (*Error, error) { - return &Error{ID: "E1234"}, nil -} - -func (r *testQueryResolver) Valid(ctx context.Context) (string, error) { - return "Ok", nil -} - -func (r *testQueryResolver) User(ctx context.Context, id int) (User, error) { - return User{ID: 1}, nil -} - -func (r *testQueryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) { - s := "Ok" - return &s, nil -} - -func (r *testQueryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) { - return &ModelMethods{}, nil -} - -func (r *testResolver) Subscription() SubscriptionResolver { - return &testSubscriptionResolver{r} -} - -type testUserResolver struct{ *testResolver } - -func (r *testResolver) Friends(ctx context.Context, obj *User) ([]User, error) { - return r.userFriends(ctx, obj) -} - -type testSubscriptionResolver struct{ *testResolver } - -func (r *testSubscriptionResolver) Updated(ctx context.Context) (<-chan string, error) { - res := make(chan string, 1) + } - go func() { - for { - select { - case t := <-r.tick: - res <- t - case <-ctx.Done(): - close(res) - return + fragment C on ShapeUnion { + ... on Circle { + radius } } - }() - return res, nil -} - -func (r *testSubscriptionResolver) InitPayload(ctx context.Context) (<-chan string, error) { - payload := handler.GetInitPayload(ctx) - channel := make(chan string, len(payload)+1) - - go func() { - <-ctx.Done() - close(channel) - }() - - // Test the helper function separately - auth := payload.Authorization() - if auth != "" { - channel <- "AUTH:" + auth - } else { - channel <- "AUTH:NONE" - } - - // Send them over the channel in alphabetic order - keys := make([]string, 0, len(payload)) - for key := range payload { - keys = append(keys, key) - } - sort.Strings(keys) - for _, key := range keys { - channel <- fmt.Sprintf("%s = %#+v", key, payload[key]) - } - - return channel, nil + `, &resp) + require.NotEmpty(t, resp.ShapeUnion.Radius) + }) } diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index 7a6e8e5674..b3e4749654 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -1,4 +1,5 @@ -schema: schema.graphql +schema: + - "*.graphql" exec: filename: generated.go @@ -38,3 +39,32 @@ models: model: "github.com/99designs/gqlgen/codegen/testserver.Error" EmbeddedPointer: model: "github.com/99designs/gqlgen/codegen/testserver.EmbeddedPointerModel" + ThirdParty: + model: "github.com/99designs/gqlgen/codegen/testserver.ThirdParty" + Keywords: + fields: + _: { fieldName: Underscore } + ValidInput: + fields: + _: { fieldName: Underscore } + ValidType: + fields: + different_case: { fieldName: DifferentCaseOld } + Panics: + model: "github.com/99designs/gqlgen/codegen/testserver.Panics" + MarshalPanic: + model: "github.com/99designs/gqlgen/codegen/testserver.MarshalPanic" + Autobind: + model: "github.com/99designs/gqlgen/codegen/testserver.Autobind" + MapStringInterfaceInput: + model: "map[string]interface{}" + MapStringInterfaceType: + model: "map[string]interface{}" + OverlappingFields: + model: "github.com/99designs/gqlgen/codegen/testserver.OverlappingFields" + fields: + oneFoo: { fieldName: foo } + twoFoo: { fieldName: foo } + oldFoo: { fieldName: foo, resolver: true } + FallbackToStringEncoding: + model: "github.com/99designs/gqlgen/codegen/testserver.FallbackToStringEncoding" diff --git a/codegen/testserver/input_test.go b/codegen/testserver/input_test.go new file mode 100644 index 0000000000..7e8f1f3b77 --- /dev/null +++ b/codegen/testserver/input_test.go @@ -0,0 +1,34 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestInput(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + + c := client.New(srv.URL) + + t.Run("when function errors on directives", func(t *testing.T) { + resolvers.QueryResolver.InputSlice = func(ctx context.Context, arg []string) (b bool, e error) { + return true, nil + } + + var resp struct { + DirectiveArg *string + } + + err := c.Post(`query { inputSlice(arg: ["ok", 1, 2, "ok"]) }`, &resp) + + require.EqualError(t, err, `http 422: {"errors":[{"message":"Expected type String!, found 1.","locations":[{"line":1,"column":32}]},{"message":"Expected type String!, found 2.","locations":[{"line":1,"column":35}]}],"data":null}`) + require.Nil(t, resp.DirectiveArg) + }) +} diff --git a/codegen/testserver/interfaces_test.go b/codegen/testserver/interfaces_test.go new file mode 100644 index 0000000000..d10f48b071 --- /dev/null +++ b/codegen/testserver/interfaces_test.go @@ -0,0 +1,16 @@ +package testserver + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestInterfaces(t *testing.T) { + t.Run("slices of interfaces are not pointers", func(t *testing.T) { + field, ok := reflect.TypeOf((*QueryResolver)(nil)).Elem().MethodByName("Shapes") + require.True(t, ok) + require.Equal(t, "[]testserver.Shape", field.Type.Out(0).String()) + }) +} diff --git a/codegen/testserver/introspection_test.go b/codegen/testserver/introspection_test.go new file mode 100644 index 0000000000..546390749a --- /dev/null +++ b/codegen/testserver/introspection_test.go @@ -0,0 +1,95 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestIntrospection(t *testing.T) { + t.Run("disabled", func(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.IntrospectionEnabled(false), + ), + ) + + c := client.New(srv.URL) + + var resp interface{} + err := c.Post(introspection.Query, &resp) + require.EqualError(t, err, "[{\"message\":\"introspection disabled\",\"path\":[\"__schema\"]}]") + }) + + t.Run("enabled by default", func(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + ), + ) + + c := client.New(srv.URL) + + var resp interface{} + err := c.Post(introspection.Query, &resp) + require.NoError(t, err) + + t.Run("does not return empty deprecation strings", func(t *testing.T) { + q := `{ + __type(name:"InnerObject") { + fields { + name + deprecationReason + } + } + }` + + c := client.New(srv.URL) + var resp struct { + Type struct { + Fields []struct { + Name string + DeprecationReason *string + } + } `json:"__type"` + } + err := c.Post(q, &resp) + require.NoError(t, err) + + require.Equal(t, "id", resp.Type.Fields[0].Name) + require.Nil(t, resp.Type.Fields[0].DeprecationReason) + }) + }) + + t.Run("disabled by middleware", func(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.RequestMiddleware(func(ctx context.Context, next func(ctx context.Context) []byte) []byte { + graphql.GetRequestContext(ctx).DisableIntrospection = true + + return next(ctx) + }), + ), + ) + + c := client.New(srv.URL) + + var resp interface{} + err := c.Post(introspection.Query, &resp) + require.EqualError(t, err, "[{\"message\":\"introspection disabled\",\"path\":[\"__schema\"]}]") + }) +} diff --git a/codegen/testserver/maps.graphql b/codegen/testserver/maps.graphql new file mode 100644 index 0000000000..82dc180acd --- /dev/null +++ b/codegen/testserver/maps.graphql @@ -0,0 +1,13 @@ +extend type Query { + mapStringInterface(in: MapStringInterfaceInput): MapStringInterfaceType +} + +type MapStringInterfaceType { + a: String + b: Int +} + +input MapStringInterfaceInput { + a: String + b: Int +} diff --git a/codegen/testserver/maps_test.go b/codegen/testserver/maps_test.go new file mode 100644 index 0000000000..e2490909a7 --- /dev/null +++ b/codegen/testserver/maps_test.go @@ -0,0 +1,52 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestMaps(t *testing.T) { + resolver := &Stub{} + resolver.QueryResolver.MapStringInterface = func(ctx context.Context, in map[string]interface{}) (i map[string]interface{}, e error) { + return in, nil + } + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolver}), + )) + defer srv.Close() + c := client.New(srv.URL) + t.Run("unset", func(t *testing.T) { + var resp struct { + MapStringInterface map[string]interface{} + } + err := c.Post(`query { mapStringInterface { a, b } }`, &resp) + require.NoError(t, err) + require.Nil(t, resp.MapStringInterface) + }) + + t.Run("nil", func(t *testing.T) { + var resp struct { + MapStringInterface map[string]interface{} + } + err := c.Post(`query { mapStringInterface(in: null) { a, b } }`, &resp) + require.NoError(t, err) + require.Nil(t, resp.MapStringInterface) + }) + + t.Run("values", func(t *testing.T) { + var resp struct { + MapStringInterface map[string]interface{} + } + err := c.Post(`query { mapStringInterface(in: { a: "a", b: null }) { a, b } }`, &resp) + require.NoError(t, err) + require.Equal(t, "a", resp.MapStringInterface["a"]) + require.Nil(t, resp.MapStringInterface["b"]) + }) +} diff --git a/codegen/testserver/middleware_test.go b/codegen/testserver/middleware_test.go new file mode 100644 index 0000000000..2a48ccf581 --- /dev/null +++ b/codegen/testserver/middleware_test.go @@ -0,0 +1,76 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/handler" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestMiddleware(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.ErrorBubble = func(ctx context.Context) (i *Error, e error) { + return &Error{ID: "E1234"}, nil + } + + resolvers.QueryResolver.User = func(ctx context.Context, id int) (user *User, e error) { + return &User{ID: 1}, nil + } + + resolvers.UserResolver.Friends = func(ctx context.Context, obj *User) (users []User, e error) { + return []User{{ID: 1}}, nil + } + + areMethods := []bool{} + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 1))) + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 2))) + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + areMethods = append(areMethods, graphql.GetResolverContext(ctx).IsMethod) + return next(ctx) + }), + )) + + c := client.New(srv.URL) + + var resp struct { + User struct { + ID int + Friends []struct { + ID int + } + } + } + + called := false + resolvers.UserResolver.Friends = func(ctx context.Context, obj *User) ([]User, error) { + assert.Equal(t, []int{1, 2, 1, 2}, ctx.Value("path")) + called = true + return []User{}, nil + } + + err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) + + // First resovles user which is a method + // Next resolves id which is not a method + // Finally resolves friends which is a method + assert.Equal(t, []bool{true, false, true}, areMethods) + + require.NoError(t, err) + require.True(t, called) + +} diff --git a/codegen/testserver/modelmethod_test.go b/codegen/testserver/modelmethod_test.go new file mode 100644 index 0000000000..d484aa745a --- /dev/null +++ b/codegen/testserver/modelmethod_test.go @@ -0,0 +1,48 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestModelMethods(t *testing.T) { + resolver := &Stub{} + resolver.QueryResolver.ModelMethods = func(ctx context.Context) (methods *ModelMethods, e error) { + return &ModelMethods{}, nil + } + resolver.ModelMethodsResolver.ResolverField = func(ctx context.Context, obj *ModelMethods) (b bool, e error) { + return true, nil + } + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolver}), + )) + defer srv.Close() + c := client.New(srv.URL) + t.Run("without context", func(t *testing.T) { + var resp struct { + ModelMethods struct { + NoContext bool + } + } + err := c.Post(`query { modelMethods{ noContext } }`, &resp) + require.NoError(t, err) + require.True(t, resp.ModelMethods.NoContext) + }) + t.Run("with context", func(t *testing.T) { + var resp struct { + ModelMethods struct { + WithContext bool + } + } + err := c.Post(`query { modelMethods{ withContext } }`, &resp) + require.NoError(t, err) + require.True(t, resp.ModelMethods.WithContext) + }) +} diff --git a/codegen/testserver/models-gen.go b/codegen/testserver/models-gen.go index ea2208bbd4..c1331c1dba 100644 --- a/codegen/testserver/models-gen.go +++ b/codegen/testserver/models-gen.go @@ -2,6 +2,45 @@ package testserver +import ( + "fmt" + "io" + "strconv" + "time" +) + +type TestUnion interface { + IsTestUnion() +} + +type A struct { + ID string `json:"id"` +} + +func (A) IsTestUnion() {} + +type AIt struct { + ID string `json:"id"` +} + +type AbIt struct { + ID string `json:"id"` +} + +type B struct { + ID string `json:"id"` +} + +func (B) IsTestUnion() {} + +type EmbeddedDefaultScalar struct { + Value *string `json:"value"` +} + +type InnerDirectives struct { + Message string `json:"message"` +} + type InnerInput struct { ID int `json:"id"` } @@ -10,7 +49,42 @@ type InnerObject struct { ID int `json:"id"` } -type Keywords struct { +type InputDirectives struct { + Text string `json:"text"` + Inner InnerDirectives `json:"inner"` + InnerNullable *InnerDirectives `json:"innerNullable"` + ThirdParty *ThirdParty `json:"thirdParty"` +} + +// Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_ +// added to the TypeMap +type Map struct { + ID string `json:"id"` +} + +type OuterInput struct { + Inner InnerInput `json:"inner"` +} + +type OuterObject struct { + Inner InnerObject `json:"inner"` +} + +type Slices struct { + Test1 []*string `json:"test1"` + Test2 []string `json:"test2"` + Test3 []*string `json:"test3"` + Test4 []string `json:"test4"` +} + +type User struct { + ID int `json:"id"` + Friends []User `json:"friends"` + Created time.Time `json:"created"` + Updated *time.Time `json:"updated"` +} + +type ValidInput struct { Break string `json:"break"` Default string `json:"default"` Func string `json:"func"` @@ -36,17 +110,70 @@ type Keywords struct { Import string `json:"import"` Return string `json:"return"` Var string `json:"var"` + Underscore string `json:"_"` } -type OuterInput struct { - Inner InnerInput `json:"inner"` +// These things are all valid, but without care generate invalid go code +type ValidType struct { + DifferentCase string `json:"differentCase"` + DifferentCaseOld string `json:"different_case"` + ValidInputKeywords bool `json:"validInputKeywords"` + ValidArgs bool `json:"validArgs"` } -type OuterObject struct { - Inner InnerObject `json:"inner"` +type XXIt struct { + ID string `json:"id"` } -type User struct { - ID int `json:"id"` - Friends []User `json:"friends"` +type XxIt struct { + ID string `json:"id"` +} + +type AsdfIt struct { + ID string `json:"id"` +} + +type IIt struct { + ID string `json:"id"` +} + +type Status string + +const ( + StatusOk Status = "OK" + StatusError Status = "ERROR" +) + +var AllStatus = []Status{ + StatusOk, + StatusError, +} + +func (e Status) IsValid() bool { + switch e { + case StatusOk, StatusError: + return true + } + return false +} + +func (e Status) String() string { + return string(e) +} + +func (e *Status) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = Status(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Status", str) + } + return nil +} + +func (e Status) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) } diff --git a/codegen/testserver/models.go b/codegen/testserver/models.go index 8647046a60..3ee710a50f 100644 --- a/codegen/testserver/models.go +++ b/codegen/testserver/models.go @@ -1,8 +1,9 @@ package testserver import ( - context "context" + "context" "fmt" + "io" ) type ForcedResolver struct { @@ -44,3 +45,42 @@ type EmbeddedPointerModel struct { type EmbeddedPointer struct { Title string } + +type MarshalPanic string + +func (m *MarshalPanic) UnmarshalGQL(v interface{}) error { + panic("BOOM") +} + +func (m MarshalPanic) MarshalGQL(w io.Writer) { + panic("BOOM") +} + +type Panics struct { +} + +func (p *Panics) FieldFuncMarshal(ctx context.Context, u []MarshalPanic) []MarshalPanic { + return []MarshalPanic{MarshalPanic("aa"), MarshalPanic("bb")} +} + +type Autobind struct { + Int int + Int32 int32 + Int64 int64 + + IdStr string + IdInt int +} + +type OverlappingFields struct { + Foo int + NewFoo int +} + +type FallbackToStringEncoding string + +const ( + FallbackToStringEncodingA FallbackToStringEncoding = "A" + FallbackToStringEncodingB FallbackToStringEncoding = "B" + FallbackToStringEncodingC FallbackToStringEncoding = "C" +) diff --git a/codegen/testserver/nulls_test.go b/codegen/testserver/nulls_test.go new file mode 100644 index 0000000000..b70935db11 --- /dev/null +++ b/codegen/testserver/nulls_test.go @@ -0,0 +1,83 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestNullBubbling(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.Valid = func(ctx context.Context) (s string, e error) { + return "Ok", nil + } + + resolvers.QueryResolver.ErrorBubble = func(ctx context.Context) (i *Error, e error) { + return &Error{ID: "E1234"}, nil + } + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + t.Run("when function errors on non required field", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + Id string + ErrorOnNonRequiredField *string + } + } + err := c.Post(`query { valid, errorBubble { id, errorOnNonRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnNonRequiredField"]}]`) + require.Equal(t, "E1234", resp.ErrorBubble.Id) + require.Nil(t, resp.ErrorBubble.ErrorOnNonRequiredField) + require.Equal(t, "Ok", resp.Valid) + }) + + t.Run("when function errors", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + NilOnRequiredField string + } + } + err := c.Post(`query { valid, errorBubble { id, errorOnRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnRequiredField"]}]`) + require.Nil(t, resp.ErrorBubble) + require.Equal(t, "Ok", resp.Valid) + }) + + t.Run("when user returns null on required field", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + NilOnRequiredField string + } + } + err := c.Post(`query { valid, errorBubble { id, nilOnRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"must not be null","path":["errorBubble","nilOnRequiredField"]}]`) + require.Nil(t, resp.ErrorBubble) + require.Equal(t, "Ok", resp.Valid) + }) + + t.Run("null args", func(t *testing.T) { + var resp struct { + NullableArg *string + } + resolvers.QueryResolver.NullableArg = func(ctx context.Context, arg *int) (i *string, e error) { + v := "Ok" + return &v, nil + } + + err := c.Post(`query { nullableArg(arg: null) }`, &resp) + require.Nil(t, err) + require.Equal(t, "Ok", *resp.NullableArg) + }) +} diff --git a/codegen/testserver/panics.graphql b/codegen/testserver/panics.graphql new file mode 100644 index 0000000000..8895fca82c --- /dev/null +++ b/codegen/testserver/panics.graphql @@ -0,0 +1,12 @@ +extend type Query { + panics: Panics +} + +type Panics { + fieldScalarMarshal: [MarshalPanic!]! + fieldFuncMarshal(u: [MarshalPanic!]!): [MarshalPanic!]! + argUnmarshal(u: [MarshalPanic!]!): Boolean! + +} + +scalar MarshalPanic diff --git a/codegen/testserver/panics_test.go b/codegen/testserver/panics_test.go new file mode 100644 index 0000000000..ed7ce713cb --- /dev/null +++ b/codegen/testserver/panics_test.go @@ -0,0 +1,56 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" +) + +func TestPanics(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.Panics = func(ctx context.Context) (panics *Panics, e error) { + return &Panics{}, nil + } + resolvers.PanicsResolver.ArgUnmarshal = func(ctx context.Context, obj *Panics, u []MarshalPanic) (b bool, e error) { + return true, nil + } + resolvers.PanicsResolver.FieldScalarMarshal = func(ctx context.Context, obj *Panics) (marshalPanic []MarshalPanic, e error) { + return []MarshalPanic{MarshalPanic("aa"), MarshalPanic("bb")}, nil + } + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + t.Run("panics in marshallers will not kill server", func(t *testing.T) { + var resp interface{} + err := c.Post(`query { panics { fieldScalarMarshal } }`, &resp) + + require.EqualError(t, err, "http 422: {\"errors\":[{\"message\":\"internal system error\"}],\"data\":null}") + }) + + t.Run("panics in unmarshalers will not kill server", func(t *testing.T) { + var resp interface{} + err := c.Post(`query { panics { argUnmarshal(u: ["aa", "bb"]) } }`, &resp) + + require.EqualError(t, err, "http 422: {\"errors\":[{\"message\":\"internal system error\"}],\"data\":null}") + }) + + t.Run("panics in funcs unmarshal return errors", func(t *testing.T) { + var resp interface{} + err := c.Post(`query { panics { fieldFuncMarshal(u: ["aa", "bb"]) } }`, &resp) + + require.EqualError(t, err, "http 422: {\"errors\":[{\"message\":\"internal system error\"}],\"data\":null}") + }) + + t.Run("panics in funcs marshal return errors", func(t *testing.T) { + var resp interface{} + err := c.Post(`query { panics { fieldFuncMarshal(u: []) } }`, &resp) + + require.EqualError(t, err, "http 422: {\"errors\":[{\"message\":\"internal system error\"}],\"data\":null}") + }) +} diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index f7d04e16cb..b00e7ee0b6 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -7,6 +7,8 @@ import ( "github.com/99designs/gqlgen/codegen/testserver/invalid-packagename" ) +// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES. + type Resolver struct{} func (r *Resolver) ForcedResolver() ForcedResolverResolver { @@ -15,6 +17,12 @@ func (r *Resolver) ForcedResolver() ForcedResolverResolver { func (r *Resolver) ModelMethods() ModelMethodsResolver { return &modelMethodsResolver{r} } +func (r *Resolver) OverlappingFields() OverlappingFieldsResolver { + return &overlappingFieldsResolver{r} +} +func (r *Resolver) Panics() PanicsResolver { + return &panicsResolver{r} +} func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } @@ -37,6 +45,21 @@ func (r *modelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMeth panic("not implemented") } +type overlappingFieldsResolver struct{ *Resolver } + +func (r *overlappingFieldsResolver) OldFoo(ctx context.Context, obj *OverlappingFields) (int, error) { + panic("not implemented") +} + +type panicsResolver struct{ *Resolver } + +func (r *panicsResolver) FieldScalarMarshal(ctx context.Context, obj *Panics) ([]MarshalPanic, error) { + panic("not implemented") +} +func (r *panicsResolver) ArgUnmarshal(ctx context.Context, obj *Panics, u []MarshalPanic) (bool, error) { + panic("not implemented") +} + type queryResolver struct{ *Resolver } func (r *queryResolver) InvalidIdentifier(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) { @@ -45,7 +68,7 @@ func (r *queryResolver) InvalidIdentifier(ctx context.Context) (*invalid_package func (r *queryResolver) Collision(ctx context.Context) (*introspection1.It, error) { panic("not implemented") } -func (r *queryResolver) MapInput(ctx context.Context, input *map[string]interface{}) (*bool, error) { +func (r *queryResolver) MapInput(ctx context.Context, input map[string]interface{}) (*bool, error) { panic("not implemented") } func (r *queryResolver) Recursive(ctx context.Context, input *RecursiveInputSlice) (*bool, error) { @@ -57,10 +80,7 @@ func (r *queryResolver) NestedInputs(ctx context.Context, input [][]*OuterInput) func (r *queryResolver) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) { panic("not implemented") } -func (r *queryResolver) Keywords(ctx context.Context, input *Keywords) (bool, error) { - panic("not implemented") -} -func (r *queryResolver) Shapes(ctx context.Context) ([]*Shape, error) { +func (r *queryResolver) Shapes(ctx context.Context) ([]Shape, error) { panic("not implemented") } func (r *queryResolver) ErrorBubble(ctx context.Context) (*Error, error) { @@ -72,13 +92,61 @@ func (r *queryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) func (r *queryResolver) Valid(ctx context.Context) (string, error) { panic("not implemented") } -func (r *queryResolver) User(ctx context.Context, id int) (User, error) { +func (r *queryResolver) User(ctx context.Context, id int) (*User, error) { panic("not implemented") } func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) { panic("not implemented") } -func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { +func (r *queryResolver) DirectiveArg(ctx context.Context, arg string) (*string, error) { + panic("not implemented") +} +func (r *queryResolver) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) { + panic("not implemented") +} +func (r *queryResolver) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) { + panic("not implemented") +} +func (r *queryResolver) DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) { + panic("not implemented") +} +func (r *queryResolver) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) { + panic("not implemented") +} +func (r *queryResolver) InputSlice(ctx context.Context, arg []string) (bool, error) { + panic("not implemented") +} +func (r *queryResolver) ShapeUnion(ctx context.Context) (ShapeUnion, error) { + panic("not implemented") +} +func (r *queryResolver) Autobind(ctx context.Context) (*Autobind, error) { + panic("not implemented") +} +func (r *queryResolver) DeprecatedField(ctx context.Context) (string, error) { + panic("not implemented") +} +func (r *queryResolver) Overlapping(ctx context.Context) (*OverlappingFields, error) { + panic("not implemented") +} +func (r *queryResolver) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) { + panic("not implemented") +} +func (r *queryResolver) Panics(ctx context.Context) (*Panics, error) { + panic("not implemented") +} +func (r *queryResolver) DefaultScalar(ctx context.Context, arg string) (string, error) { + panic("not implemented") +} +func (r *queryResolver) Slices(ctx context.Context) (*Slices, error) { + panic("not implemented") +} +func (r *queryResolver) Fallback(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) { + panic("not implemented") +} +func (r *queryResolver) OptionalUnion(ctx context.Context) (TestUnion, error) { + panic("not implemented") +} +func (r *queryResolver) ValidType(ctx context.Context) (*ValidType, error) { panic("not implemented") } diff --git a/codegen/testserver/response_extension_test.go b/codegen/testserver/response_extension_test.go new file mode 100644 index 0000000000..026aa31716 --- /dev/null +++ b/codegen/testserver/response_extension_test.go @@ -0,0 +1,34 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestResponseExtension(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.Valid = func(ctx context.Context) (s string, e error) { + return "Ok", nil + } + + srv := httptest.NewServer(handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.RequestMiddleware(func(ctx context.Context, next func(ctx context.Context) []byte) []byte { + rctx := graphql.GetRequestContext(ctx) + if err := rctx.RegisterExtension("example", "value"); err != nil { + panic(err) + } + return next(ctx) + }), + )) + c := client.New(srv.URL) + + raw, _ := c.RawPost(`query { valid }`) + require.Equal(t, raw.Extensions["example"], "value") +} diff --git a/codegen/testserver/scalar_default.graphql b/codegen/testserver/scalar_default.graphql new file mode 100644 index 0000000000..5e3a9c08fd --- /dev/null +++ b/codegen/testserver/scalar_default.graphql @@ -0,0 +1,10 @@ +extend type Query { + defaultScalar(arg: DefaultScalarImplementation! = "default"): DefaultScalarImplementation! +} + +""" This doesnt have an implementation in the typemap, so it should act like a string """ +scalar DefaultScalarImplementation + +type EmbeddedDefaultScalar { + value: DefaultScalarImplementation +} diff --git a/codegen/testserver/scalar_default_test.go b/codegen/testserver/scalar_default_test.go new file mode 100644 index 0000000000..4b438560ce --- /dev/null +++ b/codegen/testserver/scalar_default_test.go @@ -0,0 +1,34 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestDefaultScalarImplementation(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + resolvers.QueryResolver.DefaultScalar = func(ctx context.Context, arg string) (i string, e error) { + return arg, nil + } + + t.Run("with arg value", func(t *testing.T) { + var resp struct{ DefaultScalar string } + c.MustPost(`query { defaultScalar(arg: "fff") }`, &resp) + require.Equal(t, "fff", resp.DefaultScalar) + }) + + t.Run("with default value", func(t *testing.T) { + var resp struct{ DefaultScalar string } + c.MustPost(`query { defaultScalar }`, &resp) + require.Equal(t, "default", resp.DefaultScalar) + }) +} diff --git a/codegen/testserver/schema.graphql b/codegen/testserver/schema.graphql index 276e7130be..0b135308f2 100644 --- a/codegen/testserver/schema.graphql +++ b/codegen/testserver/schema.graphql @@ -5,13 +5,21 @@ type Query { recursive(input: RecursiveInputSlice): Boolean nestedInputs(input: [[OuterInput]] = [[{inner: {id: 1}}]]): Boolean nestedOutputs: [[OuterObject]] - keywords(input: Keywords): Boolean! shapes: [Shape] errorBubble: Error modelMethods: ModelMethods valid: String! user(id: Int!): User! nullableArg(arg: Int = 123): String + directiveArg(arg: String! @length(min:1, max: 255, message: "invalid length")): String + directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String + directiveInputNullable(arg: InputDirectives): String + directiveInput(arg: InputDirectives!): String + directiveInputType(arg: InnerInput! @custom): String + inputSlice(arg: [String!]!): Boolean! + shapeUnion: ShapeUnion! + autobind: Autobind + deprecatedField: String! @deprecated(reason: "test deprecated directive") } type Subscription { @@ -22,6 +30,17 @@ type Subscription { type User { id: Int! friends: [User!]! + created: Time! + updated: Time +} + +type Autobind { + int: Int! + int32: Int! + int64: Int! + + idStr: ID! + idInt: ID! } type Error { @@ -62,6 +81,19 @@ input OuterInput { inner: InnerInput! } +scalar ThirdParty + +input InputDirectives { + text: String! @length(min: 0, max: 7, message: "not valid") + inner: InnerDirectives! + innerNullable: InnerDirectives + thirdParty: ThirdParty @length(min: 0, max: 7, message: "not valid") +} + +input InnerDirectives { + message: String! @length(min: 1, message: "not valid") +} + type OuterObject { inner: InnerObject! } @@ -70,64 +102,6 @@ type InnerObject { id: Int! } -input Keywords { - break: String! - default: String! - func: String! - interface: String! - select: String! - case: String! - defer: String! - go: String! - map: String! - struct: String! - chan: String! - else: String! - goto: String! - package: String! - switch: String! - const: String! - fallthrough: String! - if: String! - range: String! - type: String! - continue: String! - for: String! - import: String! - return: String! - var: String! -} - -extend type Query { - keywordArgs( - break: String!, - default: String!, - func: String!, - interface: String!, - select: String!, - case: String!, - defer: String!, - go: String!, - map: String!, - struct: String!, - chan: String!, - else: String!, - goto: String!, - package: String!, - switch: String!, - const: String!, - fallthrough: String!, - if: String!, - range: String!, - type: String!, - continue: String!, - for: String!, - import: String!, - return: String!, - var: String!, - ): Boolean! -} - interface Shape { area: Float } @@ -150,3 +124,14 @@ type EmbeddedPointer { ID: String Title: String } + +directive @length(min: Int!, max: Int) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION +directive @range(min: Int = 0, max: Int) on ARGUMENT_DEFINITION +directive @custom on ARGUMENT_DEFINITION + +enum Status { + OK + ERROR +} + +scalar Time diff --git a/codegen/testserver/slices.graphql b/codegen/testserver/slices.graphql new file mode 100644 index 0000000000..7f4ca489f8 --- /dev/null +++ b/codegen/testserver/slices.graphql @@ -0,0 +1,10 @@ +extend type Query { + slices: Slices +} + +type Slices { + test1: [String] + test2: [String!] + test3: [String]! + test4: [String!]! +} diff --git a/codegen/testserver/slices_test.go b/codegen/testserver/slices_test.go new file mode 100644 index 0000000000..2516884705 --- /dev/null +++ b/codegen/testserver/slices_test.go @@ -0,0 +1,33 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestSlices(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + t.Run("nulls vs empty slices", func(t *testing.T) { + resolvers.QueryResolver.Slices = func(ctx context.Context) (slices *Slices, e error) { + return &Slices{}, nil + } + + var resp struct { + Slices Slices + } + c.MustPost(`query { slices { test1, test2, test3, test4 }}`, &resp) + require.Nil(t, resp.Slices.Test1) + require.Nil(t, resp.Slices.Test2) + require.NotNil(t, resp.Slices.Test3) + require.NotNil(t, resp.Slices.Test4) + }) +} diff --git a/codegen/testserver/stub.go b/codegen/testserver/stub.go new file mode 100644 index 0000000000..36a100b96f --- /dev/null +++ b/codegen/testserver/stub.go @@ -0,0 +1,218 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package testserver + +import ( + "context" + + introspection1 "github.com/99designs/gqlgen/codegen/testserver/introspection" + "github.com/99designs/gqlgen/codegen/testserver/invalid-packagename" +) + +type Stub struct { + ForcedResolverResolver struct { + Field func(ctx context.Context, obj *ForcedResolver) (*Circle, error) + } + ModelMethodsResolver struct { + ResolverField func(ctx context.Context, obj *ModelMethods) (bool, error) + } + OverlappingFieldsResolver struct { + OldFoo func(ctx context.Context, obj *OverlappingFields) (int, error) + } + PanicsResolver struct { + FieldScalarMarshal func(ctx context.Context, obj *Panics) ([]MarshalPanic, error) + ArgUnmarshal func(ctx context.Context, obj *Panics, u []MarshalPanic) (bool, error) + } + QueryResolver struct { + InvalidIdentifier func(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) + Collision func(ctx context.Context) (*introspection1.It, error) + MapInput func(ctx context.Context, input map[string]interface{}) (*bool, error) + Recursive func(ctx context.Context, input *RecursiveInputSlice) (*bool, error) + NestedInputs func(ctx context.Context, input [][]*OuterInput) (*bool, error) + NestedOutputs func(ctx context.Context) ([][]*OuterObject, error) + Shapes func(ctx context.Context) ([]Shape, error) + ErrorBubble func(ctx context.Context) (*Error, error) + ModelMethods func(ctx context.Context) (*ModelMethods, error) + Valid func(ctx context.Context) (string, error) + User func(ctx context.Context, id int) (*User, error) + NullableArg func(ctx context.Context, arg *int) (*string, error) + DirectiveArg func(ctx context.Context, arg string) (*string, error) + DirectiveNullableArg func(ctx context.Context, arg *int, arg2 *int) (*string, error) + DirectiveInputNullable func(ctx context.Context, arg *InputDirectives) (*string, error) + DirectiveInput func(ctx context.Context, arg InputDirectives) (*string, error) + DirectiveInputType func(ctx context.Context, arg InnerInput) (*string, error) + InputSlice func(ctx context.Context, arg []string) (bool, error) + ShapeUnion func(ctx context.Context) (ShapeUnion, error) + Autobind func(ctx context.Context) (*Autobind, error) + DeprecatedField func(ctx context.Context) (string, error) + Overlapping func(ctx context.Context) (*OverlappingFields, error) + MapStringInterface func(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) + Panics func(ctx context.Context) (*Panics, error) + DefaultScalar func(ctx context.Context, arg string) (string, error) + Slices func(ctx context.Context) (*Slices, error) + Fallback func(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) + OptionalUnion func(ctx context.Context) (TestUnion, error) + ValidType func(ctx context.Context) (*ValidType, error) + } + SubscriptionResolver struct { + Updated func(ctx context.Context) (<-chan string, error) + InitPayload func(ctx context.Context) (<-chan string, error) + } + UserResolver struct { + Friends func(ctx context.Context, obj *User) ([]User, error) + } +} + +func (r *Stub) ForcedResolver() ForcedResolverResolver { + return &stubForcedResolver{r} +} +func (r *Stub) ModelMethods() ModelMethodsResolver { + return &stubModelMethods{r} +} +func (r *Stub) OverlappingFields() OverlappingFieldsResolver { + return &stubOverlappingFields{r} +} +func (r *Stub) Panics() PanicsResolver { + return &stubPanics{r} +} +func (r *Stub) Query() QueryResolver { + return &stubQuery{r} +} +func (r *Stub) Subscription() SubscriptionResolver { + return &stubSubscription{r} +} +func (r *Stub) User() UserResolver { + return &stubUser{r} +} + +type stubForcedResolver struct{ *Stub } + +func (r *stubForcedResolver) Field(ctx context.Context, obj *ForcedResolver) (*Circle, error) { + return r.ForcedResolverResolver.Field(ctx, obj) +} + +type stubModelMethods struct{ *Stub } + +func (r *stubModelMethods) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) { + return r.ModelMethodsResolver.ResolverField(ctx, obj) +} + +type stubOverlappingFields struct{ *Stub } + +func (r *stubOverlappingFields) OldFoo(ctx context.Context, obj *OverlappingFields) (int, error) { + return r.OverlappingFieldsResolver.OldFoo(ctx, obj) +} + +type stubPanics struct{ *Stub } + +func (r *stubPanics) FieldScalarMarshal(ctx context.Context, obj *Panics) ([]MarshalPanic, error) { + return r.PanicsResolver.FieldScalarMarshal(ctx, obj) +} +func (r *stubPanics) ArgUnmarshal(ctx context.Context, obj *Panics, u []MarshalPanic) (bool, error) { + return r.PanicsResolver.ArgUnmarshal(ctx, obj, u) +} + +type stubQuery struct{ *Stub } + +func (r *stubQuery) InvalidIdentifier(ctx context.Context) (*invalid_packagename.InvalidIdentifier, error) { + return r.QueryResolver.InvalidIdentifier(ctx) +} +func (r *stubQuery) Collision(ctx context.Context) (*introspection1.It, error) { + return r.QueryResolver.Collision(ctx) +} +func (r *stubQuery) MapInput(ctx context.Context, input map[string]interface{}) (*bool, error) { + return r.QueryResolver.MapInput(ctx, input) +} +func (r *stubQuery) Recursive(ctx context.Context, input *RecursiveInputSlice) (*bool, error) { + return r.QueryResolver.Recursive(ctx, input) +} +func (r *stubQuery) NestedInputs(ctx context.Context, input [][]*OuterInput) (*bool, error) { + return r.QueryResolver.NestedInputs(ctx, input) +} +func (r *stubQuery) NestedOutputs(ctx context.Context) ([][]*OuterObject, error) { + return r.QueryResolver.NestedOutputs(ctx) +} +func (r *stubQuery) Shapes(ctx context.Context) ([]Shape, error) { + return r.QueryResolver.Shapes(ctx) +} +func (r *stubQuery) ErrorBubble(ctx context.Context) (*Error, error) { + return r.QueryResolver.ErrorBubble(ctx) +} +func (r *stubQuery) ModelMethods(ctx context.Context) (*ModelMethods, error) { + return r.QueryResolver.ModelMethods(ctx) +} +func (r *stubQuery) Valid(ctx context.Context) (string, error) { + return r.QueryResolver.Valid(ctx) +} +func (r *stubQuery) User(ctx context.Context, id int) (*User, error) { + return r.QueryResolver.User(ctx, id) +} +func (r *stubQuery) NullableArg(ctx context.Context, arg *int) (*string, error) { + return r.QueryResolver.NullableArg(ctx, arg) +} +func (r *stubQuery) DirectiveArg(ctx context.Context, arg string) (*string, error) { + return r.QueryResolver.DirectiveArg(ctx, arg) +} +func (r *stubQuery) DirectiveNullableArg(ctx context.Context, arg *int, arg2 *int) (*string, error) { + return r.QueryResolver.DirectiveNullableArg(ctx, arg, arg2) +} +func (r *stubQuery) DirectiveInputNullable(ctx context.Context, arg *InputDirectives) (*string, error) { + return r.QueryResolver.DirectiveInputNullable(ctx, arg) +} +func (r *stubQuery) DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) { + return r.QueryResolver.DirectiveInput(ctx, arg) +} +func (r *stubQuery) DirectiveInputType(ctx context.Context, arg InnerInput) (*string, error) { + return r.QueryResolver.DirectiveInputType(ctx, arg) +} +func (r *stubQuery) InputSlice(ctx context.Context, arg []string) (bool, error) { + return r.QueryResolver.InputSlice(ctx, arg) +} +func (r *stubQuery) ShapeUnion(ctx context.Context) (ShapeUnion, error) { + return r.QueryResolver.ShapeUnion(ctx) +} +func (r *stubQuery) Autobind(ctx context.Context) (*Autobind, error) { + return r.QueryResolver.Autobind(ctx) +} +func (r *stubQuery) DeprecatedField(ctx context.Context) (string, error) { + return r.QueryResolver.DeprecatedField(ctx) +} +func (r *stubQuery) Overlapping(ctx context.Context) (*OverlappingFields, error) { + return r.QueryResolver.Overlapping(ctx) +} +func (r *stubQuery) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) { + return r.QueryResolver.MapStringInterface(ctx, in) +} +func (r *stubQuery) Panics(ctx context.Context) (*Panics, error) { + return r.QueryResolver.Panics(ctx) +} +func (r *stubQuery) DefaultScalar(ctx context.Context, arg string) (string, error) { + return r.QueryResolver.DefaultScalar(ctx, arg) +} +func (r *stubQuery) Slices(ctx context.Context) (*Slices, error) { + return r.QueryResolver.Slices(ctx) +} +func (r *stubQuery) Fallback(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) { + return r.QueryResolver.Fallback(ctx, arg) +} +func (r *stubQuery) OptionalUnion(ctx context.Context) (TestUnion, error) { + return r.QueryResolver.OptionalUnion(ctx) +} +func (r *stubQuery) ValidType(ctx context.Context) (*ValidType, error) { + return r.QueryResolver.ValidType(ctx) +} + +type stubSubscription struct{ *Stub } + +func (r *stubSubscription) Updated(ctx context.Context) (<-chan string, error) { + return r.SubscriptionResolver.Updated(ctx) +} +func (r *stubSubscription) InitPayload(ctx context.Context) (<-chan string, error) { + return r.SubscriptionResolver.InitPayload(ctx) +} + +type stubUser struct{ *Stub } + +func (r *stubUser) Friends(ctx context.Context, obj *User) ([]User, error) { + return r.UserResolver.Friends(ctx, obj) +} diff --git a/codegen/testserver/subscription_test.go b/codegen/testserver/subscription_test.go new file mode 100644 index 0000000000..16fdc8007e --- /dev/null +++ b/codegen/testserver/subscription_test.go @@ -0,0 +1,139 @@ +package testserver + +import ( + "context" + "fmt" + "net/http/httptest" + "runtime" + "sort" + "testing" + "time" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestSubscriptions(t *testing.T) { + tick := make(chan string, 1) + + resolvers := &Stub{} + + resolvers.SubscriptionResolver.InitPayload = func(ctx context.Context) (strings <-chan string, e error) { + payload := handler.GetInitPayload(ctx) + channel := make(chan string, len(payload)+1) + + go func() { + <-ctx.Done() + close(channel) + }() + + // Test the helper function separately + auth := payload.Authorization() + if auth != "" { + channel <- "AUTH:" + auth + } else { + channel <- "AUTH:NONE" + } + + // Send them over the channel in alphabetic order + keys := make([]string, 0, len(payload)) + for key := range payload { + keys = append(keys, key) + } + sort.Strings(keys) + for _, key := range keys { + channel <- fmt.Sprintf("%s = %#+v", key, payload[key]) + } + + return channel, nil + } + + resolvers.SubscriptionResolver.Updated = func(ctx context.Context) (<-chan string, error) { + res := make(chan string, 1) + + go func() { + for { + select { + case t := <-tick: + res <- t + case <-ctx.Done(): + close(res) + return + } + } + }() + return res, nil + } + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 1))) + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 2))) + }), + )) + c := client.New(srv.URL) + + t.Run("wont leak goroutines", func(t *testing.T) { + runtime.GC() // ensure no go-routines left from preceding tests + initialGoroutineCount := runtime.NumGoroutine() + + sub := c.Websocket(`subscription { updated }`) + + tick <- "message" + + var msg struct { + resp struct { + Updated string + } + } + + err := sub.Next(&msg.resp) + require.NoError(t, err) + require.Equal(t, "message", msg.resp.Updated) + sub.Close() + + // need a little bit of time for goroutines to settle + start := time.Now() + for time.Since(start).Seconds() < 2 && initialGoroutineCount != runtime.NumGoroutine() { + time.Sleep(5 * time.Millisecond) + } + + require.Equal(t, initialGoroutineCount, runtime.NumGoroutine()) + }) + + t.Run("will parse init payload", func(t *testing.T) { + sub := c.WebsocketWithPayload(`subscription { initPayload }`, map[string]interface{}{ + "Authorization": "Bearer of the curse", + "number": 32, + "strings": []string{"hello", "world"}, + }) + + var msg struct { + resp struct { + InitPayload string + } + } + + err := sub.Next(&msg.resp) + require.NoError(t, err) + require.Equal(t, "AUTH:Bearer of the curse", msg.resp.InitPayload) + err = sub.Next(&msg.resp) + require.NoError(t, err) + require.Equal(t, "Authorization = \"Bearer of the curse\"", msg.resp.InitPayload) + err = sub.Next(&msg.resp) + require.NoError(t, err) + require.Equal(t, "number = 32", msg.resp.InitPayload) + err = sub.Next(&msg.resp) + require.NoError(t, err) + require.Equal(t, "strings = []interface {}{\"hello\", \"world\"}", msg.resp.InitPayload) + sub.Close() + }) +} diff --git a/codegen/testserver/thirdparty.go b/codegen/testserver/thirdparty.go new file mode 100644 index 0000000000..104548ce71 --- /dev/null +++ b/codegen/testserver/thirdparty.go @@ -0,0 +1,30 @@ +package testserver + +import ( + "fmt" + "github.com/99designs/gqlgen/graphql" + "io" + "strconv" +) + +type ThirdParty struct { + str string +} + +func MarshalThirdParty(tp ThirdParty) graphql.Marshaler { + return graphql.WriterFunc(func(w io.Writer) { + _, err := io.WriteString(w, strconv.Quote(tp.str)) + if err != nil { + panic(err) + } + }) +} + +func UnmarshalThirdParty(input interface{}) (ThirdParty, error) { + switch input := input.(type) { + case string: + return ThirdParty{str: input}, nil + default: + return ThirdParty{}, fmt.Errorf("unknown type for input: %s", input) + } +} diff --git a/codegen/testserver/time_test.go b/codegen/testserver/time_test.go new file mode 100644 index 0000000000..fc293563e7 --- /dev/null +++ b/codegen/testserver/time_test.go @@ -0,0 +1,70 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + "time" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestTime(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + resolvers.QueryResolver.User = func(ctx context.Context, id int) (user *User, e error) { + return &User{}, nil + } + + t.Run("zero value in nullable field", func(t *testing.T) { + var resp struct { + User struct { + Updated *string + } + } + + err := c.Post(`query { user(id: 1) { updated } }`, &resp) + require.NoError(t, err) + + require.Nil(t, resp.User.Updated) + }) + + t.Run("zero value in non nullable field", func(t *testing.T) { + var resp struct { + User struct { + Created *string + } + } + + err := c.Post(`query { user(id: 1) { created } }`, &resp) + require.EqualError(t, err, `[{"message":"must not be null","path":["user","created"]}]`) + }) + + t.Run("with values", func(t *testing.T) { + resolvers.QueryResolver.User = func(ctx context.Context, id int) (user *User, e error) { + updated := time.Date(2010, 1, 1, 0, 0, 20, 0, time.UTC) + return &User{ + Created: time.Date(2010, 1, 1, 0, 0, 10, 0, time.UTC), + Updated: &updated, + }, nil + } + + var resp struct { + User struct { + Created string + Updated string + } + } + + err := c.Post(`query { user(id: 1) { created, updated } }`, &resp) + require.NoError(t, err) + + require.Equal(t, "2010-01-01T00:00:10Z", resp.User.Created) + require.Equal(t, "2010-01-01T00:00:20Z", resp.User.Updated) + }) +} diff --git a/codegen/testserver/tracer_test.go b/codegen/testserver/tracer_test.go new file mode 100644 index 0000000000..e2ccc5f95f --- /dev/null +++ b/codegen/testserver/tracer_test.go @@ -0,0 +1,352 @@ +package testserver + +import ( + "context" + "fmt" + "net/http/httptest" + "sync" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestTracer(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.User = func(ctx context.Context, id int) (user *User, e error) { + return &User{ID: 1}, nil + } + t.Run("called in the correct order", func(t *testing.T) { + var tracerLog []string + var mu sync.Mutex + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 1))) + }), + handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { + path, _ := ctx.Value("path").([]int) + return next(context.WithValue(ctx, "path", append(path, 2))) + }), + handler.Tracer(&testTracer{ + id: 1, + append: func(s string) { + mu.Lock() + defer mu.Unlock() + tracerLog = append(tracerLog, s) + }, + }), + handler.Tracer(&testTracer{ + id: 2, + append: func(s string) { + mu.Lock() + defer mu.Unlock() + tracerLog = append(tracerLog, s) + }, + }), + )) + defer srv.Close() + c := client.New(srv.URL) + + var resp struct { + User struct { + ID int + Friends []struct { + ID int + } + } + } + + called := false + resolvers.UserResolver.Friends = func(ctx context.Context, obj *User) ([]User, error) { + assert.Equal(t, []string{ + "op:p:start:1", "op:p:start:2", + "op:v:start:1", "op:v:start:2", + "op:e:start:1", "op:e:start:2", + "field'a:e:start:1:user", "field'a:e:start:2:user", + "field'b:e:start:1:[user]", "field'b:e:start:2:[user]", + "field'c:e:start:1", "field'c:e:start:2", + "field'a:e:start:1:friends", "field'a:e:start:2:friends", + "field'b:e:start:1:[user friends]", "field'b:e:start:2:[user friends]", + }, ctx.Value("tracer")) + called = true + return []User{}, nil + } + + err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) + + require.NoError(t, err) + require.True(t, called) + mu.Lock() + defer mu.Unlock() + assert.Equal(t, []string{ + "op:p:start:1", "op:p:start:2", + "op:p:end:2", "op:p:end:1", + + "op:v:start:1", "op:v:start:2", + "op:v:end:2", "op:v:end:1", + + "op:e:start:1", "op:e:start:2", + + "field'a:e:start:1:user", "field'a:e:start:2:user", + "field'b:e:start:1:[user]", "field'b:e:start:2:[user]", + "field'c:e:start:1", "field'c:e:start:2", + "field'a:e:start:1:id", "field'a:e:start:2:id", + "field'b:e:start:1:[user id]", "field'b:e:start:2:[user id]", + "field'c:e:start:1", "field'c:e:start:2", + "field:e:end:2", "field:e:end:1", + "field'a:e:start:1:friends", "field'a:e:start:2:friends", + "field'b:e:start:1:[user friends]", "field'b:e:start:2:[user friends]", + "field'c:e:start:1", "field'c:e:start:2", + "field:e:end:2", "field:e:end:1", + "field:e:end:2", "field:e:end:1", + + "op:e:end:2", "op:e:end:1", + }, tracerLog) + }) + + t.Run("take ctx over from prev step", func(t *testing.T) { + + configurableTracer := &configurableTracer{ + StartOperationParsingCallback: func(ctx context.Context) context.Context { + return context.WithValue(ctx, "StartOperationParsing", true) + }, + EndOperationParsingCallback: func(ctx context.Context) { + assert.NotNil(t, ctx.Value("StartOperationParsing")) + }, + + StartOperationValidationCallback: func(ctx context.Context) context.Context { + return context.WithValue(ctx, "StartOperationValidation", true) + }, + EndOperationValidationCallback: func(ctx context.Context) { + assert.NotNil(t, ctx.Value("StartOperationParsing")) + assert.NotNil(t, ctx.Value("StartOperationValidation")) + }, + + StartOperationExecutionCallback: func(ctx context.Context) context.Context { + return context.WithValue(ctx, "StartOperationExecution", true) + }, + StartFieldExecutionCallback: func(ctx context.Context, field graphql.CollectedField) context.Context { + return context.WithValue(ctx, "StartFieldExecution", true) + }, + StartFieldResolverExecutionCallback: func(ctx context.Context, rc *graphql.ResolverContext) context.Context { + return context.WithValue(ctx, "StartFieldResolverExecution", true) + }, + StartFieldChildExecutionCallback: func(ctx context.Context) context.Context { + return context.WithValue(ctx, "StartFieldChildExecution", true) + }, + EndFieldExecutionCallback: func(ctx context.Context) { + assert.NotNil(t, ctx.Value("StartOperationParsing")) + assert.NotNil(t, ctx.Value("StartOperationValidation")) + assert.NotNil(t, ctx.Value("StartOperationExecution")) + assert.NotNil(t, ctx.Value("StartFieldExecution")) + assert.NotNil(t, ctx.Value("StartFieldResolverExecution")) + assert.NotNil(t, ctx.Value("StartFieldChildExecution")) + }, + + EndOperationExecutionCallback: func(ctx context.Context) { + assert.NotNil(t, ctx.Value("StartOperationParsing")) + assert.NotNil(t, ctx.Value("StartOperationValidation")) + assert.NotNil(t, ctx.Value("StartOperationExecution")) + }, + } + + srv := httptest.NewServer( + handler.GraphQL( + NewExecutableSchema(Config{Resolvers: resolvers}), + handler.Tracer(configurableTracer), + )) + defer srv.Close() + c := client.New(srv.URL) + + var resp struct { + User struct { + ID int + Friends []struct { + ID int + } + } + } + + called := false + resolvers.UserResolver.Friends = func(ctx context.Context, obj *User) ([]User, error) { + called = true + return []User{}, nil + } + + err := c.Post(`query { user(id: 1) { id, friends { id } } }`, &resp) + + require.NoError(t, err) + require.True(t, called) + }) +} + +var _ graphql.Tracer = (*configurableTracer)(nil) + +type configurableTracer struct { + StartOperationParsingCallback func(ctx context.Context) context.Context + EndOperationParsingCallback func(ctx context.Context) + StartOperationValidationCallback func(ctx context.Context) context.Context + EndOperationValidationCallback func(ctx context.Context) + StartOperationExecutionCallback func(ctx context.Context) context.Context + StartFieldExecutionCallback func(ctx context.Context, field graphql.CollectedField) context.Context + StartFieldResolverExecutionCallback func(ctx context.Context, rc *graphql.ResolverContext) context.Context + StartFieldChildExecutionCallback func(ctx context.Context) context.Context + EndFieldExecutionCallback func(ctx context.Context) + EndOperationExecutionCallback func(ctx context.Context) +} + +func (ct *configurableTracer) StartOperationParsing(ctx context.Context) context.Context { + if f := ct.StartOperationParsingCallback; f != nil { + ctx = f(ctx) + } + return ctx +} + +func (ct *configurableTracer) EndOperationParsing(ctx context.Context) { + if f := ct.EndOperationParsingCallback; f != nil { + f(ctx) + } +} + +func (ct *configurableTracer) StartOperationValidation(ctx context.Context) context.Context { + if f := ct.StartOperationValidationCallback; f != nil { + ctx = f(ctx) + } + return ctx +} + +func (ct *configurableTracer) EndOperationValidation(ctx context.Context) { + if f := ct.EndOperationValidationCallback; f != nil { + f(ctx) + } +} + +func (ct *configurableTracer) StartOperationExecution(ctx context.Context) context.Context { + if f := ct.StartOperationExecutionCallback; f != nil { + ctx = f(ctx) + } + return ctx +} + +func (ct *configurableTracer) StartFieldExecution(ctx context.Context, field graphql.CollectedField) context.Context { + if f := ct.StartFieldExecutionCallback; f != nil { + ctx = f(ctx, field) + } + return ctx +} + +func (ct *configurableTracer) StartFieldResolverExecution(ctx context.Context, rc *graphql.ResolverContext) context.Context { + if f := ct.StartFieldResolverExecutionCallback; f != nil { + ctx = f(ctx, rc) + } + return ctx +} + +func (ct *configurableTracer) StartFieldChildExecution(ctx context.Context) context.Context { + if f := ct.StartFieldChildExecutionCallback; f != nil { + ctx = f(ctx) + } + return ctx +} + +func (ct *configurableTracer) EndFieldExecution(ctx context.Context) { + if f := ct.EndFieldExecutionCallback; f != nil { + f(ctx) + } +} + +func (ct *configurableTracer) EndOperationExecution(ctx context.Context) { + if f := ct.EndOperationExecutionCallback; f != nil { + f(ctx) + } +} + +var _ graphql.Tracer = (*testTracer)(nil) + +type testTracer struct { + id int + append func(string) +} + +func (tt *testTracer) StartOperationParsing(ctx context.Context) context.Context { + line := fmt.Sprintf("op:p:start:%d", tt.id) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) EndOperationParsing(ctx context.Context) { + tt.append(fmt.Sprintf("op:p:end:%d", tt.id)) +} + +func (tt *testTracer) StartOperationValidation(ctx context.Context) context.Context { + line := fmt.Sprintf("op:v:start:%d", tt.id) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) EndOperationValidation(ctx context.Context) { + tt.append(fmt.Sprintf("op:v:end:%d", tt.id)) +} + +func (tt *testTracer) StartOperationExecution(ctx context.Context) context.Context { + line := fmt.Sprintf("op:e:start:%d", tt.id) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) StartFieldExecution(ctx context.Context, field graphql.CollectedField) context.Context { + line := fmt.Sprintf("field'a:e:start:%d:%s", tt.id, field.Name) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) StartFieldResolverExecution(ctx context.Context, rc *graphql.ResolverContext) context.Context { + line := fmt.Sprintf("field'b:e:start:%d:%v", tt.id, rc.Path()) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) StartFieldChildExecution(ctx context.Context) context.Context { + line := fmt.Sprintf("field'c:e:start:%d", tt.id) + + tracerLogs, _ := ctx.Value("tracer").([]string) + ctx = context.WithValue(ctx, "tracer", append(append([]string{}, tracerLogs...), line)) + tt.append(line) + + return ctx +} + +func (tt *testTracer) EndFieldExecution(ctx context.Context) { + tt.append(fmt.Sprintf("field:e:end:%d", tt.id)) +} + +func (tt *testTracer) EndOperationExecution(ctx context.Context) { + tt.append(fmt.Sprintf("op:e:end:%d", tt.id)) +} diff --git a/codegen/testserver/typefallback.graphql b/codegen/testserver/typefallback.graphql new file mode 100644 index 0000000000..e1ff1a59d7 --- /dev/null +++ b/codegen/testserver/typefallback.graphql @@ -0,0 +1,9 @@ +extend type Query { + fallback(arg: FallbackToStringEncoding!): FallbackToStringEncoding! +} + +enum FallbackToStringEncoding { + A + B + C +} diff --git a/codegen/testserver/typefallback_test.go b/codegen/testserver/typefallback_test.go new file mode 100644 index 0000000000..0b0f83135e --- /dev/null +++ b/codegen/testserver/typefallback_test.go @@ -0,0 +1,30 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestTypeFallback(t *testing.T) { + resolvers := &Stub{} + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + resolvers.QueryResolver.Fallback = func(ctx context.Context, arg FallbackToStringEncoding) (FallbackToStringEncoding, error) { + return arg, nil + } + + t.Run("fallback to string passthrough", func(t *testing.T) { + var resp struct { + Fallback string + } + c.MustPost(`query { fallback(arg: A) }`, &resp) + require.Equal(t, "A", resp.Fallback) + }) +} diff --git a/codegen/testserver/useptr.graphql b/codegen/testserver/useptr.graphql new file mode 100644 index 0000000000..23c1af0b42 --- /dev/null +++ b/codegen/testserver/useptr.graphql @@ -0,0 +1,13 @@ +type A { + id: ID! +} + +type B { + id: ID! +} + +union TestUnion = A | B + +extend type Query { + optionalUnion: TestUnion +} diff --git a/codegen/testserver/useptr_test.go b/codegen/testserver/useptr_test.go new file mode 100644 index 0000000000..ba088f49dc --- /dev/null +++ b/codegen/testserver/useptr_test.go @@ -0,0 +1,14 @@ +package testserver + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestUserPtr(t *testing.T) { + s := &Stub{} + r := reflect.TypeOf(s.QueryResolver.OptionalUnion) + require.True(t, r.Out(0).Kind() == reflect.Interface) +} diff --git a/codegen/testserver/validtypes.graphql b/codegen/testserver/validtypes.graphql new file mode 100644 index 0000000000..f344a9f2de --- /dev/null +++ b/codegen/testserver/validtypes.graphql @@ -0,0 +1,68 @@ +extend type Query { + validType: ValidType +} + +""" These things are all valid, but without care generate invalid go code """ +type ValidType { + differentCase: String! + different_case: String! + validInputKeywords(input: ValidInput): Boolean! + validArgs( + break: String!, + default: String!, + func: String!, + interface: String!, + select: String!, + case: String!, + defer: String!, + go: String!, + map: String!, + struct: String!, + chan: String!, + else: String!, + goto: String!, + package: String!, + switch: String!, + const: String!, + fallthrough: String!, + if: String!, + range: String!, + type: String!, + continue: String!, + for: String!, + import: String!, + return: String!, + var: String!, + _: String!, + ): Boolean! +} + +input ValidInput { + break: String! + default: String! + func: String! + interface: String! + select: String! + case: String! + defer: String! + go: String! + map: String! + struct: String! + chan: String! + else: String! + goto: String! + package: String! + switch: String! + const: String! + fallthrough: String! + if: String! + range: String! + type: String! + continue: String! + for: String! + import: String! + return: String! + var: String! + _: String! +} + diff --git a/codegen/testserver/validtypes_test.go b/codegen/testserver/validtypes_test.go new file mode 100644 index 0000000000..7c6df2fafe --- /dev/null +++ b/codegen/testserver/validtypes_test.go @@ -0,0 +1,38 @@ +package testserver + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/handler" + "github.com/stretchr/testify/require" +) + +func TestValidType(t *testing.T) { + resolvers := &Stub{} + resolvers.QueryResolver.ValidType = func(ctx context.Context) (validType *ValidType, e error) { + return &ValidType{ + DifferentCase: "new", + DifferentCaseOld: "old", + }, nil + } + + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) + c := client.New(srv.URL) + + t.Run("fields with differing cases can be distinguished", func(t *testing.T) { + var resp struct { + ValidType struct { + New string `json:"differentCase"` + Old string `json:"different_case"` + } + } + err := c.Post(`query { validType { differentCase, different_case } }`, &resp) + require.NoError(t, err) + + require.Equal(t, "new", resp.ValidType.New) + require.Equal(t, "old", resp.ValidType.Old) + }) +} diff --git a/codegen/testserver/weird_type_cases.graphql b/codegen/testserver/weird_type_cases.graphql new file mode 100644 index 0000000000..afd440f1d1 --- /dev/null +++ b/codegen/testserver/weird_type_cases.graphql @@ -0,0 +1,8 @@ +# regression test for https://github.com/99designs/gqlgen/issues/583 + +type asdfIt { id: ID! } +type iIt { id: ID! } +type AIt { id: ID! } +type XXIt { id: ID! } +type AbIt { id: ID! } +type XxIt { id: ID! } diff --git a/codegen/type.go b/codegen/type.go index 04d9bb2fde..e008373236 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -1,174 +1,18 @@ package codegen import ( - "strconv" - "strings" - - "github.com/99designs/gqlgen/codegen/templates" - - "github.com/vektah/gqlparser/ast" -) - -type NamedTypes map[string]*NamedType - -type NamedType struct { - Ref - IsScalar bool - IsInterface bool - IsInput bool - GQLType string // Name of the graphql type - Marshaler *Ref // If this type has an external marshaler this will be set -} - -type Ref struct { - GoType string // Name of the go type - Package string // the package the go type lives in - IsUserDefined bool // does the type exist in the typemap -} - -type Type struct { - *NamedType - - Modifiers []string - ASTType *ast.Type - AliasedType *Ref -} - -const ( - modList = "[]" - modPtr = "*" + "github.com/99designs/gqlgen/codegen/config" ) -func (t Ref) FullName() string { - return t.PkgDot() + t.GoType -} - -func (t Ref) PkgDot() string { - name := templates.CurrentImports.Lookup(t.Package) - if name == "" { - return "" - - } - - return name + "." -} - -func (t Type) Signature() string { - if t.AliasedType != nil { - return strings.Join(t.Modifiers, "") + t.AliasedType.FullName() - } - return strings.Join(t.Modifiers, "") + t.FullName() -} - -func (t Type) FullSignature() string { - pkg := "" - if t.Package != "" { - pkg = t.Package + "." - } - - return strings.Join(t.Modifiers, "") + pkg + t.GoType -} +func (b *builder) buildTypes() (map[string]*config.TypeReference, error) { + ret := map[string]*config.TypeReference{} -func (t Type) IsPtr() bool { - return len(t.Modifiers) > 0 && t.Modifiers[0] == modPtr -} + for _, ref := range b.Binder.References { + for ref != nil { + ret[ref.UniquenessKey()] = ref -func (t *Type) StripPtr() { - if !t.IsPtr() { - return + ref = ref.Elem() + } } - t.Modifiers = t.Modifiers[0 : len(t.Modifiers)-1] -} - -func (t Type) IsSlice() bool { - return len(t.Modifiers) > 0 && t.Modifiers[0] == modList || - len(t.Modifiers) > 1 && t.Modifiers[0] == modPtr && t.Modifiers[1] == modList -} - -func (t NamedType) IsMarshaled() bool { - return t.Marshaler != nil -} - -func (t Type) Unmarshal(result, raw string) string { - return t.unmarshal(result, raw, t.Modifiers, 1) -} - -func (t Type) unmarshal(result, raw string, remainingMods []string, depth int) string { - switch { - case len(remainingMods) > 0 && remainingMods[0] == modPtr: - ptr := "ptr" + strconv.Itoa(depth) - return tpl(`var {{.ptr}} {{.mods}}{{.t.FullName}} - if {{.raw}} != nil { - {{.next}} - {{.result}} = &{{.ptr -}} - } - `, map[string]interface{}{ - "ptr": ptr, - "t": t, - "raw": raw, - "result": result, - "mods": strings.Join(remainingMods[1:], ""), - "next": t.unmarshal(ptr, raw, remainingMods[1:], depth+1), - }) - - case len(remainingMods) > 0 && remainingMods[0] == modList: - var rawIf = "rawIf" + strconv.Itoa(depth) - var index = "idx" + strconv.Itoa(depth) - - return tpl(`var {{.rawSlice}} []interface{} - if {{.raw}} != nil { - if tmp1, ok := {{.raw}}.([]interface{}); ok { - {{.rawSlice}} = tmp1 - } else { - {{.rawSlice}} = []interface{}{ {{.raw}} } - } - } - {{.result}} = make({{.type}}, len({{.rawSlice}})) - for {{.index}} := range {{.rawSlice}} { - {{ .next -}} - }`, map[string]interface{}{ - "raw": raw, - "rawSlice": rawIf, - "index": index, - "result": result, - "type": strings.Join(remainingMods, "") + t.NamedType.FullName(), - "next": t.unmarshal(result+"["+index+"]", rawIf+"["+index+"]", remainingMods[1:], depth+1), - }) - } - - realResult := result - if t.AliasedType != nil { - result = "castTmp" - } - - return tpl(`{{- if .t.AliasedType }} - var castTmp {{.t.FullName}} - {{ end }} - {{- if eq .t.GoType "map[string]interface{}" }} - {{- .result }} = {{.raw}}.(map[string]interface{}) - {{- else if .t.Marshaler }} - {{- .result }}, err = {{ .t.Marshaler.PkgDot }}Unmarshal{{.t.Marshaler.GoType}}({{.raw}}) - {{- else -}} - err = (&{{.result}}).UnmarshalGQL({{.raw}}) - {{- end }} - {{- if .t.AliasedType }} - {{ .realResult }} = {{.t.AliasedType.FullName}}(castTmp) - {{- end }}`, map[string]interface{}{ - "realResult": realResult, - "result": result, - "raw": raw, - "t": t, - }) -} - -func (t Type) Marshal(val string) string { - if t.AliasedType != nil { - val = t.GoType + "(" + val + ")" - } - - if t.Marshaler != nil { - return "return " + t.Marshaler.PkgDot() + "Marshal" + t.Marshaler.GoType + "(" + val + ")" - } - - return "return " + val + return ret, nil } diff --git a/codegen/type.gotpl b/codegen/type.gotpl new file mode 100644 index 0000000000..f727baaca3 --- /dev/null +++ b/codegen/type.gotpl @@ -0,0 +1,131 @@ +{{- range $type := .ReferencedTypes }} + {{ with $type.UnmarshalFunc }} + func (ec *executionContext) {{ . }}(ctx context.Context, v interface{}) ({{ $type.GO | ref }}, error) { + {{- if $type.IsNilable }} + if v == nil { return nil, nil } + {{- end }} + {{- if $type.IsPtr }} + res, err := ec.{{ $type.Elem.UnmarshalFunc }}(ctx, v) + return &res, err + {{- else if $type.IsSlice }} + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{ v } + } + } + var err error + res := make([]{{$type.GO.Elem | ref}}, len(vSlice)) + for i := range vSlice { + res[i], err = ec.{{ $type.Elem.UnmarshalFunc }}(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil + {{- else }} + {{- if $type.Unmarshaler }} + {{- if $type.CastType }} + tmp, err := {{ $type.Unmarshaler | call }}(v) + return {{ $type.GO | ref }}(tmp), err + {{- else}} + return {{ $type.Unmarshaler | call }}(v) + {{- end }} + {{- else if eq ($type.GO | ref) "map[string]interface{}" }} + return v.(map[string]interface{}), nil + {{- else if $type.IsMarshaler -}} + var res {{ $type.GO | ref }} + return res, res.UnmarshalGQL(v) + {{- else }} + return ec.unmarshalInput{{ $type.GQL.Name }}(ctx, v) + {{- end }} + {{- end }} + } + {{- end }} + + {{ with $type.MarshalFunc }} + func (ec *executionContext) {{ . }}(ctx context.Context, sel ast.SelectionSet, v {{ $type.GO | ref }}) graphql.Marshaler { + {{- if $type.IsNilable }} + if v == nil { + {{- if $type.GQL.NonNull }} + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + {{- end }} + return graphql.Null + } + {{- else if $type.HasIsZero }} + if v.IsZero() { + {{- if $type.GQL.NonNull }} + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + {{- end }} + return graphql.Null + } + {{- end }} + + {{- if $type.IsSlice }} + {{- if not $type.GQL.NonNull }} + if v == nil { + return graphql.Null + } + {{- end }} + ret := make(graphql.Array, len(v)) + {{- if not $type.IsScalar }} + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + {{- end }} + for i := range v { + {{- if not $type.IsScalar }} + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + {{ else }} + ret[i] = ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, v[i]) + {{- end}} + } + {{ if not $type.IsScalar }} wg.Wait() {{ end }} + return ret + {{- else }} + + {{- if $type.IsMarshaler }} + return v + {{- else if $type.Marshaler }} + {{- if $type.IsPtr }} + return ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, *v) + {{- else }} + return {{ $type.Marshaler | call }}({{- if $type.CastType }}{{ $type.CastType | ref }}(v){{else}}v{{- end }}) + {{- end }} + {{- else }} + return ec._{{$type.Definition.Name}}(ctx, sel, {{ if not $type.IsNilable}}&{{end}} v) + {{- end }} + {{- end }} + } + {{- end }} +{{- end }} diff --git a/codegen/type_build.go b/codegen/type_build.go deleted file mode 100644 index 586b0db238..0000000000 --- a/codegen/type_build.go +++ /dev/null @@ -1,100 +0,0 @@ -package codegen - -import ( - "go/types" - "strings" - - "github.com/vektah/gqlparser/ast" - "golang.org/x/tools/go/loader" -) - -// namedTypeFromSchema objects for every graphql type, including scalars. There should only be one instance of Type for each thing -func (cfg *Config) buildNamedTypes() NamedTypes { - types := map[string]*NamedType{} - for _, schemaType := range cfg.schema.Types { - t := namedTypeFromSchema(schemaType) - - if userEntry, ok := cfg.Models[t.GQLType]; ok && userEntry.Model != "" { - t.IsUserDefined = true - t.Package, t.GoType = pkgAndType(userEntry.Model) - } else if t.IsScalar { - t.Package = "github.com/99designs/gqlgen/graphql" - t.GoType = "String" - } - - types[t.GQLType] = t - } - return types -} - -func (cfg *Config) bindTypes(namedTypes NamedTypes, destDir string, prog *loader.Program) { - for _, t := range namedTypes { - if t.Package == "" { - continue - } - - def, _ := findGoType(prog, t.Package, "Marshal"+t.GoType) - switch def := def.(type) { - case *types.Func: - sig := def.Type().(*types.Signature) - cpy := t.Ref - t.Marshaler = &cpy - - t.Package, t.GoType = pkgAndType(sig.Params().At(0).Type().String()) - } - } -} - -// namedTypeFromSchema objects for every graphql type, including primitives. -// don't recurse into object fields or interfaces yet, lets make sure we have collected everything first. -func namedTypeFromSchema(schemaType *ast.Definition) *NamedType { - switch schemaType.Kind { - case ast.Scalar, ast.Enum: - return &NamedType{GQLType: schemaType.Name, IsScalar: true} - case ast.Interface, ast.Union: - return &NamedType{GQLType: schemaType.Name, IsInterface: true} - case ast.InputObject: - return &NamedType{GQLType: schemaType.Name, IsInput: true} - default: - return &NamedType{GQLType: schemaType.Name} - } -} - -// take a string in the form github.com/package/blah.Type and split it into package and type -func pkgAndType(name string) (string, string) { - parts := strings.Split(name, ".") - if len(parts) == 1 { - return "", name - } - - return normalizeVendor(strings.Join(parts[:len(parts)-1], ".")), parts[len(parts)-1] -} - -func (n NamedTypes) getType(t *ast.Type) *Type { - orig := t - var modifiers []string - for { - if t.Elem != nil { - modifiers = append(modifiers, modList) - t = t.Elem - } else { - if !t.NonNull { - modifiers = append(modifiers, modPtr) - } - if n[t.NamedType] == nil { - panic("missing type " + t.NamedType) - } - res := &Type{ - NamedType: n[t.NamedType], - Modifiers: modifiers, - ASTType: orig, - } - - if res.IsInterface { - res.StripPtr() - } - - return res - } - } -} diff --git a/codegen/util.go b/codegen/util.go index cc6246fdb7..59dfde08cd 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -1,65 +1,30 @@ package codegen import ( - "fmt" "go/types" - "reflect" - "regexp" "strings" "github.com/pkg/errors" - "golang.org/x/tools/go/loader" ) -func findGoType(prog *loader.Program, pkgName string, typeName string) (types.Object, error) { - if pkgName == "" { - return nil, nil - } - fullName := typeName - if pkgName != "" { - fullName = pkgName + "." + typeName - } - - pkgName, err := resolvePkg(pkgName) - if err != nil { - return nil, errors.Errorf("unable to resolve package for %s: %s\n", fullName, err.Error()) - } - - pkg := prog.Imported[pkgName] - if pkg == nil { - return nil, errors.Errorf("required package was not loaded: %s", fullName) - } - - for astNode, def := range pkg.Defs { - if astNode.Name != typeName || def.Parent() == nil || def.Parent() != pkg.Pkg.Scope() { - continue - } - - return def, nil - } - - return nil, errors.Errorf("unable to find type %s\n", fullName) -} - -func findGoNamedType(prog *loader.Program, pkgName string, typeName string) (*types.Named, error) { - def, err := findGoType(prog, pkgName, typeName) - if err != nil { - return nil, err - } +func findGoNamedType(def types.Type) (*types.Named, error) { if def == nil { return nil, nil } - namedType, ok := def.Type().(*types.Named) + namedType, ok := def.(*types.Named) if !ok { - return nil, errors.Errorf("expected %s to be a named type, instead found %T\n", typeName, def.Type()) + return nil, errors.Errorf("expected %s to be a named type, instead found %T\n", def.String(), def) } return namedType, nil } -func findGoInterface(prog *loader.Program, pkgName string, typeName string) (*types.Interface, error) { - namedType, err := findGoNamedType(prog, pkgName, typeName) +func findGoInterface(def types.Type) (*types.Interface, error) { + if def == nil { + return nil, nil + } + namedType, err := findGoNamedType(def) if err != nil { return nil, err } @@ -69,319 +34,14 @@ func findGoInterface(prog *loader.Program, pkgName string, typeName string) (*ty underlying, ok := namedType.Underlying().(*types.Interface) if !ok { - return nil, errors.Errorf("expected %s to be a named interface, instead found %s", typeName, namedType.String()) + return nil, errors.Errorf("expected %s to be a named interface, instead found %s", def.String(), namedType.String()) } return underlying, nil } -func findMethod(typ *types.Named, name string) *types.Func { - for i := 0; i < typ.NumMethods(); i++ { - method := typ.Method(i) - if !method.Exported() { - continue - } - - if strings.EqualFold(method.Name(), name) { - return method - } - } - - if s, ok := typ.Underlying().(*types.Struct); ok { - for i := 0; i < s.NumFields(); i++ { - field := s.Field(i) - if !field.Anonymous() { - continue - } - - if named, ok := field.Type().(*types.Named); ok { - if f := findMethod(named, name); f != nil { - return f - } - } - } - } - - return nil -} - func equalFieldName(source, target string) bool { source = strings.Replace(source, "_", "", -1) target = strings.Replace(target, "_", "", -1) return strings.EqualFold(source, target) } - -// findField attempts to match the name to a struct field with the following -// priorites: -// 1. If struct tag is passed then struct tag has highest priority -// 2. Field in an embedded struct -// 3. Actual Field name -func findField(typ *types.Struct, name, structTag string) (*types.Var, error) { - var foundField *types.Var - foundFieldWasTag := false - - for i := 0; i < typ.NumFields(); i++ { - field := typ.Field(i) - - if structTag != "" { - tags := reflect.StructTag(typ.Tag(i)) - if val, ok := tags.Lookup(structTag); ok { - if equalFieldName(val, name) { - if foundField != nil && foundFieldWasTag { - return nil, errors.Errorf("tag %s is ambigious; multiple fields have the same tag value of %s", structTag, val) - } - - foundField = field - foundFieldWasTag = true - } - } - } - - if field.Anonymous() { - - fieldType := field.Type() - - if ptr, ok := fieldType.(*types.Pointer); ok { - fieldType = ptr.Elem() - } - - // Type.Underlying() returns itself for all types except types.Named, where it returns a struct type. - // It should be safe to always call. - if named, ok := fieldType.Underlying().(*types.Struct); ok { - f, err := findField(named, name, structTag) - if err != nil && !strings.HasPrefix(err.Error(), "no field named") { - return nil, err - } - if f != nil && foundField == nil { - foundField = f - } - } - } - - if !field.Exported() { - continue - } - - if equalFieldName(field.Name(), name) && foundField == nil { // aqui! - foundField = field - } - } - - if foundField == nil { - return nil, fmt.Errorf("no field named %s", name) - } - - return foundField, nil -} - -type BindError struct { - object *Object - field *Field - typ types.Type - methodErr error - varErr error -} - -func (b BindError) Error() string { - return fmt.Sprintf( - "Unable to bind %s.%s to %s\n %s\n %s", - b.object.GQLType, - b.field.GQLName, - b.typ.String(), - b.methodErr.Error(), - b.varErr.Error(), - ) -} - -type BindErrors []BindError - -func (b BindErrors) Error() string { - var errs []string - for _, err := range b { - errs = append(errs, err.Error()) - } - return strings.Join(errs, "\n\n") -} - -func bindObject(t types.Type, object *Object, structTag string) BindErrors { - var errs BindErrors - for i := range object.Fields { - field := &object.Fields[i] - - if field.ForceResolver { - continue - } - - // first try binding to a method - methodErr := bindMethod(t, field) - if methodErr == nil { - continue - } - - // otherwise try binding to a var - varErr := bindVar(t, field, structTag) - - if varErr != nil { - errs = append(errs, BindError{ - object: object, - typ: t, - field: field, - varErr: varErr, - methodErr: methodErr, - }) - } - } - return errs -} - -func bindMethod(t types.Type, field *Field) error { - namedType, ok := t.(*types.Named) - if !ok { - return fmt.Errorf("not a named type") - } - - goName := field.GQLName - if field.GoFieldName != "" { - goName = field.GoFieldName - } - method := findMethod(namedType, goName) - if method == nil { - return fmt.Errorf("no method named %s", field.GQLName) - } - sig := method.Type().(*types.Signature) - - if sig.Results().Len() == 1 { - field.NoErr = true - } else if sig.Results().Len() != 2 { - return fmt.Errorf("method has wrong number of args") - } - params := sig.Params() - // If the first argument is the context, remove it from the comparison and set - // the MethodHasContext flag so that the context will be passed to this model's method - if params.Len() > 0 && params.At(0).Type().String() == "context.Context" { - field.MethodHasContext = true - vars := make([]*types.Var, params.Len()-1) - for i := 1; i < params.Len(); i++ { - vars[i-1] = params.At(i) - } - params = types.NewTuple(vars...) - } - - newArgs, err := matchArgs(field, params) - if err != nil { - return err - } - - result := sig.Results().At(0) - if err := validateTypeBinding(field, result.Type()); err != nil { - return errors.Wrap(err, "method has wrong return type") - } - - // success, args and return type match. Bind to method - field.GoFieldType = GoFieldMethod - field.GoReceiverName = "obj" - field.GoFieldName = method.Name() - field.Args = newArgs - return nil -} - -func bindVar(t types.Type, field *Field, structTag string) error { - underlying, ok := t.Underlying().(*types.Struct) - if !ok { - return fmt.Errorf("not a struct") - } - - goName := field.GQLName - if field.GoFieldName != "" { - goName = field.GoFieldName - } - structField, err := findField(underlying, goName, structTag) - if err != nil { - return err - } - - if err := validateTypeBinding(field, structField.Type()); err != nil { - return errors.Wrap(err, "field has wrong type") - } - - // success, bind to var - field.GoFieldType = GoFieldVariable - field.GoReceiverName = "obj" - field.GoFieldName = structField.Name() - return nil -} - -func matchArgs(field *Field, params *types.Tuple) ([]FieldArgument, error) { - var newArgs []FieldArgument - -nextArg: - for j := 0; j < params.Len(); j++ { - param := params.At(j) - for _, oldArg := range field.Args { - if strings.EqualFold(oldArg.GQLName, param.Name()) { - if !field.ForceResolver { - oldArg.Type.Modifiers = modifiersFromGoType(param.Type()) - } - newArgs = append(newArgs, oldArg) - continue nextArg - } - } - - // no matching arg found, abort - return nil, fmt.Errorf("arg %s not found on method", param.Name()) - } - return newArgs, nil -} - -func validateTypeBinding(field *Field, goType types.Type) error { - gqlType := normalizeVendor(field.Type.FullSignature()) - goTypeStr := normalizeVendor(goType.String()) - - if equalTypes(goTypeStr, gqlType) { - field.Type.Modifiers = modifiersFromGoType(goType) - return nil - } - - // deal with type aliases - underlyingStr := normalizeVendor(goType.Underlying().String()) - if equalTypes(underlyingStr, gqlType) { - field.Type.Modifiers = modifiersFromGoType(goType) - pkg, typ := pkgAndType(goType.String()) - field.AliasedType = &Ref{GoType: typ, Package: pkg} - return nil - } - - return fmt.Errorf("%s is not compatible with %s", gqlType, goTypeStr) -} - -func modifiersFromGoType(t types.Type) []string { - var modifiers []string - for { - switch val := t.(type) { - case *types.Pointer: - modifiers = append(modifiers, modPtr) - t = val.Elem() - case *types.Array: - modifiers = append(modifiers, modList) - t = val.Elem() - case *types.Slice: - modifiers = append(modifiers, modList) - t = val.Elem() - default: - return modifiers - } - } -} - -var modsRegex = regexp.MustCompile(`^(\*|\[\])*`) - -func normalizeVendor(pkg string) string { - modifiers := modsRegex.FindAllString(pkg, 1)[0] - pkg = strings.TrimPrefix(pkg, modifiers) - parts := strings.Split(pkg, "/vendor/") - return modifiers + parts[len(parts)-1] -} - -func equalTypes(goType string, gqlType string) bool { - return goType == gqlType || "*"+goType == gqlType || goType == "*"+gqlType || strings.Replace(goType, "[]*", "[]", -1) == gqlType -} diff --git a/docs/content/_introduction.md b/docs/content/_introduction.md new file mode 120000 index 0000000000..fe84005413 --- /dev/null +++ b/docs/content/_introduction.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/docs/content/config.md b/docs/content/config.md index bf219bb89f..98cb7127e8 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -3,7 +3,7 @@ linkTitle: Configuration title: How to configure gqlgen using gqlgen.yml description: How to configure gqlgen using gqlgen.yml menu: main -weight: -7 +weight: -5 --- gqlgen can be configured using a `gqlgen.yml` file, by default it will be loaded from the current directory, or any parent directory. @@ -50,7 +50,14 @@ models: fields: id: resolver: true # force a resolver to be generated - fieldName: todoId # bind to a different go field name + fieldName: todoId # bind to a different go field name + # model also accepts multiple backing go types. When mapping onto structs + # any of these types can be used, the first one is used as the default for + # resolver args. + ID: + model: + - github.com/99designs/gqlgen/graphql.IntID + - github.com/99designs/gqlgen/graphql.ID ``` Everything has defaults, so add things as you need. diff --git a/docs/content/feature-comparison.md b/docs/content/feature-comparison.md new file mode 100644 index 0000000000..9c1bec69d0 --- /dev/null +++ b/docs/content/feature-comparison.md @@ -0,0 +1,29 @@ +--- +linkTitle: Feature Comparison +title: Comparing Features of Other Go GraphQL Implementations +description: Comparing Features of Other Go GraphQL Implementations +menu: main +weight: -1 +--- + +| | [gqlgen](https://github.com/99designs/gqlgen) | [gophers](https://github.com/graph-gophers/graphql-go) | [graphql-go](https://github.com/graphql-go/graphql) | [thunder](https://github.com/samsarahq/thunder) | +| --------: | :-------- | :-------- | :-------- | :-------- | +| Kind | schema first | schema first | run time types | struct first | +| Boilerplate | less | more | more | some | +| Docs | [docs](https://gqlgen.com) & [examples](https://github.com/99designs/gqlgen/tree/master/example) | [examples](https://github.com/graph-gophers/graphql-go/tree/master/example/starwars) | [examples](https://github.com/graphql-go/graphql/tree/master/examples) | [examples](https://github.com/samsarahq/thunder/tree/master/example)| +| Query | 👍 | 👍 | 👍 | 👍 | +| Mutation | 👍 | 🚧 [pr](https://github.com/graph-gophers/graphql-go/pull/182) | 👍 | 👍 | +| Subscription | 👍 | 🚧 [pr](https://github.com/graph-gophers/graphql-go/pull/182) | 👍 | 👍 | +| Type Safety | 👍 | 👍 | ⛔️ | 👍 | +| Type Binding | 👍 | 🚧 [pr](https://github.com/graph-gophers/graphql-go/pull/194) | ⛔️ | 👍 | +| Embedding | 👍 | ⛔️ | 🚧 [pr](https://github.com/graphql-go/graphql/pull/371) | ⛔️ | +| Interfaces | 👍 | 👍 | 👍 | ⛔️ [is](https://github.com/samsarahq/thunder/issues/78) | +| Generated Enums | 👍 | ⛔️ | ⛔️ | ⛔️ | +| Generated Inputs | 👍 | ⛔️ | ⛔️ | ⛔️ | +| Stitching gql | 🕐 [is](https://github.com/99designs/gqlgen/issues/5) | ⛔️ | ⛔️ | ⛔️ | +| Opentracing | 👍 | 👍 | ⛔️ | ✂️[pr](https://github.com/samsarahq/thunder/pull/77) | +| Hooks for error logging | 👍 | ⛔️ | ⛔️ | ⛔️ | +| Dataloading | 👍 | 👍 | 👍 | ⚠️ | +| Concurrency | 👍 | 👍 | 👍 | 👍 | +| Custom errors & error.path | 👍 | ⛔️ [is](https://github.com/graphql-go/graphql/issues/259) | ⛔️ | ⛔️ | +| Query complexity | 👍 | ⛔️ [is](https://github.com/graphql-go/graphql/issues/231) | ⛔️ | ⛔️ | diff --git a/docs/content/getting-started-dep.md b/docs/content/getting-started-dep.md new file mode 100644 index 0000000000..93c8410c37 --- /dev/null +++ b/docs/content/getting-started-dep.md @@ -0,0 +1,290 @@ +--- +linkTitle: Getting Started Using dep +title: Building GraphQL servers in golang +description: Get started building type-safe GraphQL servers in Golang using gqlgen +weight: -7 +hidden: true +--- + +> Deprecated +> +> This tutorial uses the `dep` tool to manage dependencies instead of Go Modules and should be considered a deprecated way to use gqlgen. Read out new [Getting Started]({{< ref "getting-started.md" >}}) guide for instructions for using Go Modules. + +This tutorial will take you through the process of building a GraphQL server with gqlgen that can: + + - Return a list of todos + - Create new todos + - Mark off todos as they are completed + +You can find the finished code for this tutorial [here](https://github.com/vektah/gqlgen-tutorials/tree/master/gettingstarted) + +## Install gqlgen + +This article uses [`dep`](https://github.com/golang/dep) to install gqlgen. [Follow the instructions for your environment](https://github.com/golang/dep) to install. + +Assuming you already have a working [Go environment](https://golang.org/doc/install), create a directory for the project in your `$GOPATH`: + +```sh +$ mkdir -p $GOPATH/src/github.com/[username]/gqlgen-todos +``` + +Add the following file to your project under `scripts/gqlgen.go`: + +```go +// +build ignore + +package main + +import "github.com/99designs/gqlgen/cmd" + +func main() { + cmd.Execute() +} +``` + +Lastly, initialise dep. This will inspect any imports you have in your project, and pull down the latest tagged release. + +```sh +$ dep init +``` + +## Building the server + +### Define the schema + +gqlgen is a schema-first library — before writing code, you describe your API using the GraphQL +[Schema Definition Language](http://graphql.org/learn/schema/). This usually goes into a file called `schema.graphql`: + +```graphql +type Todo { + id: ID! + text: String! + done: Boolean! + user: User! +} + +type User { + id: ID! + name: String! +} + +type Query { + todos: [Todo!]! +} + +input NewTodo { + text: String! + userId: String! +} + +type Mutation { + createTodo(input: NewTodo!): Todo! +} +``` + +### Create the project skeleton + +```bash +$ go run scripts/gqlgen.go init +``` + +This has created an empty skeleton with all files you need: + + - `gqlgen.yml` — The gqlgen config file, knobs for controlling the generated code. + - `generated.go` — The GraphQL execution runtime, the bulk of the generated code. + - `models_gen.go` — Generated models required to build the graph. Often you will override these with your own models. Still very useful for input types. + - `resolver.go` — This is where your application code lives. `generated.go` will call into this to get the data the user has requested. + - `server/server.go` — This is a minimal entry point that sets up an `http.Handler` to the generated GraphQL server. + + Now run dep ensure, so that we can ensure that the newly generated code's dependencies are all present: + + ```sh + $ dep ensure + ``` + +### Create the database models + +The generated model for Todo isn't right, it has a user embeded in it but we only want to fetch it if the user actually requested it. So instead lets make a new model in `todo.go`: + +```go +package gettingstarted + +type Todo struct { + ID string + Text string + Done bool + UserID string +} +``` + +Next tell gqlgen to use this new struct by adding it to `gqlgen.yml`: + +```yaml +models: + Todo: + model: github.com/[username]/gqlgen-todos/gettingstarted.Todo +``` + +Regenerate by running: + +```bash +$ go run scripts/gqlgen.go -v +Unable to bind Todo.user to github.com/[username]/gqlgen-todos/gettingstarted.Todo + no method named user + no field named user + Adding resolver method +``` + +> Note +> +> The verbose flag `-v` is here to show what gqlgen is doing. It has looked at all the fields on the model and found matching methods for all of them, except user. For user it has added a resolver to the interface you need to implement. *This is the magic that makes gqlgen work so well!* + +### Implement the resolvers + +The generated runtime has defined an interface for all the missing resolvers that we need to provide. Lets take a look in `generated.go` + +```go +// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { + return &executableSchema{ + resolvers: cfg.Resolvers, + directives: cfg.Directives, + } +} + +type Config struct { + Resolvers ResolverRoot + Directives DirectiveRoot +} + +type ResolverRoot interface { + Mutation() MutationResolver + Query() QueryResolver + Todo() TodoResolver +} + +type DirectiveRoot struct { +} +type MutationResolver interface { + CreateTodo(ctx context.Context, input NewTodo) (Todo, error) +} +type QueryResolver interface { + Todos(ctx context.Context) ([]Todo, error) +} +type TodoResolver interface { + User(ctx context.Context, obj *Todo) (User, error) +} +``` + +Notice the `TodoResolver.User` method? Thats gqlgen saying "I dont know how to get a User from a Todo, you tell me.". +Its worked out how to build everything else for us. + +For any missing models (like NewTodo) gqlgen will generate a go struct. This is usually only used for input types and +one-off return values. Most of the time your types will be coming from the database, or an API client so binding is +better than generating. + +### Write the resolvers + +This is a work in progress, we have a way to generate resolver stubs, but it cannot currently update existing code. We can force it to run again by deleting `resolver.go` and re-running gqlgen: + +```bash +$ rm resolver.go +$ go run scripts/gqlgen.go +``` + +Now we just need to fill in the `not implemented` parts. Update `resolver.go` + +```go +package gettingstarted + +import ( + context "context" + "fmt" + "math/rand" +) + +type Resolver struct { + todos []Todo +} + +func (r *Resolver) Mutation() MutationResolver { + return &mutationResolver{r} +} +func (r *Resolver) Query() QueryResolver { + return &queryResolver{r} +} +func (r *Resolver) Todo() TodoResolver { + return &todoResolver{r} +} + +type mutationResolver struct{ *Resolver } + +func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (*Todo, error) { + todo := &Todo{ + Text: input.Text, + ID: fmt.Sprintf("T%d", rand.Int()), + UserID: input.UserID, + } + r.todos = append(r.todos, *todo) + return todo, nil +} + +type queryResolver struct{ *Resolver } + +func (r *queryResolver) Todos(ctx context.Context) ([]Todo, error) { + return r.todos, nil +} + +type todoResolver struct{ *Resolver } + +func (r *todoResolver) User(ctx context.Context, obj *Todo) (*User, error) { + return &User{ID: obj.UserID, Name: "user " + obj.UserID}, nil +} + +``` + +We now have a working server, to start it: +```bash +go run server/server.go +``` + +then open http://localhost:8080 in a browser. here are some queries to try: +```graphql +mutation createTodo { + createTodo(input:{text:"todo", userId:"1"}) { + user { + id + } + text + done + } +} + +query findTodos { + todos { + text + done + user { + name + } + } +} +``` + +## Finishing touches + +At the top of our `resolver.go` add the following line: + +```go +//go:generate go run scripts/gqlgen.go -v +``` + +This magic comment tells `go generate` what command to run when we want to regenerate our code. To run go generate recursively over your entire project, use this command: + +```go +go generate ./... +``` + +> Note +> +> Ensure that the path to your `gqlgen` binary is relative to the file the generate command is added to. diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index 9ea218afc2..37d0913e13 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -3,7 +3,7 @@ linkTitle: Getting Started title: Building GraphQL servers in golang description: Get started building type-safe GraphQL servers in Golang using gqlgen menu: main -weight: -5 +weight: -7 --- This tutorial will take you through the process of building a GraphQL server with gqlgen that can: @@ -14,38 +14,18 @@ This tutorial will take you through the process of building a GraphQL server wit You can find the finished code for this tutorial [here](https://github.com/vektah/gqlgen-tutorials/tree/master/gettingstarted) -## Install gqlgen - -This article uses [`dep`](https://github.com/golang/dep) to install gqlgen. [Follow the instructions for your environment](https://github.com/golang/dep) to install. - -Assuming you already have a working [Go environment](https://golang.org/doc/install), create a directory for the project in your `$GOPATH`: - -```sh -$ mkdir -p $GOPATH/src/github.com/[username]/gqlgen-todos -``` - -> Go Modules +> Note > -> Currently `gqlgen` does not support Go Modules. This is due to the [`loader`](https://godoc.org/golang.org/x/tools/go/loader) package, that also does not yet support Go Modules. We are looking at solutions to this and the issue is tracked in Github. - -Add the following file to your project under `scripts/gqlgen.go`: - -```go -// +build ignore - -package main +> This tutorial uses Go Modules and requires Go 1.11+. If you want to use this tutorial without Go Modules, take a look at our [Getting Started Using dep]({{< ref "getting-started-dep.md" >}}) guide instead. -import "github.com/99designs/gqlgen/cmd" +## Setup Project -func main() { - cmd.Execute() -} -``` - -Lastly, initialise dep. This will inspect any imports you have in your project, and pull down the latest tagged release. +Create a directory for your project, and initialise it as a Go Module: ```sh -$ dep init +$ mkdir gqlgen-todos +$ cd gqlgen-todos +$ go mod init github.com/[username]/gqlgen-todos ``` ## Building the server @@ -85,7 +65,7 @@ type Mutation { ### Create the project skeleton ```bash -$ go run scripts/gqlgen.go init +$ go run github.com/99designs/gqlgen init ``` This has created an empty skeleton with all files you need: @@ -95,19 +75,13 @@ This has created an empty skeleton with all files you need: - `models_gen.go` — Generated models required to build the graph. Often you will override these with your own models. Still very useful for input types. - `resolver.go` — This is where your application code lives. `generated.go` will call into this to get the data the user has requested. - `server/server.go` — This is a minimal entry point that sets up an `http.Handler` to the generated GraphQL server. - - Now run dep ensure, so that we can ensure that the newly generated code's dependencies are all present: - - ```sh - $ dep ensure - ``` ### Create the database models The generated model for Todo isn't right, it has a user embeded in it but we only want to fetch it if the user actually requested it. So instead lets make a new model in `todo.go`: ```go -package gettingstarted +package gqlgen_todos type Todo struct { ID string @@ -122,17 +96,13 @@ Next tell gqlgen to use this new struct by adding it to `gqlgen.yml`: ```yaml models: Todo: - model: github.com/[username]/gqlgen-todos/gettingstarted.Todo + model: github.com/[username]/gqlgen-todos.Todo ``` Regenerate by running: ```bash -$ go run scripts/gqlgen.go -v -Unable to bind Todo.user to github.com/[username]/gqlgen-todos/gettingstarted.Todo - no method named user - no field named user - Adding resolver method +$ go run github.com/99designs/gqlgen ``` > Note @@ -141,20 +111,16 @@ Unable to bind Todo.user to github.com/[username]/gqlgen-todos/gettingstarted.To ### Implement the resolvers -The generated runtime has defined an interface for all the missing resolvers that we need to provide. Lets take a look in `generated.go` +The generated runtime has defined an interface for all the missing resolvers that we need to provide. Lets take a look in `generated.go`: ```go -// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. -func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { - return &executableSchema{ - resolvers: cfg.Resolvers, - directives: cfg.Directives, - } +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema {} + // ... } type Config struct { Resolvers ResolverRoot - Directives DirectiveRoot + // ... } type ResolverRoot interface { @@ -163,23 +129,21 @@ type ResolverRoot interface { Todo() TodoResolver } -type DirectiveRoot struct { -} type MutationResolver interface { - CreateTodo(ctx context.Context, input NewTodo) (Todo, error) + CreateTodo(ctx context.Context, input NewTodo) (*Todo, error) } type QueryResolver interface { Todos(ctx context.Context) ([]Todo, error) } type TodoResolver interface { - User(ctx context.Context, obj *Todo) (User, error) + User(ctx context.Context, obj *Todo) (*User, error) } ``` Notice the `TodoResolver.User` method? Thats gqlgen saying "I dont know how to get a User from a Todo, you tell me.". Its worked out how to build everything else for us. -For any missing models (like NewTodo) gqlgen will generate a go struct. This is usually only used for input types and +For any missing models (like `NewTodo`) gqlgen will generate a go struct. This is usually only used for input types and one-off return values. Most of the time your types will be coming from the database, or an API client so binding is better than generating. @@ -189,15 +153,13 @@ This is a work in progress, we have a way to generate resolver stubs, but it can ```bash $ rm resolver.go -$ go run scripts/gqlgen.go +$ go run github.com/99designs/gqlgen ``` Now we just need to fill in the `not implemented` parts. Update `resolver.go` ```go -//go:generate go run ./scripts/gqlgen.go - -package gettingstarted +package gqlgen_todos import ( context "context" @@ -205,7 +167,7 @@ import ( "math/rand" ) -type Resolver struct{ +type Resolver struct { todos []Todo } @@ -221,13 +183,13 @@ func (r *Resolver) Todo() TodoResolver { type mutationResolver struct{ *Resolver } -func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (Todo, error) { - todo := Todo{ +func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (*Todo, error) { + todo := &Todo{ Text: input.Text, ID: fmt.Sprintf("T%d", rand.Int()), UserID: input.UserID, } - r.todos = append(r.todos, todo) + r.todos = append(r.todos, *todo) return todo, nil } @@ -239,8 +201,8 @@ func (r *queryResolver) Todos(ctx context.Context) ([]Todo, error) { type todoResolver struct{ *Resolver } -func (r *todoResolver) User(ctx context.Context, obj *Todo) (User, error) { - return User{ID: obj.UserID, Name: "user " + obj.UserID}, nil +func (r *todoResolver) User(ctx context.Context, obj *Todo) (*User, error) { + return &User{ID: obj.UserID, Name: "user " + obj.UserID}, nil } ``` @@ -278,7 +240,7 @@ query findTodos { At the top of our `resolver.go` add the following line: ```go -//go:generate go run scripts/gqlgen.go -v +//go:generate go run github.com/99designs/gqlgen ``` This magic comment tells `go generate` what command to run when we want to regenerate our code. To run go generate recursively over your entire project, use this command: @@ -286,7 +248,3 @@ This magic comment tells `go generate` what command to run when we want to regen ```go go generate ./... ``` - -> Note -> -> Ensure that the path to your `gqlgen` binary is relative to the file the generate command is added to. diff --git a/docs/content/introduction.md b/docs/content/introduction.md index 1d98c9b1e1..6ee0d144fa 100644 --- a/docs/content/introduction.md +++ b/docs/content/introduction.md @@ -1,31 +1,6 @@ --- linkTitle: Introduction -title: Type-safe graphql for golang +title: Type-safe GraphQL for Go type: homepage date: 2018-03-17T13:06:47+11:00 --- - -## What is gqlgen? - -[gqlgen](https://github.com/99designs/gqlgen) is a golang library for building graphql servers without any fuss. gqlgen is: - - - Schema first: You define your API using the graphql [Schema Definition Language](http://graphql.org/learn/schema/) - - Type safe: You should never see `map[string]interface{}` here. - - Codegen: Let us generate the boring bits, so you can build your app quickly. - - -## Getting started - -First take a look at the [Getting Started]({{< ref "getting-started.md" >}}) tutorial. - -If you cant find what your looking for, maybe the [examples](https://github.com/99designs/gqlgen/tree/master/example) will help. - - -## Getting help - -If you think you've found a bug, or something isn't behaving the way you think it should please raise an [issue](https://github.com/99designs/gqlgen/issues) on github. - - -## Talks - - - [Christopher Biscardi @ Gophercon UK 2018](https://youtu.be/FdURVezcdcw) diff --git a/docs/content/recipes/gin.md b/docs/content/recipes/gin.md new file mode 100644 index 0000000000..fb4e445689 --- /dev/null +++ b/docs/content/recipes/gin.md @@ -0,0 +1,53 @@ +--- +title: "Using Gin to setup HTTP handlers" +description: Setting up HTTP handlers using Gin, a HTTP web framework written in Go. +linkTitle: Gin +menu: { main: { parent: 'recipes' } } +--- + +Gin is an excellent alternative for the `net/http` router. From their official [GitHub page](https://github.com/gin-gonic/gin): + +> Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin. + +Here are the steps to setup Gin and gqlgen together: + +Install Gin: +```bash +$ go get github.com/gin-gonic/gin +``` + +In your router file, define the handlers for the GraphQL and Playground endpoints in two different methods and tie then together in the Gin router: +```go +import ( + "github.com/99designs/gqlgen/handler" + "github.com/gin-gonic/gin" +) + +// Defining the Graphql handler +func graphqlHandler() gin.HandlerFunc { + // NewExecutableSchema and Config are in the generated.go file + // Resolver is in the resolver.go file + h := handler.GraphQL(NewExecutableSchema(Config{Resolvers: &Resolver{}})) + + return func(c *gin.Context) { + h.ServeHTTP(c.Writer, c.Request) + } +} + +// Defining the Playground handler +func playgroundHandler() gin.HandlerFunc { + h := handler.Playground("GraphQL", "/query") + + return func(c *gin.Context) { + h.ServeHTTP(c.Writer, c.Request) + } +} + +func main() { + // Setting up Gin + r := gin.Default() + r.POST("/query", graphqlHandler()) + r.GET("/", playgroundHandler()) + r.Run() +} +``` diff --git a/docs/content/reference/changesets.md b/docs/content/reference/changesets.md new file mode 100644 index 0000000000..1c7e9b0d9e --- /dev/null +++ b/docs/content/reference/changesets.md @@ -0,0 +1,67 @@ +--- +linkTitle: Changesets +title: Using maps as changesets +description: Falling back to map[string]interface{} to allow for presence checks. +menu: { main: { parent: 'reference' } } +--- + +Occasionally you need to distinguish presence from nil (undefined vs null). In gqlgen we do this using maps: + + +```graphql +type Query { + updateUser(id: ID!, changes: UserChanges!): User +} + +type UserChanges { + name: String + email: String +} +``` + +Then in config set the backing type to `map[string]interface{}` +```yaml +models: + UserChanges: + model: "map[string]interface{}" +``` + +After running go generate you should end up with a resolver that looks like this: +```go +func (r *queryResolver) UpdateUser(ctx context.Context, id int, changes map[string]interface{}) (*User, error) { + u := fetchFromDb(id) + /// apply the changes + saveToDb(u) + return u, nil +} +``` + +We often use the mapstructure library to directly apply these changesets directly to the object using reflection: +```go + +func ApplyChanges(changes map[string]interface{}, to interface{}) error { + dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ + ErrorUnused: true, + TagName: "json", + Result: to, + ZeroFields: true, + // This is needed to get mapstructure to call the gqlgen unmarshaler func for custom scalars (eg Date) + DecodeHook: func(a reflect.Type, b reflect.Type, v interface{}) (interface{}, error) { + if reflect.PtrTo(b).Implements(reflect.TypeOf((*graphql.Unmarshaler)(nil)).Elem()) { + resultType := reflect.New(b) + result := resultType.MethodByName("UnmarshalGQL").Call([]reflect.Value{reflect.ValueOf(v)}) + err, _ := result[0].Interface().(error) + return resultType.Elem().Interface(), err + } + + return v, nil + }, + }) + + if err != nil { + return err + } + + return dec.Decode(changes) +} +``` diff --git a/docs/content/reference/complexity.md b/docs/content/reference/complexity.md index 70640351ba..5f92f5d9f1 100644 --- a/docs/content/reference/complexity.md +++ b/docs/content/reference/complexity.md @@ -56,7 +56,7 @@ func main() { } ``` -Now any query with complexity greater than 5 is rejected by the API. By default, each field and level of depth adds one to the overall query complexity. +Now any query with complexity greater than 5 is rejected by the API. By default, each field and level of depth adds one to the overall query complexity. You can also use `handler.ComplexityLimitFunc` to dynamically configure the complexity limit per request. This helps, but we still have a problem: the `posts` and `related` fields, which return arrays, are much more expensive to resolve than the scalar `title` and `text` fields. However, the default complexity calculation weights them equally. It would make more sense to apply a higher cost to the array fields. diff --git a/docs/content/reference/field-collection.md b/docs/content/reference/field-collection.md new file mode 100644 index 0000000000..f79bc4b0b6 --- /dev/null +++ b/docs/content/reference/field-collection.md @@ -0,0 +1,57 @@ +--- +title: 'Determining which fields were requested by a query' +description: How to determine which fields a query requested in a resolver. +linkTitle: Field Collection +menu: { main: { parent: 'reference' } } +--- + +Often it is useful to know which fields were queried for in a resolver. Having this information can allow a resolver to only fetch the set of fields required from a data source, rather than over-fetching everything and allowing gqlgen to do the rest. + +This process is known as [Field Collection](https://facebook.github.io/graphql/draft/#sec-Field-Collection) — gqlgen automatically does this in order to know which fields should be a part of the response payload. The set of collected fields does however depend on the type being resolved. Queries can contain fragments, and resolvers can return interfaces and unions, therefore the set of collected fields cannot be fully determined until the type of the resolved object is known. + +Within a resolver, there are several API methods available to query the selected fields. + +## CollectAllFields + +`CollectAllFields` is the simplest way to get the set of queried fields. It will return a slice of strings of the field names from the query. This will be a unique set of fields, and will return all fragment fields, ignoring fragment Type Conditions. + +Given the following example query: + +```graphql +query { + foo { + fieldA + ... on Bar { + fieldB + } + ... on Baz { + fieldC + } + } +} +``` + +Calling `CollectAllFields` from a resolver will yield a string slice containing `fieldA`, `fieldB`, and `fieldC`. + +## CollectFieldsCtx + +`CollectFieldsCtx` is useful in cases where more information on matches is required, or the set of collected fields should match fragment type conditions for a resolved type. `CollectFieldsCtx` takes a `satisfies` parameter, which should be a slice of strings of types that the resolved type will satisfy. + +For example, given the following schema: + +```graphql +interface Shape { + area: Float +} +type Circle implements Shape { + radius: Float + area: Float +} +union Shapes = Circle +``` + +The type `Circle` would satisfy `Circle`, `Shape`, and `Shapes` — these values should be passed to `CollectFieldsCtx` to get the set of collected fields for a resolved `Circle` object. + +> Note +> +> `CollectFieldsCtx` is just a convenience wrapper around `CollectFields` that calls the later with the selection set automatically passed through from the resolver context. diff --git a/docs/content/reference/plugins.md b/docs/content/reference/plugins.md new file mode 100644 index 0000000000..7f8cfce0b0 --- /dev/null +++ b/docs/content/reference/plugins.md @@ -0,0 +1,62 @@ +--- +linkTitle: Plugins +title: How to write plugins for gqlgen +description: Use plugins to customize code generation and integrate with other libraries +menu: { main: { parent: 'reference' } } +--- + +Plugins provide a way to hook into the gqlgen code generation lifecycle. In order to use anything other than the +default plugins you will need to create your own entrypoint: + + +## Using a plugin +```go +// +build ignore + +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "time" + + "github.com/99designs/gqlgen/api" + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/plugin/stubgen" +) + +func main() { + cfg, err := config.LoadConfigFromDefaultLocations() + if err != nil { + fmt.Fprintln(os.Stderr, "failed to load config", err.Error()) + os.Exit(2) + } + + + err = api.Generate(cfg, + api.AddPlugin(yourplugin.New()), // This is the magic line + ) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(3) + } +} + +``` + +## Writing a plugin + +There are currently only two hooks: + - MutateConfig: Allows a plugin to mutate the config before codegen starts. This allows plugins to add + custom directives, define types, and implement resolvers. see + [modelgen](https://github.com/99designs/gqlgen/tree/master/plugin/modelgen) for an example + - GenerateCode: Allows a plugin to generate a new output file, see + [stubgen](https://github.com/99designs/gqlgen/tree/master/plugin/stubgen) for an example + +Take a look at [plugin.go](https://github.com/99designs/gqlgen/blob/master/plugin/plugin.go) for the full list of +available hooks. These are likely to change with each release. + + diff --git a/docs/content/reference/scalars.md b/docs/content/reference/scalars.md index 961cd748c0..ec9a9fcf0b 100644 --- a/docs/content/reference/scalars.md +++ b/docs/content/reference/scalars.md @@ -1,14 +1,32 @@ --- -linkTitle: Custom Scalars -title: Using custom graphql types in golang -description: Defining custom GraphQL scalar types using gqlgen +linkTitle: Scalars +title: Mapping GraphQL scalar types to Go types +description: Mapping GraphQL scalar types to Go types menu: { main: { parent: 'reference' } } --- -There are two different ways to implement scalars in gqlgen, depending on your need. +## Built-in helpers +gqlgen ships with two built-in helpers for common custom scalar use-cases, `Time` and `Map`. Adding either of these to a schema will automatically add the marshalling behaviour to Go types. + +### Time + +```graphql +scalar Time +``` + +Maps a `Time` GraphQL scalar to a Go `time.Time` struct. + +### Map + +```graphql +scalar Map +``` + +Maps an arbitrary GraphQL value to a `map[string]{interface}` Go type. + +## Custom scalars with user defined types -## With user defined types For user defined types you can implement the graphql.Marshal and graphql.Unmarshal interfaces and they will be called. ```go @@ -55,7 +73,7 @@ models: ``` -## Custom scalars for types you don't control +## Custom scalars with third party types Sometimes you cant add methods to a type because its in another repo, part of the standard library (eg string or time.Time). To do this we can build an external marshaler: diff --git a/docs/layouts/_default/baseof.html b/docs/layouts/_default/baseof.html index 4fb29e6809..70eea20aba 100644 --- a/docs/layouts/_default/baseof.html +++ b/docs/layouts/_default/baseof.html @@ -9,7 +9,7 @@ {{ if not .IsHome }}{{ .Title }} —{{ end }} {{ .Site.Title }} - + diff --git a/docs/layouts/index.html b/docs/layouts/index.html index 9e5776800d..f3e8fa58eb 100644 --- a/docs/layouts/index.html +++ b/docs/layouts/index.html @@ -11,6 +11,11 @@

{{ .LinkTitle }}

{{ .Content }} + {{.Scratch.Set "intro" (readFile "content/_introduction.md")}} + {{.Scratch.Set "intro" (split (.Scratch.Get "intro") "\n")}} + {{.Scratch.Set "intro" (after 2 (.Scratch.Get "intro"))}} + {{.Scratch.Set "intro" (delimit (.Scratch.Get "intro") "\n")}} + {{.Scratch.Get "intro"|markdownify}}
{{ end }} diff --git a/docs/static/main.css b/docs/static/main.css index 2178cbac66..0e26e83a76 100644 --- a/docs/static/main.css +++ b/docs/static/main.css @@ -221,10 +221,6 @@ ul.submenu span { padding: 5px 10px; } -ul.menu li { - font-weight: 400; -} - ul.menu li.active, ul.menu a:hover { background-color: var(--color-nav-active); @@ -389,7 +385,6 @@ em { color: var(--color-heading-text); background-color: var(--color-heading-background); font-family: var(--font-heading); - font-weight: 500; list-style-type: none; -webkit-font-smoothing: antialiased; @@ -435,4 +430,20 @@ blockquote p:first-of-type { blockquote code { background-color: var(--color-blockquote-highlight); -} \ No newline at end of file +} + +table { + width: 100%; +} + +td, th { + padding: 0.2em 1em; +} + +tr { + border-bottom: 1px solid var(--color-heading-background); +} + +tr td:first-child, th { + font-weight: bold; +} diff --git a/example/chat/generated.go b/example/chat/generated.go index d1bb62f7d3..9081ed4439 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "errors" + "io" "strconv" "sync" "time" @@ -16,6 +17,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -42,15 +45,15 @@ type DirectiveRoot struct { type ComplexityRoot struct { Chatroom struct { - Name func(childComplexity int) int Messages func(childComplexity int) int + Name func(childComplexity int) int } Message struct { - Id func(childComplexity int) int - Text func(childComplexity int) int - CreatedBy func(childComplexity int) int CreatedAt func(childComplexity int) int + CreatedBy func(childComplexity int) int + ID func(childComplexity int) int + Text func(childComplexity int) int } Mutation struct { @@ -67,121 +70,13 @@ type ComplexityRoot struct { } type MutationResolver interface { - Post(ctx context.Context, text string, username string, roomName string) (Message, error) + Post(ctx context.Context, text string, username string, roomName string) (*Message, error) } type QueryResolver interface { Room(ctx context.Context, name string) (*Chatroom, error) } type SubscriptionResolver interface { - MessageAdded(ctx context.Context, roomName string) (<-chan Message, error) -} - -func field_Mutation_post_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["text"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["text"] = arg0 - var arg1 string - if tmp, ok := rawArgs["username"]; ok { - var err error - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["username"] = arg1 - var arg2 string - if tmp, ok := rawArgs["roomName"]; ok { - var err error - arg2, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["roomName"] = arg2 - return args, nil - -} - -func field_Query_room_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field_Subscription_messageAdded_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["roomName"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["roomName"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - + MessageAdded(ctx context.Context, roomName string) (<-chan *Message, error) } type executableSchema struct { @@ -195,80 +90,82 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Chatroom.name": - if e.complexity.Chatroom.Name == nil { - break - } - - return e.complexity.Chatroom.Name(childComplexity), true - - case "Chatroom.messages": + case "Chatroom.Messages": if e.complexity.Chatroom.Messages == nil { break } return e.complexity.Chatroom.Messages(childComplexity), true - case "Message.id": - if e.complexity.Message.Id == nil { + case "Chatroom.Name": + if e.complexity.Chatroom.Name == nil { break } - return e.complexity.Message.Id(childComplexity), true + return e.complexity.Chatroom.Name(childComplexity), true - case "Message.text": - if e.complexity.Message.Text == nil { + case "Message.CreatedAt": + if e.complexity.Message.CreatedAt == nil { break } - return e.complexity.Message.Text(childComplexity), true + return e.complexity.Message.CreatedAt(childComplexity), true - case "Message.createdBy": + case "Message.CreatedBy": if e.complexity.Message.CreatedBy == nil { break } return e.complexity.Message.CreatedBy(childComplexity), true - case "Message.createdAt": - if e.complexity.Message.CreatedAt == nil { + case "Message.ID": + if e.complexity.Message.ID == nil { break } - return e.complexity.Message.CreatedAt(childComplexity), true + return e.complexity.Message.ID(childComplexity), true + + case "Message.Text": + if e.complexity.Message.Text == nil { + break + } + + return e.complexity.Message.Text(childComplexity), true - case "Mutation.post": + case "Mutation.Post": if e.complexity.Mutation.Post == nil { break } - args, err := field_Mutation_post_args(rawArgs) + args, err := ec.field_Mutation_post_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Mutation.Post(childComplexity, args["text"].(string), args["username"].(string), args["roomName"].(string)), true - case "Query.room": + case "Query.Room": if e.complexity.Query.Room == nil { break } - args, err := field_Query_room_args(rawArgs) + args, err := ec.field_Query_room_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Query.Room(childComplexity, args["name"].(string)), true - case "Subscription.messageAdded": + case "Subscription.MessageAdded": if e.complexity.Subscription.MessageAdded == nil { break } - args, err := field_Subscription_messageAdded_args(rawArgs) + args, err := ec.field_Subscription_messageAdded_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -292,7 +189,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -350,181 +248,234 @@ type executionContext struct { *executableSchema } -var chatroomImplementors = []string{"Chatroom"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, obj *Chatroom) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, chatroomImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Chatroom") - case "name": - out.Values[i] = ec._Chatroom_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "messages": - out.Values[i] = ec._Chatroom_messages(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil } - - if invalid { - return graphql.Null - } - return out + return res } -// nolint: vetshadow -func (ec *executionContext) _Chatroom_name(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Chatroom", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return introspection.WrapSchema(parsedSchema), nil } -// nolint: vetshadow -func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Chatroom", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Messages, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.([]Message) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `type Chatroom { + name: String! + messages: [Message!]! +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } +type Message { + id: ID! + text: String! + createdBy: String! + createdAt: Time! +} - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { +type Query { + room(name:String!): Chatroom +} - return ec._Message(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } +type Mutation { + post(text: String!, username: String!, roomName: String!): Message! +} - } - wg.Wait() - return arr1 +type Subscription { + messageAdded(roomName: String!): Message! } -var messageImplementors = []string{"Message"} +scalar Time +`}, +) -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, obj *Message) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, messageImplementors) +// endregion ************************** generated!.gotpl ************************** - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +// region ***************************** args.gotpl ***************************** - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Message") - case "id": - out.Values[i] = ec._Message_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "text": - out.Values[i] = ec._Message_text(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "createdBy": - out.Values[i] = ec._Message_createdBy(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "createdAt": - out.Values[i] = ec._Message_createdAt(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) field_Mutation_post_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["text"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["text"] = arg0 + var arg1 string + if tmp, ok := rawArgs["username"]; ok { + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["username"] = arg1 + var arg2 string + if tmp, ok := rawArgs["roomName"]; ok { + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err } } + args["roomName"] = arg2 + return args, nil +} - if invalid { +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_room_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Subscription_messageAdded_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["roomName"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["roomName"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Chatroom_name(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Chatroom", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return out + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Chatroom", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Messages, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]Message) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNMessage2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Message_id(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Message", - Args: nil, - Field: field, + Object: "Message", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -541,17 +492,17 @@ func (ec *executionContext) _Message_id(ctx context.Context, field graphql.Colle res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNID2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Message_text(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Message", - Args: nil, - Field: field, + Object: "Message", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -568,17 +519,17 @@ func (ec *executionContext) _Message_text(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Message_createdBy(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Message", - Args: nil, - Field: field, + Object: "Message", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -595,17 +546,17 @@ func (ec *executionContext) _Message_createdBy(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Message_createdAt(ctx context.Context, field graphql.CollectedField, obj *Message) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Message", - Args: nil, - Field: field, + Object: "Message", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -622,59 +573,26 @@ func (ec *executionContext) _Message_createdAt(ctx context.Context, field graphq res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalTime(res) -} - -var mutationImplementors = []string{"Mutation"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, mutationImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Mutation", - }) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Mutation") - case "post": - out.Values[i] = ec._Mutation_post(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Mutation_post_args(rawArgs) + args, err := ec.field_Mutation_post_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Mutation", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -686,69 +604,29 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.(Message) + res := resTmp.(*Message) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Message(ctx, field.Selections, &res) -} - -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "room": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_room(ctx, field) - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalNMessage2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_room(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_room_args(rawArgs) + args, err := ec.field_Query_room_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -760,30 +638,26 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle res := resTmp.(*Chatroom) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Chatroom(ctx, field.Selections, res) + return ec.marshalOChatroom2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐChatroom(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -795,22 +669,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -824,45 +693,20 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -var subscriptionImplementors = []string{"Subscription"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Subscription(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, subscriptionImplementors) +func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Subscription", + Field: field, + Args: nil, }) - if len(fields) != 1 { - ec.Errorf(ctx, "must subscribe to exactly one stream") - return nil - } - - switch fields[0].Name { - case "messageAdded": - return ec._Subscription_messageAdded(ctx, fields[0]) - default: - panic("unknown field " + strconv.Quote(fields[0].Name)) - } -} - -func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler { rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Subscription_messageAdded_args(rawArgs) + args, err := ec.field_Subscription_messageAdded_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return nil } - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Field: field, - }) // FIXME: subscriptions are missing request middleware stack https://github.com/99designs/gqlgen/issues/259 // and Tracer stack rctx := ctx @@ -876,64 +720,24 @@ func (ec *executionContext) _Subscription_messageAdded(ctx context.Context, fiel if !ok { return nil } - var out graphql.OrderedMap - out.Add(field.Alias, func() graphql.Marshaler { - return ec._Message(ctx, field.Selections, &res) - }()) - return &out - } -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null + return graphql.WriterFunc(func(w io.Writer) { + w.Write([]byte{'{'}) + graphql.MarshalString(field.Alias).MarshalGQL(w) + w.Write([]byte{':'}) + ec.marshalNMessage2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx, field.Selections, res).MarshalGQL(w) + w.Write([]byte{'}'}) + }) } - return out } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -950,17 +754,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -974,17 +778,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1001,26 +805,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1037,89 +832,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1136,17 +859,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1160,17 +883,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1187,17 +910,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1211,70 +934,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1291,17 +961,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1315,17 +985,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1342,50 +1012,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1402,25 +1039,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1437,17 +1066,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1461,60 +1090,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1531,17 +1117,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1555,17 +1141,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1582,25 +1168,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1614,125 +1192,44 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return graphql.MarshalString(*res) + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1749,25 +1246,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1781,22 +1270,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1810,22 +1294,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1842,96 +1321,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1948,17 +1348,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1972,21 +1372,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2000,25 +1396,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2030,50 +1427,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2087,50 +1451,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2144,58 +1475,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2207,50 +1506,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2264,125 +1530,996 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var chatroomImplementors = []string{"Chatroom"} + +func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, obj *Chatroom) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, chatroomImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Chatroom") + case "name": + out.Values[i] = ec._Chatroom_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "messages": + out.Values[i] = ec._Chatroom_messages(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var messageImplementors = []string{"Message"} + +func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, obj *Message) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, messageImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Message") + case "id": + out.Values[i] = ec._Message_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "text": + out.Values[i] = ec._Message_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "createdBy": + out.Values[i] = ec._Message_createdBy(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "createdAt": + out.Values[i] = ec._Message_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var mutationImplementors = []string{"Mutation"} + +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, mutationImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "post": + out.Values[i] = ec._Mutation_post(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "room": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_room(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var subscriptionImplementors = []string{"Subscription"} + +func (ec *executionContext) _Subscription(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, subscriptionImplementors) + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Subscription", + }) + if len(fields) != 1 { + ec.Errorf(ctx, "must subscribe to exactly one stream") + return nil + } + + switch fields[0].Name { + case "messageAdded": + return ec._Subscription_messageAdded(ctx, fields[0]) + default: + panic("unknown field " + strconv.Quote(fields[0].Name)) + } +} + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) +} + +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) +} + +func (ec *executionContext) marshalNMessage2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx context.Context, sel ast.SelectionSet, v Message) graphql.Marshaler { + return ec._Message(ctx, sel, &v) +} + +func (ec *executionContext) marshalNMessage2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx context.Context, sel ast.SelectionSet, v []Message) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNMessage2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNMessage2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐMessage(ctx context.Context, sel ast.SelectionSet, v *Message) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Message(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) +} + +func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return graphql.MarshalTime(v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} - return ec.___InputValue(ctx, field.Selections, &res[idx1]) +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.OfType(), nil - }) - if resTmp == nil { + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) marshalOChatroom2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐChatroom(ctx context.Context, sel ast.SelectionSet, v Chatroom) graphql.Marshaler { + return ec._Chatroom(ctx, sel, &v) +} - if res == nil { +func (ec *executionContext) marshalOChatroom2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋchatᚐChatroom(ctx context.Context, sel ast.SelectionSet, v *Chatroom) graphql.Marshaler { + if v == nil { return graphql.Null } + return ec._Chatroom(ctx, sel, v) +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + } - return res + wg.Wait() + return ret } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null } - return introspection.WrapSchema(parsedSchema), nil + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `type Chatroom { - name: String! - messages: [Message!]! +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) } -type Message { - id: ID! - text: String! - createdBy: String! - createdAt: Time! +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) } -type Query { - room(name:String!): Chatroom +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) } -type Mutation { - post(text: String!, username: String!, roomName: String!): Message! +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -type Subscription { - messageAdded(roomName: String!): Message! +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) } -scalar Time -`}, -) +// endregion ***************************** type.gotpl ***************************** diff --git a/example/chat/resolvers.go b/example/chat/resolvers.go index ff7a2af24c..5c0de7b060 100644 --- a/example/chat/resolvers.go +++ b/example/chat/resolvers.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package chat @@ -37,16 +37,16 @@ func New() Config { type Chatroom struct { Name string Messages []Message - Observers map[string]chan Message + Observers map[string]chan *Message } type mutationResolver struct{ *resolver } -func (r *mutationResolver) Post(ctx context.Context, text string, username string, roomName string) (Message, error) { +func (r *mutationResolver) Post(ctx context.Context, text string, username string, roomName string) (*Message, error) { r.mu.Lock() room := r.Rooms[roomName] if room == nil { - room = &Chatroom{Name: roomName, Observers: map[string]chan Message{}} + room = &Chatroom{Name: roomName, Observers: map[string]chan *Message{}} r.Rooms[roomName] = room } r.mu.Unlock() @@ -61,10 +61,10 @@ func (r *mutationResolver) Post(ctx context.Context, text string, username strin room.Messages = append(room.Messages, message) r.mu.Lock() for _, observer := range room.Observers { - observer <- message + observer <- &message } r.mu.Unlock() - return message, nil + return &message, nil } type queryResolver struct{ *resolver } @@ -73,7 +73,7 @@ func (r *queryResolver) Room(ctx context.Context, name string) (*Chatroom, error r.mu.Lock() room := r.Rooms[name] if room == nil { - room = &Chatroom{Name: name, Observers: map[string]chan Message{}} + room = &Chatroom{Name: name, Observers: map[string]chan *Message{}} r.Rooms[name] = room } r.mu.Unlock() @@ -83,17 +83,17 @@ func (r *queryResolver) Room(ctx context.Context, name string) (*Chatroom, error type subscriptionResolver struct{ *resolver } -func (r *subscriptionResolver) MessageAdded(ctx context.Context, roomName string) (<-chan Message, error) { +func (r *subscriptionResolver) MessageAdded(ctx context.Context, roomName string) (<-chan *Message, error) { r.mu.Lock() room := r.Rooms[roomName] if room == nil { - room = &Chatroom{Name: roomName, Observers: map[string]chan Message{}} + room = &Chatroom{Name: roomName, Observers: map[string]chan *Message{}} r.Rooms[roomName] = room } r.mu.Unlock() id := randString(8) - events := make(chan Message, 1) + events := make(chan *Message, 1) go func() { <-ctx.Done() diff --git a/example/config/generated.go b/example/config/generated.go index f408b8e5fa..c95c8f1a06 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -15,6 +15,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -49,21 +51,21 @@ type ComplexityRoot struct { } Todo struct { - Id func(childComplexity int) int - DatabaseId func(childComplexity int) int - Text func(childComplexity int) int - Done func(childComplexity int) int - User func(childComplexity int) int + DatabaseID func(childComplexity int) int + Description func(childComplexity int) int + Done func(childComplexity int) int + ID func(childComplexity int) int + User func(childComplexity int) int } User struct { - Id func(childComplexity int) int - Name func(childComplexity int) int + FullName func(childComplexity int) int + ID func(childComplexity int) int } } type MutationResolver interface { - CreateTodo(ctx context.Context, input NewTodo) (Todo, error) + CreateTodo(ctx context.Context, input NewTodo) (*Todo, error) } type QueryResolver interface { Todos(ctx context.Context) ([]Todo, error) @@ -72,66 +74,6 @@ type TodoResolver interface { ID(ctx context.Context, obj *Todo) (string, error) } -func field_Mutation_createTodo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 NewTodo - if tmp, ok := rawArgs["input"]; ok { - var err error - arg0, err = UnmarshalNewTodo(tmp) - if err != nil { - return nil, err - } - } - args["input"] = arg0 - return args, nil - -} - -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -143,75 +85,77 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Mutation.createTodo": + case "Mutation.CreateTodo": if e.complexity.Mutation.CreateTodo == nil { break } - args, err := field_Mutation_createTodo_args(rawArgs) + args, err := ec.field_Mutation_createTodo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Mutation.CreateTodo(childComplexity, args["input"].(NewTodo)), true - case "Query.todos": + case "Query.Todos": if e.complexity.Query.Todos == nil { break } return e.complexity.Query.Todos(childComplexity), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "Todo.DatabaseID": + if e.complexity.Todo.DatabaseID == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.Todo.DatabaseID(childComplexity), true - case "Todo.databaseId": - if e.complexity.Todo.DatabaseId == nil { + case "Todo.Description": + if e.complexity.Todo.Description == nil { break } - return e.complexity.Todo.DatabaseId(childComplexity), true + return e.complexity.Todo.Description(childComplexity), true - case "Todo.text": - if e.complexity.Todo.Text == nil { + case "Todo.Done": + if e.complexity.Todo.Done == nil { break } - return e.complexity.Todo.Text(childComplexity), true + return e.complexity.Todo.Done(childComplexity), true - case "Todo.done": - if e.complexity.Todo.Done == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Done(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.user": + case "Todo.User": if e.complexity.Todo.User == nil { break } return e.complexity.Todo.User(childComplexity), true - case "User.id": - if e.complexity.User.Id == nil { + case "User.FullName": + if e.complexity.User.FullName == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.User.FullName(childComplexity), true - case "User.name": - if e.complexity.User.Name == nil { + case "User.ID": + if e.complexity.User.ID == nil { break } - return e.complexity.User.Name(childComplexity), true + return e.complexity.User.ID(childComplexity), true } return 0, false @@ -230,7 +174,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -259,56 +204,146 @@ type executionContext struct { *executableSchema } -var mutationImplementors = []string{"Mutation"} +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil + } + return res +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, mutationImplementors) +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Mutation", - }) +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `type Query { + todos: [Todo!]! +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Mutation") - case "createTodo": - out.Values[i] = ec._Mutation_createTodo(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +type Mutation { + createTodo(input: NewTodo!): Todo! +} +`}, + &ast.Source{Name: "todo.graphql", Input: `type Todo { + id: ID! + databaseId: Int! + text: String! + done: Boolean! + user: User! +} + +input NewTodo { + text: String! + userId: String! +} + +`}, + &ast.Source{Name: "user.graphql", Input: `type User { + id: ID! + name: String! +} +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Mutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 NewTodo + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalNNewTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐNewTodo(ctx, tmp) + if err != nil { + return nil, err } } + args["input"] = arg0 + return args, nil +} - if invalid { - return graphql.Null +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil } -// nolint: vetshadow +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Mutation_createTodo_args(rawArgs) + args, err := ec.field_Mutation_createTodo_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Mutation", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -320,64 +355,20 @@ func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field grap } return graphql.Null } - res := resTmp.(Todo) + res := resTmp.(*Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Todo(ctx, field.Selections, &res) -} - -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "todos": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_todos(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -394,58 +385,26 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll res := resTmp.([]Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Todo(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -457,22 +416,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -486,77 +440,17 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -var todoImplementors = []string{"Todo"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, todoImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Todo") - case "id": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Todo_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "databaseId": - out.Values[i] = ec._Todo_databaseId(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "text": - out.Values[i] = ec._Todo_text(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "done": - out.Values[i] = ec._Todo_done(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "user": - out.Values[i] = ec._Todo_user(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -573,17 +467,17 @@ func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.Collecte res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNID2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_databaseId(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -600,17 +494,17 @@ func (ec *executionContext) _Todo_databaseId(ctx context.Context, field graphql. res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -627,17 +521,17 @@ func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -654,17 +548,17 @@ func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.Collec res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_user(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -681,53 +575,17 @@ func (ec *executionContext) _Todo_user(ctx context.Context, field graphql.Collec res := resTmp.(User) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._User(ctx, field.Selections, &res) -} - -var userImplementors = []string{"User"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *User) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, userImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("User") - case "id": - out.Values[i] = ec._User_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._User_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐUser(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -744,17 +602,17 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNID2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -771,59 +629,17 @@ func (ec *executionContext) _User_name(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -840,17 +656,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -864,17 +680,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -891,26 +707,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -927,89 +734,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1026,17 +761,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1050,17 +785,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1077,17 +812,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1101,70 +836,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1181,17 +863,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1205,17 +887,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1232,50 +914,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1292,25 +941,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1327,17 +968,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1351,60 +992,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1421,17 +1019,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1445,17 +1043,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1472,25 +1070,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1504,65 +1094,17 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1579,50 +1121,17 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1639,25 +1148,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1671,22 +1172,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1700,22 +1196,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1732,96 +1223,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1838,17 +1250,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1862,21 +1274,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1890,25 +1298,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1920,50 +1329,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1977,50 +1353,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2034,58 +1377,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2097,50 +1408,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2154,50 +1432,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2211,15 +1456,14 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } +// endregion **************************** field.gotpl ***************************** - return ec.___Type(ctx, field.Selections, res) -} +// region **************************** input.gotpl ***************************** -func UnmarshalNewTodo(v interface{}) (NewTodo, error) { +func (ec *executionContext) unmarshalInputNewTodo(ctx context.Context, v interface{}) (NewTodo, error) { var it NewTodo var asMap = v.(map[string]interface{}) @@ -2227,13 +1471,13 @@ func UnmarshalNewTodo(v interface{}) (NewTodo, error) { switch k { case "text": var err error - it.Text, err = graphql.UnmarshalString(v) + it.Text, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } case "userId": var err error - it.UserID, err = graphql.UnmarshalString(v) + it.UserID, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } @@ -2243,61 +1487,953 @@ func UnmarshalNewTodo(v interface{}) (NewTodo, error) { return it, nil } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var mutationImplementors = []string{"Mutation"} + +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, mutationImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "createTodo": + out.Values[i] = ec._Mutation_createTodo(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil } - return res + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "todos": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_todos(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapSchema(parsedSchema), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var todoImplementors = []string{"Todo"} + +func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, todoImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Todo") + case "id": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Todo_id(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "databaseId": + out.Values[i] = ec._Todo_databaseId(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "text": + out.Values[i] = ec._Todo_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "done": + out.Values[i] = ec._Todo_done(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "user": + out.Values[i] = ec._Todo_user(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `type Query { - todos: [Todo!]! -} +var userImplementors = []string{"User"} -type Mutation { - createTodo(input: NewTodo!): Todo! -} -`}, - &ast.Source{Name: "todo.graphql", Input: `type Todo { - id: ID! - databaseId: Int! - text: String! - done: Boolean! - user: User! +func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *User) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, userImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("User") + case "id": + out.Values[i] = ec._User_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -input NewTodo { - text: String! - userId: String! +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -`}, - &ast.Source{Name: "user.graphql", Input: `type User { - id: ID! - name: String! +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -`}, -) + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) +} + +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalNNewTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐNewTodo(ctx context.Context, v interface{}) (NewTodo, error) { + return ec.unmarshalInputNewTodo(ctx, v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx context.Context, sel ast.SelectionSet, v Todo) graphql.Marshaler { + return ec._Todo(ctx, sel, &v) +} + +func (ec *executionContext) marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx context.Context, sel ast.SelectionSet, v []Todo) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐTodo(ctx context.Context, sel ast.SelectionSet, v *Todo) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Todo(ctx, sel, v) +} + +func (ec *executionContext) marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋconfigᚐUser(ctx context.Context, sel ast.SelectionSet, v User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/config/resolver.go b/example/config/resolver.go index 1e17bba53e..85b5eae5bc 100644 --- a/example/config/resolver.go +++ b/example/config/resolver.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package config @@ -38,7 +38,7 @@ func (r *Resolver) Todo() TodoResolver { type mutationResolver struct{ *Resolver } -func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (Todo, error) { +func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (*Todo, error) { newID := r.nextID r.nextID++ @@ -49,7 +49,7 @@ func (r *mutationResolver) CreateTodo(ctx context.Context, input NewTodo) (Todo, r.todos = append(r.todos, newTodo) - return newTodo, nil + return &newTodo, nil } type queryResolver struct{ *Resolver } @@ -60,6 +60,10 @@ func (r *queryResolver) Todos(ctx context.Context) ([]Todo, error) { type todoResolver struct{ *Resolver } +func (r *todoResolver) Description(ctx context.Context, obj *Todo) (string, error) { + panic("implement me") +} + func (r *todoResolver) ID(ctx context.Context, obj *Todo) (string, error) { if obj.ID != "" { return obj.ID, nil diff --git a/example/dataloader/addressloader_gen.go b/example/dataloader/addressloader_gen.go index b99ad3635d..90e1d433fc 100644 --- a/example/dataloader/addressloader_gen.go +++ b/example/dataloader/addressloader_gen.go @@ -7,6 +7,27 @@ import ( "time" ) +// AddressLoaderConfig captures the config to create a new AddressLoader +type AddressLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []int) ([]*Address, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewAddressLoader creates a new AddressLoader given a fetch, wait, and maxBatch +func NewAddressLoader(config AddressLoaderConfig) *AddressLoader { + return &AddressLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // AddressLoader batches and caches requests type AddressLoader struct { // this method provides the data for the loader diff --git a/example/dataloader/dataloader_test.go b/example/dataloader/dataloader_test.go index 7be58002af..7283f12089 100644 --- a/example/dataloader/dataloader_test.go +++ b/example/dataloader/dataloader_test.go @@ -84,7 +84,7 @@ func TestTodo(t *testing.T) { } err := c.Post(`{ torture2d(customerIds:{}) { id name } }`, &resp) - require.EqualError(t, err, "[{\"message\":\"map[string]interface {} is not an int\"}]") + require.EqualError(t, err, "[{\"message\":\"map[string]interface {} is not an int\",\"path\":[\"torture2d\"]}]") }) } diff --git a/example/dataloader/dataloaders.go b/example/dataloader/dataloaders.go index 8e4efe56ed..05944e5d5e 100644 --- a/example/dataloader/dataloaders.go +++ b/example/dataloader/dataloaders.go @@ -1,6 +1,6 @@ -//go:generate gorunpkg github.com/vektah/dataloaden -keys int github.com/99designs/gqlgen/example/dataloader.Address -//go:generate gorunpkg github.com/vektah/dataloaden -keys int -slice github.com/99designs/gqlgen/example/dataloader.Order -//go:generate gorunpkg github.com/vektah/dataloaden -keys int -slice github.com/99designs/gqlgen/example/dataloader.Item +//go:generate go run github.com/vektah/dataloaden -keys int github.com/99designs/gqlgen/example/dataloader.Address +//go:generate go run github.com/vektah/dataloaden -keys int -slice github.com/99designs/gqlgen/example/dataloader.Order +//go:generate go run github.com/vektah/dataloaden -keys int -slice github.com/99designs/gqlgen/example/dataloader.Item package dataloader diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index a3d4f0ffdb..ab15069c1a 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -16,6 +16,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -42,15 +44,15 @@ type DirectiveRoot struct { type ComplexityRoot struct { Address struct { - Id func(childComplexity int) int - Street func(childComplexity int) int Country func(childComplexity int) int + ID func(childComplexity int) int + Street func(childComplexity int) int } Customer struct { - Id func(childComplexity int) int - Name func(childComplexity int) int Address func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int Orders func(childComplexity int) int } @@ -59,9 +61,9 @@ type ComplexityRoot struct { } Order struct { - Id func(childComplexity int) int - Date func(childComplexity int) int Amount func(childComplexity int) int + Date func(childComplexity int) int + ID func(childComplexity int) int Items func(childComplexity int) int } @@ -85,114 +87,6 @@ type QueryResolver interface { Torture2d(ctx context.Context, customerIds [][]int) ([][]Customer, error) } -func field_Query_torture1d_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 []int - if tmp, ok := rawArgs["customerIds"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } - } - arg0 = make([]int, len(rawIf1)) - for idx1 := range rawIf1 { - arg0[idx1], err = graphql.UnmarshalInt(rawIf1[idx1]) - } - if err != nil { - return nil, err - } - } - args["customerIds"] = arg0 - return args, nil - -} - -func field_Query_torture2d_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 [][]int - if tmp, ok := rawArgs["customerIds"]; ok { - var err error - var rawIf1 []interface{} - if tmp != nil { - if tmp1, ok := tmp.([]interface{}); ok { - rawIf1 = tmp1 - } else { - rawIf1 = []interface{}{tmp} - } - } - arg0 = make([][]int, len(rawIf1)) - for idx1 := range rawIf1 { - var rawIf2 []interface{} - if rawIf1[idx1] != nil { - if tmp1, ok := rawIf1[idx1].([]interface{}); ok { - rawIf2 = tmp1 - } else { - rawIf2 = []interface{}{rawIf1[idx1]} - } - } - arg0[idx1] = make([]int, len(rawIf2)) - for idx2 := range rawIf2 { - arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2]) - } - } - if err != nil { - return nil, err - } - } - args["customerIds"] = arg0 - return args, nil - -} - -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -204,117 +98,119 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Address.id": - if e.complexity.Address.Id == nil { + case "Address.Country": + if e.complexity.Address.Country == nil { break } - return e.complexity.Address.Id(childComplexity), true + return e.complexity.Address.Country(childComplexity), true - case "Address.street": - if e.complexity.Address.Street == nil { + case "Address.ID": + if e.complexity.Address.ID == nil { break } - return e.complexity.Address.Street(childComplexity), true + return e.complexity.Address.ID(childComplexity), true - case "Address.country": - if e.complexity.Address.Country == nil { + case "Address.Street": + if e.complexity.Address.Street == nil { break } - return e.complexity.Address.Country(childComplexity), true + return e.complexity.Address.Street(childComplexity), true - case "Customer.id": - if e.complexity.Customer.Id == nil { + case "Customer.Address": + if e.complexity.Customer.Address == nil { break } - return e.complexity.Customer.Id(childComplexity), true + return e.complexity.Customer.Address(childComplexity), true - case "Customer.name": - if e.complexity.Customer.Name == nil { + case "Customer.ID": + if e.complexity.Customer.ID == nil { break } - return e.complexity.Customer.Name(childComplexity), true + return e.complexity.Customer.ID(childComplexity), true - case "Customer.address": - if e.complexity.Customer.Address == nil { + case "Customer.Name": + if e.complexity.Customer.Name == nil { break } - return e.complexity.Customer.Address(childComplexity), true + return e.complexity.Customer.Name(childComplexity), true - case "Customer.orders": + case "Customer.Orders": if e.complexity.Customer.Orders == nil { break } return e.complexity.Customer.Orders(childComplexity), true - case "Item.name": + case "Item.Name": if e.complexity.Item.Name == nil { break } return e.complexity.Item.Name(childComplexity), true - case "Order.id": - if e.complexity.Order.Id == nil { + case "Order.Amount": + if e.complexity.Order.Amount == nil { break } - return e.complexity.Order.Id(childComplexity), true + return e.complexity.Order.Amount(childComplexity), true - case "Order.date": + case "Order.Date": if e.complexity.Order.Date == nil { break } return e.complexity.Order.Date(childComplexity), true - case "Order.amount": - if e.complexity.Order.Amount == nil { + case "Order.ID": + if e.complexity.Order.ID == nil { break } - return e.complexity.Order.Amount(childComplexity), true + return e.complexity.Order.ID(childComplexity), true - case "Order.items": + case "Order.Items": if e.complexity.Order.Items == nil { break } return e.complexity.Order.Items(childComplexity), true - case "Query.customers": + case "Query.Customers": if e.complexity.Query.Customers == nil { break } return e.complexity.Query.Customers(childComplexity), true - case "Query.torture1d": + case "Query.Torture1d": if e.complexity.Query.Torture1d == nil { break } - args, err := field_Query_torture1d_args(rawArgs) + args, err := ec.field_Query_torture1d_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Query.Torture1d(childComplexity, args["customerIds"].([]int)), true - case "Query.torture2d": + case "Query.Torture2d": if e.complexity.Query.Torture2d == nil { break } - args, err := field_Query_torture2d_args(rawArgs) + args, err := ec.field_Query_torture2d_args(context.TODO(), rawArgs) if err != nil { return 0, false } @@ -338,7 +234,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -354,54 +251,157 @@ type executionContext struct { *executableSchema } -var addressImplementors = []string{"Address"} +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil + } + return res +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, obj *Address) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, addressImplementors) +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Address") - case "id": - out.Values[i] = ec._Address_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "street": - out.Values[i] = ec._Address_street(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "country": - out.Values[i] = ec._Address_country(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `type Query { + customers: [Customer!] + + # these methods are here to test code generation of nested arrays + torture1d(customerIds: [Int!]): [Customer!] + torture2d(customerIds: [[Int!]]): [[Customer!]] +} + +type Customer { + id: Int! + name: String! + address: Address + orders: [Order!] +} + +type Address { + id: Int! + street: String! + country: String! +} + +type Order { + id: Int! + date: Time! + amount: Float! + items: [Item!] +} + +type Item { + name: String! +} +scalar Time +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_torture1d_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []int + if tmp, ok := rawArgs["customerIds"]; ok { + arg0, err = ec.unmarshalOInt2ᚕint(ctx, tmp) + if err != nil { + return nil, err } } + args["customerIds"] = arg0 + return args, nil +} - if invalid { - return graphql.Null +func (ec *executionContext) field_Query_torture2d_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 [][]int + if tmp, ok := rawArgs["customerIds"]; ok { + arg0, err = ec.unmarshalOInt2ᚕᚕint(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["customerIds"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil } -// nolint: vetshadow +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + func (ec *executionContext) _Address_id(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Address", - Args: nil, - Field: field, + Object: "Address", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -418,17 +418,17 @@ func (ec *executionContext) _Address_id(ctx context.Context, field graphql.Colle res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Address_street(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Address", - Args: nil, - Field: field, + Object: "Address", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -445,17 +445,17 @@ func (ec *executionContext) _Address_street(ctx context.Context, field graphql.C res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Address_country(ctx context.Context, field graphql.CollectedField, obj *Address) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Address", - Args: nil, - Field: field, + Object: "Address", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -472,65 +472,17 @@ func (ec *executionContext) _Address_country(ctx context.Context, field graphql. res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -var customerImplementors = []string{"Customer"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, obj *Customer) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, customerImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Customer") - case "id": - out.Values[i] = ec._Customer_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._Customer_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "address": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Customer_address(ctx, field, obj) - wg.Done() - }(i, field) - case "orders": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Customer_orders(ctx, field, obj) - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) _Customer_id(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Customer", - Args: nil, - Field: field, + Object: "Customer", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -547,17 +499,17 @@ func (ec *executionContext) _Customer_id(ctx context.Context, field graphql.Coll res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Customer_name(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Customer", - Args: nil, - Field: field, + Object: "Customer", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -574,17 +526,17 @@ func (ec *executionContext) _Customer_name(ctx context.Context, field graphql.Co res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Customer_address(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Customer", - Args: nil, - Field: field, + Object: "Customer", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -598,22 +550,17 @@ func (ec *executionContext) _Customer_address(ctx context.Context, field graphql res := resTmp.(*Address) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Address(ctx, field.Selections, res) + return ec.marshalOAddress2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐAddress(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql.CollectedField, obj *Customer) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Customer", - Args: nil, - Field: field, + Object: "Customer", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -627,80 +574,17 @@ func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql. res := resTmp.([]Order) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Order(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var itemImplementors = []string{"Item"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj *Item) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, itemImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Item") - case "name": - out.Values[i] = ec._Item_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOOrder2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐOrder(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Item_name(ctx context.Context, field graphql.CollectedField, obj *Item) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Item", - Args: nil, - Field: field, + Object: "Item", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -717,64 +601,17 @@ func (ec *executionContext) _Item_name(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -var orderImplementors = []string{"Order"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, obj *Order) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, orderImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Order") - case "id": - out.Values[i] = ec._Order_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "date": - out.Values[i] = ec._Order_date(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "amount": - out.Values[i] = ec._Order_amount(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "items": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Order_items(ctx, field, obj) - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Order_id(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Order", - Args: nil, - Field: field, + Object: "Order", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -791,17 +628,17 @@ func (ec *executionContext) _Order_id(ctx context.Context, field graphql.Collect res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Order_date(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Order", - Args: nil, - Field: field, + Object: "Order", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -818,17 +655,17 @@ func (ec *executionContext) _Order_date(ctx context.Context, field graphql.Colle res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalTime(res) + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Order_amount(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Order", - Args: nil, - Field: field, + Object: "Order", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -845,17 +682,17 @@ func (ec *executionContext) _Order_amount(ctx context.Context, field graphql.Col res := resTmp.(float64) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return ec.marshalNFloat2float64(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Order_items(ctx context.Context, field graphql.CollectedField, obj *Order) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Order", - Args: nil, - Field: field, + Object: "Order", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -869,102 +706,17 @@ func (ec *executionContext) _Order_items(ctx context.Context, field graphql.Coll res := resTmp.([]Item) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Item(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "customers": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_customers(ctx, field) - wg.Done() - }(i, field) - case "torture1d": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_torture1d(ctx, field) - wg.Done() - }(i, field) - case "torture2d": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_torture2d(ctx, field) - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalOItem2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐItem(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_customers(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -978,58 +730,26 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. res := resTmp.([]Customer) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Customer(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalOCustomer2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_torture1d(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_torture1d_args(rawArgs) + args, err := ec.field_Query_torture1d_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1041,58 +761,26 @@ func (ec *executionContext) _Query_torture1d(ctx context.Context, field graphql. res := resTmp.([]Customer) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Customer(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalOCustomer2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_torture2d(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_torture2d_args(rawArgs) + args, err := ec.field_Query_torture2d_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1104,89 +792,26 @@ func (ec *executionContext) _Query_torture2d(ctx context.Context, field graphql. res := resTmp.([][]Customer) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - arr2 := make(graphql.Array, len(res[idx1])) - - isLen1 := len(res[idx1]) == 1 - if !isLen1 { - wg.Add(len(res[idx1])) - } - - for idx2 := range res[idx1] { - idx2 := idx2 - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: &res[idx1][idx2], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx2 int) { - if !isLen1 { - defer wg.Done() - } - arr2[idx2] = func() graphql.Marshaler { - - return ec._Customer(ctx, field.Selections, &res[idx1][idx2]) - }() - } - if isLen1 { - f(idx2) - } else { - go f(idx2) - } - - } - - return arr2 - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalOCustomer2ᚕᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1198,22 +823,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1227,64 +847,17 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1301,17 +874,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1325,17 +898,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1352,26 +925,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1388,89 +952,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1487,17 +979,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1511,17 +1003,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1538,17 +1030,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1562,70 +1054,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1642,17 +1081,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1666,17 +1105,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1693,50 +1132,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1753,25 +1159,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1788,17 +1186,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1812,60 +1210,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1882,17 +1237,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1906,17 +1261,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1933,25 +1288,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1965,125 +1312,44 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return graphql.MarshalString(*res) + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2100,25 +1366,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2132,22 +1390,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2161,22 +1414,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2193,96 +1441,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2299,17 +1468,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2323,21 +1492,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2351,25 +1516,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2381,50 +1547,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2438,50 +1571,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2495,58 +1595,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2558,189 +1626,1276 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var addressImplementors = []string{"Address"} + +func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, obj *Address) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, addressImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Address") + case "id": + out.Values[i] = ec._Address_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "street": + out.Values[i] = ec._Address_street(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "country": + out.Values[i] = ec._Address_country(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var customerImplementors = []string{"Customer"} + +func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, obj *Customer) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, customerImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Customer") + case "id": + out.Values[i] = ec._Customer_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec._Customer_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "address": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Customer_address(ctx, field, obj) + return res + }) + case "orders": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Customer_orders(ctx, field, obj) + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var itemImplementors = []string{"Item"} + +func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj *Item) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, itemImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Item") + case "name": + out.Values[i] = ec._Item_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var orderImplementors = []string{"Order"} + +func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, obj *Order) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, orderImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Order") + case "id": + out.Values[i] = ec._Order_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "date": + out.Values[i] = ec._Order_date(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "amount": + out.Values[i] = ec._Order_amount(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "items": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Order_items(ctx, field, obj) + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "customers": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_customers(ctx, field) + return res + }) + case "torture1d": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_torture1d(ctx, field) + return res + }) + case "torture2d": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_torture2d(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) marshalNCustomer2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx context.Context, sel ast.SelectionSet, v Customer) graphql.Marshaler { + return ec._Customer(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNFloat2float64(ctx context.Context, v interface{}) (float64, error) { + return graphql.UnmarshalFloat(v) +} + +func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { + return graphql.MarshalFloat(v) +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) marshalNItem2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐItem(ctx context.Context, sel ast.SelectionSet, v Item) graphql.Marshaler { + return ec._Item(ctx, sel, &v) +} + +func (ec *executionContext) marshalNOrder2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐOrder(ctx context.Context, sel ast.SelectionSet, v Order) graphql.Marshaler { + return ec._Order(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) +} + +func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return graphql.MarshalTime(v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalOAddress2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐAddress(ctx context.Context, sel ast.SelectionSet, v Address) graphql.Marshaler { + return ec._Address(ctx, sel, &v) +} + +func (ec *executionContext) marshalOAddress2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐAddress(ctx context.Context, sel ast.SelectionSet, v *Address) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Address(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) marshalOCustomer2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx context.Context, sel ast.SelectionSet, v []Customer) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCustomer2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) marshalOCustomer2ᚕᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx context.Context, sel ast.SelectionSet, v [][]Customer) graphql.Marshaler { + if v == nil { + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.InputFields(), nil - }) - if resTmp == nil { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOCustomer2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐCustomer(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalOInt2ᚕint(ctx context.Context, v interface{}) ([]int, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]int, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNInt2int(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOInt2ᚕint(ctx context.Context, sel ast.SelectionSet, v []int) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNInt2int(ctx, sel, v[i]) + } - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup + return ret +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) unmarshalOInt2ᚕᚕint(ctx context.Context, v interface{}) ([][]int, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([][]int, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalOInt2ᚕint(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOInt2ᚕᚕint(ctx context.Context, sel ast.SelectionSet, v [][]int) graphql.Marshaler { + if v == nil { + return graphql.Null } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalOInt2ᚕint(ctx, sel, v[i]) + } + + return ret +} - for idx1 := range res { - idx1 := idx1 +func (ec *executionContext) marshalOItem2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐItem(ctx context.Context, sel ast.SelectionSet, v []Item) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { + ret[i] = ec.marshalNItem2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐItem(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - return ec.___InputValue(ctx, field.Selections, &res[idx1]) + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalOOrder2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐOrder(ctx context.Context, sel ast.SelectionSet, v []Order) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNOrder2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋdataloaderᚐOrder(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.OfType(), nil - }) - if resTmp == nil { + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, sel, *v) +} - if res == nil { +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { return graphql.Null } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - return ec.___Type(ctx, field.Selections, res) + } + wg.Wait() + return ret } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + } - return res + wg.Wait() + return ret } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null } - return introspection.WrapSchema(parsedSchema), nil -} + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + wg.Wait() + return ret } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `type Query { - customers: [Customer!] - - # these methods are here to test code generation of nested arrays - torture1d(customerIds: [Int!]): [Customer!] - torture2d(customerIds: [[Int!]]): [[Customer!]] +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) } -type Customer { - id: Int! - name: String! - address: Address - orders: [Order!] +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) } -type Address { - id: Int! - street: String! - country: String! +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) } -type Order { - id: Int! - date: Time! - amount: Float! - items: [Item!] +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret } -type Item { - name: String! +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) } -scalar Time -`}, -) + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/dataloader/itemsliceloader_gen.go b/example/dataloader/itemsliceloader_gen.go index 55620a5056..5fa1007840 100644 --- a/example/dataloader/itemsliceloader_gen.go +++ b/example/dataloader/itemsliceloader_gen.go @@ -7,6 +7,27 @@ import ( "time" ) +// ItemSliceLoaderConfig captures the config to create a new ItemSliceLoader +type ItemSliceLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []int) ([][]Item, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewItemSliceLoader creates a new ItemSliceLoader given a fetch, wait, and maxBatch +func NewItemSliceLoader(config ItemSliceLoaderConfig) *ItemSliceLoader { + return &ItemSliceLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // ItemSliceLoader batches and caches requests type ItemSliceLoader struct { // this method provides the data for the loader diff --git a/example/dataloader/ordersliceloader_gen.go b/example/dataloader/ordersliceloader_gen.go index 432559040d..e76e24d31f 100644 --- a/example/dataloader/ordersliceloader_gen.go +++ b/example/dataloader/ordersliceloader_gen.go @@ -7,6 +7,27 @@ import ( "time" ) +// OrderSliceLoaderConfig captures the config to create a new OrderSliceLoader +type OrderSliceLoaderConfig struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []int) ([][]Order, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// NewOrderSliceLoader creates a new OrderSliceLoader given a fetch, wait, and maxBatch +func NewOrderSliceLoader(config OrderSliceLoaderConfig) *OrderSliceLoader { + return &OrderSliceLoader{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // OrderSliceLoader batches and caches requests type OrderSliceLoader struct { // this method provides the data for the loader diff --git a/example/dataloader/resolvers.go b/example/dataloader/resolvers.go index 8c132b1f28..956251cdb0 100644 --- a/example/dataloader/resolvers.go +++ b/example/dataloader/resolvers.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package dataloader diff --git a/example/scalars/.gqlgen.yml b/example/scalars/.gqlgen.yml index c49b8f70ef..e92ce20865 100644 --- a/example/scalars/.gqlgen.yml +++ b/example/scalars/.gqlgen.yml @@ -14,3 +14,5 @@ models: model: github.com/99designs/gqlgen/example/scalars/model.ID Tier: model: github.com/99designs/gqlgen/example/scalars/model.Tier + Banned: + model: github.com/99designs/gqlgen/example/scalars/model.Banned diff --git a/example/scalars/vendor/external/model.go b/example/scalars/external/model.go similarity index 100% rename from example/scalars/vendor/external/model.go rename to example/scalars/external/model.go diff --git a/example/scalars/generated.go b/example/scalars/generated.go index af67c2b40d..e611828ae3 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -6,11 +6,11 @@ import ( "bytes" "context" "errors" - "external" "strconv" "sync" "time" + "github.com/99designs/gqlgen/example/scalars/external" "github.com/99designs/gqlgen/example/scalars/model" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" @@ -18,6 +18,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -43,23 +45,23 @@ type DirectiveRoot struct { type ComplexityRoot struct { Address struct { - Id func(childComplexity int) int + ID func(childComplexity int) int Location func(childComplexity int) int } Query struct { - User func(childComplexity int, id external.ObjectID) int Search func(childComplexity int, input *model.SearchArgs) int + User func(childComplexity int, id external.ObjectID) int } User struct { - Id func(childComplexity int) int - Name func(childComplexity int) int + Address func(childComplexity int) int Created func(childComplexity int) int + CustomResolver func(childComplexity int) int + ID func(childComplexity int) int IsBanned func(childComplexity int) int + Name func(childComplexity int) int PrimitiveResolver func(childComplexity int) int - CustomResolver func(childComplexity int) int - Address func(childComplexity int) int Tier func(childComplexity int) int } } @@ -70,87 +72,7 @@ type QueryResolver interface { } type UserResolver interface { PrimitiveResolver(ctx context.Context, obj *model.User) (string, error) - CustomResolver(ctx context.Context, obj *model.User) (model.Point, error) -} - -func field_Query_user_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 external.ObjectID - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = model.UnmarshalID(tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - return args, nil - -} - -func field_Query_search_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *model.SearchArgs - if tmp, ok := rawArgs["input"]; ok { - var err error - var ptr1 model.SearchArgs - if tmp != nil { - ptr1, err = UnmarshalSearchArgs(tmp) - arg0 = &ptr1 - } - - if err != nil { - return nil, err - } - } - args["input"] = arg0 - return args, nil - -} - -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - + CustomResolver(ctx context.Context, obj *model.User) (*model.Point, error) } type executableSchema struct { @@ -164,96 +86,98 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Address.id": - if e.complexity.Address.Id == nil { + case "Address.ID": + if e.complexity.Address.ID == nil { break } - return e.complexity.Address.Id(childComplexity), true + return e.complexity.Address.ID(childComplexity), true - case "Address.location": + case "Address.Location": if e.complexity.Address.Location == nil { break } return e.complexity.Address.Location(childComplexity), true - case "Query.user": - if e.complexity.Query.User == nil { + case "Query.Search": + if e.complexity.Query.Search == nil { break } - args, err := field_Query_user_args(rawArgs) + args, err := ec.field_Query_search_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.User(childComplexity, args["id"].(external.ObjectID)), true + return e.complexity.Query.Search(childComplexity, args["input"].(*model.SearchArgs)), true - case "Query.search": - if e.complexity.Query.Search == nil { + case "Query.User": + if e.complexity.Query.User == nil { break } - args, err := field_Query_search_args(rawArgs) + args, err := ec.field_Query_user_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Search(childComplexity, args["input"].(*model.SearchArgs)), true + return e.complexity.Query.User(childComplexity, args["id"].(external.ObjectID)), true - case "User.id": - if e.complexity.User.Id == nil { + case "User.Address": + if e.complexity.User.Address == nil { break } - return e.complexity.User.Id(childComplexity), true + return e.complexity.User.Address(childComplexity), true - case "User.name": - if e.complexity.User.Name == nil { + case "User.Created": + if e.complexity.User.Created == nil { break } - return e.complexity.User.Name(childComplexity), true + return e.complexity.User.Created(childComplexity), true - case "User.created": - if e.complexity.User.Created == nil { + case "User.CustomResolver": + if e.complexity.User.CustomResolver == nil { break } - return e.complexity.User.Created(childComplexity), true + return e.complexity.User.CustomResolver(childComplexity), true - case "User.isBanned": - if e.complexity.User.IsBanned == nil { + case "User.ID": + if e.complexity.User.ID == nil { break } - return e.complexity.User.IsBanned(childComplexity), true + return e.complexity.User.ID(childComplexity), true - case "User.primitiveResolver": - if e.complexity.User.PrimitiveResolver == nil { + case "User.IsBanned": + if e.complexity.User.IsBanned == nil { break } - return e.complexity.User.PrimitiveResolver(childComplexity), true + return e.complexity.User.IsBanned(childComplexity), true - case "User.customResolver": - if e.complexity.User.CustomResolver == nil { + case "User.Name": + if e.complexity.User.Name == nil { break } - return e.complexity.User.CustomResolver(childComplexity), true + return e.complexity.User.Name(childComplexity), true - case "User.address": - if e.complexity.User.Address == nil { + case "User.PrimitiveResolver": + if e.complexity.User.PrimitiveResolver == nil { break } - return e.complexity.User.Address(childComplexity), true + return e.complexity.User.PrimitiveResolver(childComplexity), true - case "User.tier": + case "User.Tier": if e.complexity.User.Tier == nil { break } @@ -277,7 +201,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -293,46 +218,161 @@ type executionContext struct { *executableSchema } -var addressImplementors = []string{"Address"} +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil + } + return res +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, obj *model.Address) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, addressImplementors) +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Address") - case "id": - out.Values[i] = ec._Address_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "location": - out.Values[i] = ec._Address_location(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `type Query { + user(id: ID!): User + search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! +} + +type User { + id: ID! + name: String! + created: Timestamp + isBanned: Banned! + primitiveResolver: String! + customResolver: Point! + address: Address + tier: Tier +} + +type Address { + id: ID! + location: Point +} + +input SearchArgs { + location: Point + createdAfter: Timestamp + isBanned: Banned # TODO: This can be a Boolean again once multiple backing types are allowed +} + +enum Tier { + A + B + C +} + +scalar Timestamp +scalar Point +scalar Banned +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_search_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *model.SearchArgs + if tmp, ok := rawArgs["input"]; ok { + arg0, err = ec.unmarshalOSearchArgs2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐSearchArgs(ctx, tmp) + if err != nil { + return nil, err } } + args["input"] = arg0 + return args, nil +} - if invalid { - return graphql.Null +func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 external.ObjectID + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋexternalᚐObjectID(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil } -// nolint: vetshadow +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + func (ec *executionContext) _Address_id(ctx context.Context, field graphql.CollectedField, obj *model.Address) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Address", - Args: nil, - Field: field, + Object: "Address", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -349,17 +389,17 @@ func (ec *executionContext) _Address_id(ctx context.Context, field graphql.Colle res := resTmp.(external.ObjectID) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return model.MarshalID(res) + return ec.marshalNID2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋexternalᚐObjectID(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Address_location(ctx context.Context, field graphql.CollectedField, obj *model.Address) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Address", - Args: nil, - Field: field, + Object: "Address", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -373,78 +413,26 @@ func (ec *executionContext) _Address_location(ctx context.Context, field graphql res := resTmp.(*model.Point) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_user_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) return graphql.Null } - return *res -} - -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "user": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_user(ctx, field) - wg.Done() - }(i, field) - case "search": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_search(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_user_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -456,30 +444,26 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle res := resTmp.(*model.User) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._User(ctx, field.Selections, res) + return ec.marshalOUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_search_args(rawArgs) + args, err := ec.field_Query_search_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -494,58 +478,26 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col res := resTmp.([]model.User) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._User(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalNUser2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -557,22 +509,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -586,87 +533,17 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) -} - -var userImplementors = []string{"User"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *model.User) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, userImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("User") - case "id": - out.Values[i] = ec._User_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._User_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "created": - out.Values[i] = ec._User_created(ctx, field, obj) - case "isBanned": - out.Values[i] = ec._User_isBanned(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "primitiveResolver": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._User_primitiveResolver(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "customResolver": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._User_customResolver(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "address": - out.Values[i] = ec._User_address(ctx, field, obj) - case "tier": - out.Values[i] = ec._User_tier(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -683,17 +560,17 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte res := resTmp.(external.ObjectID) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return model.MarshalID(res) + return ec.marshalNID2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋexternalᚐObjectID(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -710,17 +587,17 @@ func (ec *executionContext) _User_name(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_created(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -734,17 +611,17 @@ func (ec *executionContext) _User_created(ctx context.Context, field graphql.Col res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return model.MarshalTimestamp(res) + return ec.marshalOTimestamp2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_isBanned(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -761,17 +638,17 @@ func (ec *executionContext) _User_isBanned(ctx context.Context, field graphql.Co res := resTmp.(model.Banned) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(bool(res)) + return ec.marshalNBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -788,17 +665,17 @@ func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field g res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_customResolver(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -812,20 +689,20 @@ func (ec *executionContext) _User_customResolver(ctx context.Context, field grap } return graphql.Null } - res := resTmp.(model.Point) + res := resTmp.(*model.Point) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return res + return ec.marshalNPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_address(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -839,18 +716,17 @@ func (ec *executionContext) _User_address(ctx context.Context, field graphql.Col res := resTmp.(model.Address) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Address(ctx, field.Selections, &res) + return ec.marshalOAddress2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐAddress(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _User_tier(ctx context.Context, field graphql.CollectedField, obj *model.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -864,59 +740,17 @@ func (ec *executionContext) _User_tier(ctx context.Context, field graphql.Collec res := resTmp.(model.Tier) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return res -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOTier2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐTier(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -933,17 +767,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -957,17 +791,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -984,26 +818,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1020,89 +845,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1119,17 +872,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1143,17 +896,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1170,17 +923,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1194,70 +947,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1274,17 +974,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1298,17 +998,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1325,50 +1025,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1385,25 +1052,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1420,17 +1079,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1444,60 +1103,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1514,17 +1130,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1538,17 +1154,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1565,25 +1181,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1597,65 +1205,17 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1672,50 +1232,17 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1732,25 +1259,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1764,22 +1283,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1793,22 +1307,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1825,96 +1334,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1931,17 +1361,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1955,21 +1385,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1983,25 +1409,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2013,50 +1440,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2070,50 +1464,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2127,58 +1488,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2190,50 +1519,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2247,50 +1543,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2304,15 +1567,14 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } +// endregion **************************** field.gotpl ***************************** - return ec.___Type(ctx, field.Selections, res) -} +// region **************************** input.gotpl ***************************** -func UnmarshalSearchArgs(v interface{}) (model.SearchArgs, error) { +func (ec *executionContext) unmarshalInputSearchArgs(ctx context.Context, v interface{}) (model.SearchArgs, error) { var it model.SearchArgs var asMap = v.(map[string]interface{}) @@ -2320,32 +1582,19 @@ func UnmarshalSearchArgs(v interface{}) (model.SearchArgs, error) { switch k { case "location": var err error - var ptr1 model.Point - if v != nil { - err = (&ptr1).UnmarshalGQL(v) - it.Location = &ptr1 - } - + it.Location, err = ec.unmarshalOPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx, v) if err != nil { return it, err } case "createdAfter": var err error - var ptr1 time.Time - if v != nil { - ptr1, err = model.UnmarshalTimestamp(v) - it.CreatedAfter = &ptr1 - } - + it.CreatedAfter, err = ec.unmarshalOTimestamp2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } case "isBanned": var err error - - var castTmp bool - castTmp, err = graphql.UnmarshalBoolean(v) - it.IsBanned = model.Banned(castTmp) + it.IsBanned, err = ec.unmarshalOBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx, v) if err != nil { return it, err } @@ -2355,70 +1604,1050 @@ func UnmarshalSearchArgs(v interface{}) (model.SearchArgs, error) { return it, nil } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var addressImplementors = []string{"Address"} + +func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, obj *model.Address) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, addressImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Address") + case "id": + out.Values[i] = ec._Address_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "location": + out.Values[i] = ec._Address_location(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil } - return res -} - -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") + out.Dispatch() + if invalid { + return graphql.Null } - return introspection.WrapSchema(parsedSchema), nil + return out } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") - } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil -} +var queryImplementors = []string{"Query"} -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `type Query { - user(id: ID!): User - search(input: SearchArgs = {location: "37,144", isBanned: false}): [User!]! -} +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) -type User { - id: ID! - name: String! - created: Timestamp - isBanned: Boolean! - primitiveResolver: String! - customResolver: Point! - address: Address - tier: Tier -} + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) -type Address { - id: ID! - location: Point + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "user": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_user(ctx, field) + return res + }) + case "search": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_search(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -input SearchArgs { - location: Point - createdAfter: Timestamp - isBanned: Boolean -} +var userImplementors = []string{"User"} -enum Tier { - A - B - C -} +func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *model.User) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, userImplementors) -scalar Timestamp -scalar Point -`}, -) + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("User") + case "id": + out.Values[i] = ec._User_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "created": + out.Values[i] = ec._User_created(ctx, field, obj) + case "isBanned": + out.Values[i] = ec._User_isBanned(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "primitiveResolver": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._User_primitiveResolver(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "customResolver": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._User_customResolver(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "address": + out.Values[i] = ec._User_address(ctx, field, obj) + case "tier": + out.Values[i] = ec._User_tier(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx context.Context, v interface{}) (model.Banned, error) { + var res model.Banned + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx context.Context, sel ast.SelectionSet, v model.Banned) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNID2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋexternalᚐObjectID(ctx context.Context, v interface{}) (external.ObjectID, error) { + return model.UnmarshalID(v) +} + +func (ec *executionContext) marshalNID2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋexternalᚐObjectID(ctx context.Context, sel ast.SelectionSet, v external.ObjectID) graphql.Marshaler { + return model.MarshalID(v) +} + +func (ec *executionContext) unmarshalNPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, v interface{}) (model.Point, error) { + var res model.Point + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, sel ast.SelectionSet, v model.Point) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalNPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, v interface{}) (*model.Point, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalNPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalNPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, sel ast.SelectionSet, v *model.Point) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v model.User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} + +func (ec *executionContext) marshalNUser2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v []model.User) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNUser2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalOAddress2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐAddress(ctx context.Context, sel ast.SelectionSet, v model.Address) graphql.Marshaler { + return ec._Address(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalOBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx context.Context, v interface{}) (model.Banned, error) { + var res model.Banned + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOBanned2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐBanned(ctx context.Context, sel ast.SelectionSet, v model.Banned) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, v interface{}) (model.Point, error) { + var res model.Point + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, sel ast.SelectionSet, v model.Point) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, v interface{}) (*model.Point, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOPoint2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOPoint2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐPoint(ctx context.Context, sel ast.SelectionSet, v *model.Point) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalOSearchArgs2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐSearchArgs(ctx context.Context, v interface{}) (model.SearchArgs, error) { + return ec.unmarshalInputSearchArgs(ctx, v) +} + +func (ec *executionContext) unmarshalOSearchArgs2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐSearchArgs(ctx context.Context, v interface{}) (*model.SearchArgs, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOSearchArgs2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐSearchArgs(ctx, v) + return &res, err +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOTier2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐTier(ctx context.Context, v interface{}) (model.Tier, error) { + var res model.Tier + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOTier2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐTier(ctx context.Context, sel ast.SelectionSet, v model.Tier) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOTimestamp2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return model.UnmarshalTimestamp(v) +} + +func (ec *executionContext) marshalOTimestamp2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + return graphql.Null + } + return model.MarshalTimestamp(v) +} + +func (ec *executionContext) unmarshalOTimestamp2ᚖtimeᚐTime(ctx context.Context, v interface{}) (*time.Time, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOTimestamp2timeᚐTime(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOTimestamp2ᚖtimeᚐTime(ctx context.Context, sel ast.SelectionSet, v *time.Time) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOTimestamp2timeᚐTime(ctx, sel, *v) +} + +func (ec *executionContext) marshalOUser2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v model.User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} + +func (ec *executionContext) marshalOUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋscalarsᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v *model.User) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._User(ctx, sel, v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/scalars/model/generated.go b/example/scalars/model/generated.go index a79b765819..2ee63fc8ab 100644 --- a/example/scalars/model/generated.go +++ b/example/scalars/model/generated.go @@ -3,7 +3,7 @@ package model import ( - "external" + "github.com/99designs/gqlgen/example/scalars/external" ) type Address struct { diff --git a/example/scalars/model/model.go b/example/scalars/model/model.go index a98134f197..d95cb8ff39 100644 --- a/example/scalars/model/model.go +++ b/example/scalars/model/model.go @@ -8,18 +8,38 @@ import ( "strings" "time" - "external" - + "github.com/99designs/gqlgen/example/scalars/external" "github.com/99designs/gqlgen/graphql" ) type Banned bool +func (b Banned) MarshalGQL(w io.Writer) { + if b { + w.Write([]byte("true")) + } else { + w.Write([]byte("false")) + } +} + +func (b *Banned) UnmarshalGQL(v interface{}) error { + switch v := v.(type) { + case string: + *b = strings.ToLower(v) == "true" + return nil + case bool: + *b = Banned(v) + return nil + default: + return fmt.Errorf("%T is not a bool", v) + } +} + type User struct { ID external.ObjectID Name string Created time.Time // direct binding to builtin types with external Marshal/Unmarshal methods - IsBanned Banned // aliased primitive + IsBanned Banned Address Address Tier Tier } diff --git a/example/scalars/resolvers.go b/example/scalars/resolvers.go index af7c62122e..c723b0d544 100644 --- a/example/scalars/resolvers.go +++ b/example/scalars/resolvers.go @@ -1,13 +1,13 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package scalars import ( context "context" - "external" "fmt" time "time" + "github.com/99designs/gqlgen/example/scalars/external" "github.com/99designs/gqlgen/example/scalars/model" ) @@ -69,6 +69,6 @@ func (r *userResolver) PrimitiveResolver(ctx context.Context, obj *model.User) ( return "test", nil } -func (r *userResolver) CustomResolver(ctx context.Context, obj *model.User) (model.Point, error) { - return model.Point{X: 5, Y: 1}, nil +func (r *userResolver) CustomResolver(ctx context.Context, obj *model.User) (*model.Point, error) { + return &model.Point{X: 5, Y: 1}, nil } diff --git a/example/scalars/scalar_test.go b/example/scalars/scalar_test.go index 77afbdbe26..15ac529070 100644 --- a/example/scalars/scalar_test.go +++ b/example/scalars/scalar_test.go @@ -61,7 +61,7 @@ func TestScalars(t *testing.T) { var resp struct{ Search []RawUser } err := c.Post(`{ search(input:{createdAfter:"2014"}) { id } }`, &resp) - require.EqualError(t, err, `[{"message":"time should be a unix timestamp"}]`) + require.EqualError(t, err, `[{"message":"time should be a unix timestamp","path":["search"]}]`) }) t.Run("scalar resolver methods", func(t *testing.T) { diff --git a/example/scalars/schema.graphql b/example/scalars/schema.graphql index 032e3f3a99..2bf00540ff 100644 --- a/example/scalars/schema.graphql +++ b/example/scalars/schema.graphql @@ -7,7 +7,7 @@ type User { id: ID! name: String! created: Timestamp - isBanned: Boolean! + isBanned: Banned! primitiveResolver: String! customResolver: Point! address: Address @@ -22,7 +22,7 @@ type Address { input SearchArgs { location: Point createdAfter: Timestamp - isBanned: Boolean + isBanned: Banned # TODO: This can be a Boolean again once multiple backing types are allowed } enum Tier { @@ -33,3 +33,4 @@ enum Tier { scalar Timestamp scalar Point +scalar Banned diff --git a/example/scalars/vendor/readme.md b/example/scalars/vendor/readme.md deleted file mode 100644 index a7ae70d827..0000000000 --- a/example/scalars/vendor/readme.md +++ /dev/null @@ -1 +0,0 @@ -fake vendor directory for scalar tests. diff --git a/example/selection/.gqlgen.yml b/example/selection/.gqlgen.yml new file mode 100644 index 0000000000..846418d6bc --- /dev/null +++ b/example/selection/.gqlgen.yml @@ -0,0 +1,5 @@ +schema: schema.graphql +model: + filename: models_gen.go +exec: + filename: generated.go diff --git a/example/selection/generated.go b/example/selection/generated.go index b8f99c7e32..18a99e88ba 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -17,6 +17,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -41,17 +43,17 @@ type DirectiveRoot struct { type ComplexityRoot struct { Like struct { + Collected func(childComplexity int) int Reaction func(childComplexity int) int - Sent func(childComplexity int) int Selection func(childComplexity int) int - Collected func(childComplexity int) int + Sent func(childComplexity int) int } Post struct { + Collected func(childComplexity int) int Message func(childComplexity int) int - Sent func(childComplexity int) int Selection func(childComplexity int) int - Collected func(childComplexity int) int + Sent func(childComplexity int) int } Query struct { @@ -63,51 +65,6 @@ type QueryResolver interface { Events(ctx context.Context) ([]Event, error) } -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -119,65 +76,67 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Like.reaction": - if e.complexity.Like.Reaction == nil { + case "Like.Collected": + if e.complexity.Like.Collected == nil { break } - return e.complexity.Like.Reaction(childComplexity), true + return e.complexity.Like.Collected(childComplexity), true - case "Like.sent": - if e.complexity.Like.Sent == nil { + case "Like.Reaction": + if e.complexity.Like.Reaction == nil { break } - return e.complexity.Like.Sent(childComplexity), true + return e.complexity.Like.Reaction(childComplexity), true - case "Like.selection": + case "Like.Selection": if e.complexity.Like.Selection == nil { break } return e.complexity.Like.Selection(childComplexity), true - case "Like.collected": - if e.complexity.Like.Collected == nil { + case "Like.Sent": + if e.complexity.Like.Sent == nil { break } - return e.complexity.Like.Collected(childComplexity), true + return e.complexity.Like.Sent(childComplexity), true - case "Post.message": - if e.complexity.Post.Message == nil { + case "Post.Collected": + if e.complexity.Post.Collected == nil { break } - return e.complexity.Post.Message(childComplexity), true + return e.complexity.Post.Collected(childComplexity), true - case "Post.sent": - if e.complexity.Post.Sent == nil { + case "Post.Message": + if e.complexity.Post.Message == nil { break } - return e.complexity.Post.Sent(childComplexity), true + return e.complexity.Post.Message(childComplexity), true - case "Post.selection": + case "Post.Selection": if e.complexity.Post.Selection == nil { break } return e.complexity.Post.Selection(childComplexity), true - case "Post.collected": - if e.complexity.Post.Collected == nil { + case "Post.Sent": + if e.complexity.Post.Sent == nil { break } - return e.complexity.Post.Collected(childComplexity), true + return e.complexity.Post.Sent(childComplexity), true - case "Query.events": + case "Query.Events": if e.complexity.Query.Events == nil { break } @@ -201,7 +160,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -217,53 +177,121 @@ type executionContext struct { *executableSchema } -var likeImplementors = []string{"Like", "Event"} +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil + } + return res +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj *Like) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, likeImplementors) +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Like") - case "reaction": - out.Values[i] = ec._Like_reaction(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "sent": - out.Values[i] = ec._Like_sent(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "selection": - out.Values[i] = ec._Like_selection(ctx, field, obj) - case "collected": - out.Values[i] = ec._Like_collected(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `interface Event { + selection: [String!] + collected: [String!] +} + +type Post implements Event { + message: String! + sent: Time! + selection: [String!] + collected: [String!] +} + +type Like implements Event { + reaction: String! + sent: Time! + selection: [String!] + collected: [String!] +} + +type Query { + events: [Event!] +} + +scalar Time +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err } } + args["name"] = arg0 + return args, nil +} - if invalid { - return graphql.Null +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil } -// nolint: vetshadow +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + func (ec *executionContext) _Like_reaction(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Like", - Args: nil, - Field: field, + Object: "Like", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -280,17 +308,17 @@ func (ec *executionContext) _Like_reaction(ctx context.Context, field graphql.Co res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Like_sent(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Like", - Args: nil, - Field: field, + Object: "Like", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -307,17 +335,17 @@ func (ec *executionContext) _Like_sent(ctx context.Context, field graphql.Collec res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalTime(res) + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Like_selection(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Like", - Args: nil, - Field: field, + Object: "Like", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -331,26 +359,17 @@ func (ec *executionContext) _Like_selection(ctx context.Context, field graphql.C res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalOString2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Like_collected(ctx context.Context, field graphql.CollectedField, obj *Like) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Like", - Args: nil, - Field: field, + Object: "Like", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -364,65 +383,17 @@ func (ec *executionContext) _Like_collected(ctx context.Context, field graphql.C res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 -} - -var postImplementors = []string{"Post", "Event"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj *Post) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, postImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Post") - case "message": - out.Values[i] = ec._Post_message(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "sent": - out.Values[i] = ec._Post_sent(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "selection": - out.Values[i] = ec._Post_selection(ctx, field, obj) - case "collected": - out.Values[i] = ec._Post_collected(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Post_message(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Post", - Args: nil, - Field: field, + Object: "Post", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -439,17 +410,17 @@ func (ec *executionContext) _Post_message(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Post_sent(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Post", - Args: nil, - Field: field, + Object: "Post", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -466,17 +437,17 @@ func (ec *executionContext) _Post_sent(ctx context.Context, field graphql.Collec res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalTime(res) + return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Post_selection(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Post", - Args: nil, - Field: field, + Object: "Post", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -490,26 +461,17 @@ func (ec *executionContext) _Post_selection(ctx context.Context, field graphql.C res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalOString2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Post_collected(ctx context.Context, field graphql.CollectedField, obj *Post) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Post", - Args: nil, - Field: field, + Object: "Post", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -523,131 +485,50 @@ func (ec *executionContext) _Post_collected(ctx context.Context, field graphql.C res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚕstring(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() +func (ec *executionContext) _Query_events(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } - - return arr1 + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Events(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]Event) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOEvent2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋselectionᚐEvent(ctx, field.Selections, res) } -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "events": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_events(ctx, field) - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) _Query_events(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Events(rctx) - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.([]Event) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Event(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -659,22 +540,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -688,64 +564,17 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -762,17 +591,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -786,17 +615,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -813,26 +642,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -849,89 +669,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -948,17 +696,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -972,17 +720,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -999,17 +747,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1023,70 +771,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1103,17 +798,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1127,17 +822,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1154,50 +849,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1214,25 +876,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1249,17 +903,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1273,60 +927,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1343,17 +954,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1367,17 +978,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1394,25 +1005,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1426,65 +1029,17 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1501,50 +1056,17 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1561,25 +1083,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1593,22 +1107,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1622,22 +1131,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1654,96 +1158,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1760,17 +1185,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1784,21 +1209,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1812,25 +1233,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1842,50 +1264,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1899,50 +1288,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1956,58 +1312,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2019,50 +1343,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2076,50 +1367,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2133,13 +1391,16 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } +// endregion **************************** field.gotpl ***************************** - return ec.___Type(ctx, field.Selections, res) -} +// region **************************** input.gotpl ***************************** + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** func (ec *executionContext) _Event(ctx context.Context, sel ast.SelectionSet, obj *Event) graphql.Marshaler { switch obj := (*obj).(type) { @@ -2158,59 +1419,914 @@ func (ec *executionContext) _Event(ctx context.Context, sel ast.SelectionSet, ob } } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var likeImplementors = []string{"Like", "Event"} + +func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj *Like) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, likeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Like") + case "reaction": + out.Values[i] = ec._Like_reaction(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "sent": + out.Values[i] = ec._Like_sent(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "selection": + out.Values[i] = ec._Like_selection(ctx, field, obj) + case "collected": + out.Values[i] = ec._Like_collected(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil } - return res + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var postImplementors = []string{"Post", "Event"} + +func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj *Post) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, postImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Post") + case "message": + out.Values[i] = ec._Post_message(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "sent": + out.Values[i] = ec._Post_sent(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "selection": + out.Values[i] = ec._Post_selection(ctx, field, obj) + case "collected": + out.Values[i] = ec._Post_collected(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapSchema(parsedSchema), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "events": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_events(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `interface Event { - selection: [String!] - collected: [String!] -} +var __DirectiveImplementors = []string{"__Directive"} -type Post implements Event { - message: String! - sent: Time! - selection: [String!] - collected: [String!] -} +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) -type Like implements Event { - reaction: String! - sent: Time! - selection: [String!] - collected: [String!] + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -type Query { - events: [Event!] -} +var __EnumValueImplementors = []string{"__EnumValue"} -scalar Time -`}, -) +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) marshalNEvent2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋselectionᚐEvent(ctx context.Context, sel ast.SelectionSet, v Event) graphql.Marshaler { + return ec._Event(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) +} + +func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return graphql.MarshalTime(v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) marshalOEvent2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋselectionᚐEvent(ctx context.Context, sel ast.SelectionSet, v []Event) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNEvent2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋselectionᚐEvent(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNString2string(ctx, sel, v[i]) + } + + return ret +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/selection/selection.go b/example/selection/selection.go index 6e83692595..e423a8a7e1 100644 --- a/example/selection/selection.go +++ b/example/selection/selection.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package selection diff --git a/example/starwars/.gqlgen.yml b/example/starwars/.gqlgen.yml index 49f10ad970..42d07800ed 100644 --- a/example/starwars/.gqlgen.yml +++ b/example/starwars/.gqlgen.yml @@ -1,14 +1,19 @@ +exec: + filename: generated/exec.go +model: + filename: models/generated.go + models: Droid: - model: github.com/99designs/gqlgen/example/starwars.Droid + model: github.com/99designs/gqlgen/example/starwars/models.Droid FriendsConnection: - model: github.com/99designs/gqlgen/example/starwars.FriendsConnection + model: github.com/99designs/gqlgen/example/starwars/models.FriendsConnection Human: - model: github.com/99designs/gqlgen/example/starwars.Human + model: github.com/99designs/gqlgen/example/starwars/models.Human Review: - model: github.com/99designs/gqlgen/example/starwars.Review + model: github.com/99designs/gqlgen/example/starwars/models.Review ReviewInput: - model: github.com/99designs/gqlgen/example/starwars.Review + model: github.com/99designs/gqlgen/example/starwars/models.Review Starship: fields: length: diff --git a/example/starwars/benchmarks_test.go b/example/starwars/benchmarks_test.go new file mode 100644 index 0000000000..f0d9e1f043 --- /dev/null +++ b/example/starwars/benchmarks_test.go @@ -0,0 +1,31 @@ +package starwars + +import ( + "net/http/httptest" + "strings" + "testing" + + "github.com/99designs/gqlgen/example/starwars/generated" + "github.com/99designs/gqlgen/handler" +) + +func BenchmarkSimpleQueryNoArgs(b *testing.B) { + server := handler.GraphQL(generated.NewExecutableSchema(NewResolver())) + + q := `{"query":"{ search(text:\"Luke\") { ... on Human { starships { name } } } }"}` + + var body strings.Reader + r := httptest.NewRequest("POST", "/graphql", &body) + + b.ResetTimer() + rec := httptest.NewRecorder() + for i := 0; i < b.N; i++ { + body.Reset(q) + rec.Body.Reset() + server.ServeHTTP(rec, r) + if rec.Body.String() != `{"data":{"search":[{"starships":[{"name":"X-Wing"},{"name":"Imperial shuttle"}]}]}}` { + b.Fatalf("Unexpected response") + } + + } +} diff --git a/example/starwars/generated.go b/example/starwars/generated/exec.go similarity index 60% rename from example/starwars/generated.go rename to example/starwars/generated/exec.go index a58a5750e6..f31dcbe29b 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated/exec.go @@ -1,6 +1,6 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package starwars +package generated import ( "bytes" @@ -11,12 +11,15 @@ import ( "sync" "time" + "github.com/99designs/gqlgen/example/starwars/models" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -46,19 +49,19 @@ type DirectiveRoot struct { type ComplexityRoot struct { Droid struct { - Id func(childComplexity int) int - Name func(childComplexity int) int + AppearsIn func(childComplexity int) int Friends func(childComplexity int) int FriendsConnection func(childComplexity int, first *int, after *string) int - AppearsIn func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int PrimaryFunction func(childComplexity int) int } FriendsConnection struct { - TotalCount func(childComplexity int) int Edges func(childComplexity int) int Friends func(childComplexity int) int PageInfo func(childComplexity int) int + TotalCount func(childComplexity int) int } FriendsEdge struct { @@ -67,714 +70,420 @@ type ComplexityRoot struct { } Human struct { - Id func(childComplexity int) int - Name func(childComplexity int) int - Height func(childComplexity int, unit LengthUnit) int - Mass func(childComplexity int) int + AppearsIn func(childComplexity int) int Friends func(childComplexity int) int FriendsConnection func(childComplexity int, first *int, after *string) int - AppearsIn func(childComplexity int) int + Height func(childComplexity int, unit models.LengthUnit) int + ID func(childComplexity int) int + Mass func(childComplexity int) int + Name func(childComplexity int) int Starships func(childComplexity int) int } Mutation struct { - CreateReview func(childComplexity int, episode Episode, review Review) int + CreateReview func(childComplexity int, episode models.Episode, review models.Review) int } PageInfo struct { - StartCursor func(childComplexity int) int EndCursor func(childComplexity int) int HasNextPage func(childComplexity int) int + StartCursor func(childComplexity int) int } Query struct { - Hero func(childComplexity int, episode *Episode) int - Reviews func(childComplexity int, episode Episode, since *time.Time) int - Search func(childComplexity int, text string) int Character func(childComplexity int, id string) int Droid func(childComplexity int, id string) int + Hero func(childComplexity int, episode *models.Episode) int Human func(childComplexity int, id string) int + Reviews func(childComplexity int, episode models.Episode, since *time.Time) int + Search func(childComplexity int, text string) int Starship func(childComplexity int, id string) int } Review struct { - Stars func(childComplexity int) int Commentary func(childComplexity int) int + Stars func(childComplexity int) int Time func(childComplexity int) int } Starship struct { - Id func(childComplexity int) int - Name func(childComplexity int) int - Length func(childComplexity int, unit *LengthUnit) int History func(childComplexity int) int + ID func(childComplexity int) int + Length func(childComplexity int, unit *models.LengthUnit) int + Name func(childComplexity int) int } } type DroidResolver interface { - Friends(ctx context.Context, obj *Droid) ([]Character, error) - FriendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (FriendsConnection, error) + Friends(ctx context.Context, obj *models.Droid) ([]models.Character, error) + FriendsConnection(ctx context.Context, obj *models.Droid, first *int, after *string) (*models.FriendsConnection, error) } type FriendsConnectionResolver interface { - Edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error) - Friends(ctx context.Context, obj *FriendsConnection) ([]Character, error) + Edges(ctx context.Context, obj *models.FriendsConnection) ([]models.FriendsEdge, error) + Friends(ctx context.Context, obj *models.FriendsConnection) ([]models.Character, error) } type HumanResolver interface { - Friends(ctx context.Context, obj *Human) ([]Character, error) - FriendsConnection(ctx context.Context, obj *Human, first *int, after *string) (FriendsConnection, error) + Friends(ctx context.Context, obj *models.Human) ([]models.Character, error) + FriendsConnection(ctx context.Context, obj *models.Human, first *int, after *string) (*models.FriendsConnection, error) - Starships(ctx context.Context, obj *Human) ([]Starship, error) + Starships(ctx context.Context, obj *models.Human) ([]models.Starship, error) } type MutationResolver interface { - CreateReview(ctx context.Context, episode Episode, review Review) (*Review, error) + CreateReview(ctx context.Context, episode models.Episode, review models.Review) (*models.Review, error) } type QueryResolver interface { - Hero(ctx context.Context, episode *Episode) (Character, error) - Reviews(ctx context.Context, episode Episode, since *time.Time) ([]Review, error) - Search(ctx context.Context, text string) ([]SearchResult, error) - Character(ctx context.Context, id string) (Character, error) - Droid(ctx context.Context, id string) (*Droid, error) - Human(ctx context.Context, id string) (*Human, error) - Starship(ctx context.Context, id string) (*Starship, error) + Hero(ctx context.Context, episode *models.Episode) (models.Character, error) + Reviews(ctx context.Context, episode models.Episode, since *time.Time) ([]models.Review, error) + Search(ctx context.Context, text string) ([]models.SearchResult, error) + Character(ctx context.Context, id string) (models.Character, error) + Droid(ctx context.Context, id string) (*models.Droid, error) + Human(ctx context.Context, id string) (*models.Human, error) + Starship(ctx context.Context, id string) (*models.Starship, error) } type StarshipResolver interface { - Length(ctx context.Context, obj *Starship, unit *LengthUnit) (float64, error) + Length(ctx context.Context, obj *models.Starship, unit *models.LengthUnit) (float64, error) } -func field_Droid_friendsConnection_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["first"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - } - - if err != nil { - return nil, err - } - } - args["first"] = arg0 - var arg1 *string - if tmp, ok := rawArgs["after"]; ok { - var err error - var ptr1 string - if tmp != nil { - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 - } - - if err != nil { - return nil, err - } - } - args["after"] = arg1 - return args, nil +type executableSchema struct { + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} +func (e *executableSchema) Schema() *ast.Schema { + return parsedSchema } -func field_Human_height_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 LengthUnit - if tmp, ok := rawArgs["unit"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return nil, err +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec + switch typeName + "." + field { + + case "Droid.AppearsIn": + if e.complexity.Droid.AppearsIn == nil { + break } - } - args["unit"] = arg0 - return args, nil -} + return e.complexity.Droid.AppearsIn(childComplexity), true -func field_Human_friendsConnection_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["first"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 + case "Droid.Friends": + if e.complexity.Droid.Friends == nil { + break } - if err != nil { - return nil, err - } - } - args["first"] = arg0 - var arg1 *string - if tmp, ok := rawArgs["after"]; ok { - var err error - var ptr1 string - if tmp != nil { - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 + return e.complexity.Droid.Friends(childComplexity), true + + case "Droid.FriendsConnection": + if e.complexity.Droid.FriendsConnection == nil { + break } + args, err := ec.field_Droid_friendsConnection_args(context.TODO(), rawArgs) if err != nil { - return nil, err + return 0, false } - } - args["after"] = arg1 - return args, nil -} + return e.complexity.Droid.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true -func field_Mutation_createReview_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return nil, err - } - } - args["episode"] = arg0 - var arg1 Review - if tmp, ok := rawArgs["review"]; ok { - var err error - arg1, err = UnmarshalReviewInput(tmp) - if err != nil { - return nil, err + case "Droid.ID": + if e.complexity.Droid.ID == nil { + break } - } - args["review"] = arg1 - return args, nil -} + return e.complexity.Droid.ID(childComplexity), true -func field_Query_hero_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - var ptr1 Episode - if tmp != nil { - err = (&ptr1).UnmarshalGQL(tmp) - arg0 = &ptr1 + case "Droid.Name": + if e.complexity.Droid.Name == nil { + break } - if err != nil { - return nil, err + return e.complexity.Droid.Name(childComplexity), true + + case "Droid.PrimaryFunction": + if e.complexity.Droid.PrimaryFunction == nil { + break } - } - args["episode"] = arg0 - return args, nil -} + return e.complexity.Droid.PrimaryFunction(childComplexity), true -func field_Query_reviews_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 Episode - if tmp, ok := rawArgs["episode"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return nil, err - } - } - args["episode"] = arg0 - var arg1 *time.Time - if tmp, ok := rawArgs["since"]; ok { - var err error - var ptr1 time.Time - if tmp != nil { - ptr1, err = graphql.UnmarshalTime(tmp) - arg1 = &ptr1 + case "FriendsConnection.Edges": + if e.complexity.FriendsConnection.Edges == nil { + break } - if err != nil { - return nil, err + return e.complexity.FriendsConnection.Edges(childComplexity), true + + case "FriendsConnection.Friends": + if e.complexity.FriendsConnection.Friends == nil { + break } - } - args["since"] = arg1 - return args, nil -} + return e.complexity.FriendsConnection.Friends(childComplexity), true -func field_Query_search_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["text"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + case "FriendsConnection.PageInfo": + if e.complexity.FriendsConnection.PageInfo == nil { + break } - } - args["text"] = arg0 - return args, nil -} + return e.complexity.FriendsConnection.PageInfo(childComplexity), true -func field_Query_character_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return nil, err + case "FriendsConnection.TotalCount": + if e.complexity.FriendsConnection.TotalCount == nil { + break } - } - args["id"] = arg0 - return args, nil -} + return e.complexity.FriendsConnection.TotalCount(childComplexity), true -func field_Query_droid_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return nil, err + case "FriendsEdge.Cursor": + if e.complexity.FriendsEdge.Cursor == nil { + break } - } - args["id"] = arg0 - return args, nil -} + return e.complexity.FriendsEdge.Cursor(childComplexity), true -func field_Query_human_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return nil, err + case "FriendsEdge.Node": + if e.complexity.FriendsEdge.Node == nil { + break } - } - args["id"] = arg0 - return args, nil -} + return e.complexity.FriendsEdge.Node(childComplexity), true -func field_Query_starship_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return nil, err + case "Human.AppearsIn": + if e.complexity.Human.AppearsIn == nil { + break } - } - args["id"] = arg0 - return args, nil -} + return e.complexity.Human.AppearsIn(childComplexity), true -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err + case "Human.Friends": + if e.complexity.Human.Friends == nil { + break } - } - args["name"] = arg0 - return args, nil -} + return e.complexity.Human.Friends(childComplexity), true -func field_Starship_length_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *LengthUnit - if tmp, ok := rawArgs["unit"]; ok { - var err error - var ptr1 LengthUnit - if tmp != nil { - err = (&ptr1).UnmarshalGQL(tmp) - arg0 = &ptr1 + case "Human.FriendsConnection": + if e.complexity.Human.FriendsConnection == nil { + break } + args, err := ec.field_Human_friendsConnection_args(context.TODO(), rawArgs) if err != nil { - return nil, err + return 0, false } - } - args["unit"] = arg0 - return args, nil -} + return e.complexity.Human.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err + case "Human.Height": + if e.complexity.Human.Height == nil { + break } - } - args["includeDeprecated"] = arg0 - return args, nil - -} -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) + args, err := ec.field_Human_height_args(context.TODO(), rawArgs) if err != nil { - return nil, err + return 0, false } - } - args["includeDeprecated"] = arg0 - return args, nil -} - -type executableSchema struct { - resolvers ResolverRoot - directives DirectiveRoot - complexity ComplexityRoot -} - -func (e *executableSchema) Schema() *ast.Schema { - return parsedSchema -} - -func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { - switch typeName + "." + field { + return e.complexity.Human.Height(childComplexity, args["unit"].(models.LengthUnit)), true - case "Droid.id": - if e.complexity.Droid.Id == nil { + case "Human.ID": + if e.complexity.Human.ID == nil { break } - return e.complexity.Droid.Id(childComplexity), true + return e.complexity.Human.ID(childComplexity), true - case "Droid.name": - if e.complexity.Droid.Name == nil { + case "Human.Mass": + if e.complexity.Human.Mass == nil { break } - return e.complexity.Droid.Name(childComplexity), true - - case "Droid.friends": - if e.complexity.Droid.Friends == nil { - break - } - - return e.complexity.Droid.Friends(childComplexity), true - - case "Droid.friendsConnection": - if e.complexity.Droid.FriendsConnection == nil { - break - } - - args, err := field_Droid_friendsConnection_args(rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Droid.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true - - case "Droid.appearsIn": - if e.complexity.Droid.AppearsIn == nil { - break - } - - return e.complexity.Droid.AppearsIn(childComplexity), true - - case "Droid.primaryFunction": - if e.complexity.Droid.PrimaryFunction == nil { - break - } - - return e.complexity.Droid.PrimaryFunction(childComplexity), true - - case "FriendsConnection.totalCount": - if e.complexity.FriendsConnection.TotalCount == nil { - break - } - - return e.complexity.FriendsConnection.TotalCount(childComplexity), true - - case "FriendsConnection.edges": - if e.complexity.FriendsConnection.Edges == nil { - break - } - - return e.complexity.FriendsConnection.Edges(childComplexity), true - - case "FriendsConnection.friends": - if e.complexity.FriendsConnection.Friends == nil { - break - } - - return e.complexity.FriendsConnection.Friends(childComplexity), true - - case "FriendsConnection.pageInfo": - if e.complexity.FriendsConnection.PageInfo == nil { - break - } - - return e.complexity.FriendsConnection.PageInfo(childComplexity), true - - case "FriendsEdge.cursor": - if e.complexity.FriendsEdge.Cursor == nil { - break - } - - return e.complexity.FriendsEdge.Cursor(childComplexity), true - - case "FriendsEdge.node": - if e.complexity.FriendsEdge.Node == nil { - break - } - - return e.complexity.FriendsEdge.Node(childComplexity), true - - case "Human.id": - if e.complexity.Human.Id == nil { - break - } - - return e.complexity.Human.Id(childComplexity), true + return e.complexity.Human.Mass(childComplexity), true - case "Human.name": + case "Human.Name": if e.complexity.Human.Name == nil { break } return e.complexity.Human.Name(childComplexity), true - case "Human.height": - if e.complexity.Human.Height == nil { - break - } - - args, err := field_Human_height_args(rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Human.Height(childComplexity, args["unit"].(LengthUnit)), true - - case "Human.mass": - if e.complexity.Human.Mass == nil { - break - } - - return e.complexity.Human.Mass(childComplexity), true - - case "Human.friends": - if e.complexity.Human.Friends == nil { - break - } - - return e.complexity.Human.Friends(childComplexity), true - - case "Human.friendsConnection": - if e.complexity.Human.FriendsConnection == nil { - break - } - - args, err := field_Human_friendsConnection_args(rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Human.FriendsConnection(childComplexity, args["first"].(*int), args["after"].(*string)), true - - case "Human.appearsIn": - if e.complexity.Human.AppearsIn == nil { - break - } - - return e.complexity.Human.AppearsIn(childComplexity), true - - case "Human.starships": + case "Human.Starships": if e.complexity.Human.Starships == nil { break } return e.complexity.Human.Starships(childComplexity), true - case "Mutation.createReview": + case "Mutation.CreateReview": if e.complexity.Mutation.CreateReview == nil { break } - args, err := field_Mutation_createReview_args(rawArgs) + args, err := ec.field_Mutation_createReview_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(Episode), args["review"].(Review)), true - - case "PageInfo.startCursor": - if e.complexity.PageInfo.StartCursor == nil { - break - } - - return e.complexity.PageInfo.StartCursor(childComplexity), true + return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(models.Episode), args["review"].(models.Review)), true - case "PageInfo.endCursor": + case "PageInfo.EndCursor": if e.complexity.PageInfo.EndCursor == nil { break } return e.complexity.PageInfo.EndCursor(childComplexity), true - case "PageInfo.hasNextPage": + case "PageInfo.HasNextPage": if e.complexity.PageInfo.HasNextPage == nil { break } return e.complexity.PageInfo.HasNextPage(childComplexity), true - case "Query.hero": - if e.complexity.Query.Hero == nil { + case "PageInfo.StartCursor": + if e.complexity.PageInfo.StartCursor == nil { + break + } + + return e.complexity.PageInfo.StartCursor(childComplexity), true + + case "Query.Character": + if e.complexity.Query.Character == nil { break } - args, err := field_Query_hero_args(rawArgs) + args, err := ec.field_Query_character_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Hero(childComplexity, args["episode"].(*Episode)), true + return e.complexity.Query.Character(childComplexity, args["id"].(string)), true - case "Query.reviews": - if e.complexity.Query.Reviews == nil { + case "Query.Droid": + if e.complexity.Query.Droid == nil { break } - args, err := field_Query_reviews_args(rawArgs) + args, err := ec.field_Query_droid_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Reviews(childComplexity, args["episode"].(Episode), args["since"].(*time.Time)), true + return e.complexity.Query.Droid(childComplexity, args["id"].(string)), true - case "Query.search": - if e.complexity.Query.Search == nil { + case "Query.Hero": + if e.complexity.Query.Hero == nil { break } - args, err := field_Query_search_args(rawArgs) + args, err := ec.field_Query_hero_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Search(childComplexity, args["text"].(string)), true + return e.complexity.Query.Hero(childComplexity, args["episode"].(*models.Episode)), true - case "Query.character": - if e.complexity.Query.Character == nil { + case "Query.Human": + if e.complexity.Query.Human == nil { break } - args, err := field_Query_character_args(rawArgs) + args, err := ec.field_Query_human_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Character(childComplexity, args["id"].(string)), true + return e.complexity.Query.Human(childComplexity, args["id"].(string)), true - case "Query.droid": - if e.complexity.Query.Droid == nil { + case "Query.Reviews": + if e.complexity.Query.Reviews == nil { break } - args, err := field_Query_droid_args(rawArgs) + args, err := ec.field_Query_reviews_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Droid(childComplexity, args["id"].(string)), true + return e.complexity.Query.Reviews(childComplexity, args["episode"].(models.Episode), args["since"].(*time.Time)), true - case "Query.human": - if e.complexity.Query.Human == nil { + case "Query.Search": + if e.complexity.Query.Search == nil { break } - args, err := field_Query_human_args(rawArgs) + args, err := ec.field_Query_search_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Query.Human(childComplexity, args["id"].(string)), true + return e.complexity.Query.Search(childComplexity, args["text"].(string)), true - case "Query.starship": + case "Query.Starship": if e.complexity.Query.Starship == nil { break } - args, err := field_Query_starship_args(rawArgs) + args, err := ec.field_Query_starship_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Query.Starship(childComplexity, args["id"].(string)), true - case "Review.stars": - if e.complexity.Review.Stars == nil { + case "Review.Commentary": + if e.complexity.Review.Commentary == nil { break } - return e.complexity.Review.Stars(childComplexity), true + return e.complexity.Review.Commentary(childComplexity), true - case "Review.commentary": - if e.complexity.Review.Commentary == nil { + case "Review.Stars": + if e.complexity.Review.Stars == nil { break } - return e.complexity.Review.Commentary(childComplexity), true + return e.complexity.Review.Stars(childComplexity), true - case "Review.time": + case "Review.Time": if e.complexity.Review.Time == nil { break } return e.complexity.Review.Time(childComplexity), true - case "Starship.id": - if e.complexity.Starship.Id == nil { + case "Starship.History": + if e.complexity.Starship.History == nil { break } - return e.complexity.Starship.Id(childComplexity), true + return e.complexity.Starship.History(childComplexity), true - case "Starship.name": - if e.complexity.Starship.Name == nil { + case "Starship.ID": + if e.complexity.Starship.ID == nil { break } - return e.complexity.Starship.Name(childComplexity), true + return e.complexity.Starship.ID(childComplexity), true - case "Starship.length": + case "Starship.Length": if e.complexity.Starship.Length == nil { break } - args, err := field_Starship_length_args(rawArgs) + args, err := ec.field_Starship_length_args(context.TODO(), rawArgs) if err != nil { return 0, false } - return e.complexity.Starship.Length(childComplexity, args["unit"].(*LengthUnit)), true + return e.complexity.Starship.Length(childComplexity, args["unit"].(*models.LengthUnit)), true - case "Starship.history": - if e.complexity.Starship.History == nil { + case "Starship.Name": + if e.complexity.Starship.Name == nil { break } - return e.complexity.Starship.History(childComplexity), true + return e.complexity.Starship.Name(childComplexity), true } return 0, false @@ -793,7 +502,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -822,532 +532,1436 @@ type executionContext struct { *executableSchema } -var droidImplementors = []string{"Droid", "Character"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, obj *Droid) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, droidImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Droid") - case "id": - out.Values[i] = ec._Droid_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._Droid_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "friends": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Droid_friends(ctx, field, obj) - wg.Done() - }(i, field) - case "friendsConnection": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Droid_friendsConnection(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "appearsIn": - out.Values[i] = ec._Droid_appearsIn(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "primaryFunction": - out.Values[i] = ec._Droid_primaryFunction(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil } + }() + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return res } -// nolint: vetshadow -func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ID, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return introspection.WrapSchema(parsedSchema), nil } -// nolint: vetshadow -func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -// nolint: vetshadow -func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `# The query type, represents all of the entry points into our object graph +type Query { + hero(episode: Episode = NEWHOPE): Character + reviews(episode: Episode!, since: Time): [Review!]! + search(text: String!): [SearchResult!]! + character(id: ID!): Character + droid(id: ID!): Droid + human(id: ID!): Human + starship(id: ID!): Starship +} +# The mutation type, represents all updates we can make to our data +type Mutation { + createReview(episode: Episode!, review: ReviewInput!): Review +} +# The episodes in the Star Wars trilogy +enum Episode { + # Star Wars Episode IV: A New Hope, released in 1977. + NEWHOPE + # Star Wars Episode V: The Empire Strikes Back, released in 1980. + EMPIRE + # Star Wars Episode VI: Return of the Jedi, released in 1983. + JEDI +} +# A character from the Star Wars universe +interface Character { + # The ID of the character + id: ID! + # The name of the character + name: String! + # The friends of the character, or an empty list if they have none + friends: [Character!] + # The friends of the character exposed as a connection with edges + friendsConnection(first: Int, after: ID): FriendsConnection! + # The movies this character appears in + appearsIn: [Episode!]! +} +# Units of height +enum LengthUnit { + # The standard unit around the world + METER + # Primarily used in the United States + FOOT +} +# A humanoid creature from the Star Wars universe +type Human implements Character { + # The ID of the human + id: ID! + # What this human calls themselves + name: String! + # Height in the preferred unit, default is meters + height(unit: LengthUnit = METER): Float! + # Mass in kilograms, or null if unknown + mass: Float + # This human's friends, or an empty list if they have none + friends: [Character!] + # The friends of the human exposed as a connection with edges + friendsConnection(first: Int, after: ID): FriendsConnection! + # The movies this human appears in + appearsIn: [Episode!]! + # A list of starships this person has piloted, or an empty list if none + starships: [Starship!] +} +# An autonomous mechanical character in the Star Wars universe +type Droid implements Character { + # The ID of the droid + id: ID! + # What others call this droid + name: String! + # This droid's friends, or an empty list if they have none + friends: [Character!] + # The friends of the droid exposed as a connection with edges + friendsConnection(first: Int, after: ID): FriendsConnection! + # The movies this droid appears in + appearsIn: [Episode!]! + # This droid's primary function + primaryFunction: String +} +# A connection object for a character's friends +type FriendsConnection { + # The total number of friends + totalCount: Int! + # The edges for each of the character's friends. + edges: [FriendsEdge!] + # A list of the friends, as a convenience when edges are not needed. + friends: [Character!] + # Information for paginating this connection + pageInfo: PageInfo! +} +# An edge object for a character's friends +type FriendsEdge { + # A cursor used for pagination + cursor: ID! + # The character represented by this friendship edge + node: Character +} +# Information for paginating this connection +type PageInfo { + startCursor: ID! + endCursor: ID! + hasNextPage: Boolean! +} +# Represents a review for a movie +type Review { + # The number of stars this review gave, 1-5 + stars: Int! + # Comment about the movie + commentary: String + # when the review was posted + time: Time +} +# The input object sent when someone is creating a new review +input ReviewInput { + # 0-5 stars + stars: Int! + # Comment about the movie, optional + commentary: String + # when the review was posted + time: Time +} +type Starship { + # The ID of the starship + id: ID! + # The name of the starship + name: String! + # Length of the starship, along the longest axis + length(unit: LengthUnit = METER): Float! + # coordinates tracking this ship + history: [[Int!]!]! +} +union SearchResult = Human | Droid | Starship +scalar Time +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Droid_friendsConnection_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["first"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg0 + var arg1 *string + if tmp, ok := rawArgs["after"]; ok { + arg1, err = ec.unmarshalOID2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Human_friendsConnection_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["first"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg0 + var arg1 *string + if tmp, ok := rawArgs["after"]; ok { + arg1, err = ec.unmarshalOID2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Human_height_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 models.LengthUnit + if tmp, ok := rawArgs["unit"]; ok { + arg0, err = ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, tmp) + if err != nil { + return nil, err + } + } + args["unit"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_createReview_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 models.Episode + if tmp, ok := rawArgs["episode"]; ok { + arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) + if err != nil { + return nil, err + } + } + args["episode"] = arg0 + var arg1 models.Review + if tmp, ok := rawArgs["review"]; ok { + arg1, err = ec.unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, tmp) + if err != nil { + return nil, err + } + } + args["review"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_character_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_droid_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_hero_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *models.Episode + if tmp, ok := rawArgs["episode"]; ok { + arg0, err = ec.unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) + if err != nil { + return nil, err + } + } + args["episode"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_human_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_reviews_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 models.Episode + if tmp, ok := rawArgs["episode"]; ok { + arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) + if err != nil { + return nil, err + } + } + args["episode"] = arg0 + var arg1 *time.Time + if tmp, ok := rawArgs["since"]; ok { + arg1, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, tmp) + if err != nil { + return nil, err + } + } + args["since"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Query_search_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["text"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["text"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_starship_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Starship_length_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *models.LengthUnit + if tmp, ok := rawArgs["unit"]; ok { + arg0, err = ec.unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, tmp) + if err != nil { + return nil, err + } + } + args["unit"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Droid().Friends(rctx, obj) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]models.Character) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) +} + +func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Droid_friendsConnection_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Droid().FriendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.FriendsConnection) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.AppearsIn, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]models.Episode) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, field.Selections, res) +} + +func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Droid", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PrimaryFunction, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsConnection", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.TotalCount(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsConnection", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.FriendsConnection().Edges(rctx, obj) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]models.FriendsEdge) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsConnection", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.FriendsConnection().Friends(rctx, obj) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]models.Character) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsConnection", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(models.PageInfo) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *models.FriendsEdge) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsEdge", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql.CollectedField, obj *models.FriendsEdge) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "FriendsEdge", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(models.Character) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_id(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_name(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Human_height_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Height(args["unit"].(models.LengthUnit)), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Mass, nil + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(float64) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Droid().Friends(rctx, obj) + return ec.resolvers.Human().Friends(rctx, obj) }) if resTmp == nil { return graphql.Null } - res := resTmp.([]Character) + res := resTmp.([]models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Human_friendsConnection_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Human().FriendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.FriendsConnection) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx, field.Selections, res) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.AppearsIn, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]models.Episode) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, field.Selections, res) +} + +func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Human", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Human().Starships(rctx, obj) + }) + if resTmp == nil { + return graphql.Null } + res := resTmp.([]models.Starship) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, field.Selections, res) +} - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], +func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Mutation_createReview_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateReview(rctx, args["episode"].(models.Episode), args["review"].(models.Review)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*models.Review) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, field.Selections, res) +} + +func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "PageInfo", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.StartCursor, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} - return ec._Character(ctx, field.Selections, &res[idx1]) - }() +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "PageInfo", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndCursor, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - if isLen1 { - f(idx1) - } else { - go f(idx1) + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "PageInfo", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HasNextPage, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_hero_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Hero(rctx, args["episode"].(*models.Episode)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(models.Character) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_reviews_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Reviews(rctx, args["episode"].(models.Episode), args["since"].(*time.Time)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]models.Review) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_search_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Search(rctx, args["text"].(string)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } + return graphql.Null + } + res := resTmp.([]models.SearchResult) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx, field.Selections, res) +} +func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_character_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Character(rctx, args["id"].(string)) + }) + if resTmp == nil { + return graphql.Null } - wg.Wait() - return arr1 + res := resTmp.(models.Character) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Droid_friendsConnection_args(rawArgs) + args, err := ec.field_Query_droid_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Droid().FriendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + return ec.resolvers.Query().Droid(rctx, args["id"].(string)) }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(FriendsConnection) + res := resTmp.(*models.Droid) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._FriendsConnection(ctx, field.Selections, &res) + return ec.marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_human_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.AppearsIn, nil + return ec.resolvers.Query().Human(rctx, args["id"].(string)) }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.([]Episode) + res := resTmp.(*models.Human) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return res[idx1] - }() - } - - return arr1 + return ec.marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Droid", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_starship_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.PrimaryFunction, nil + return ec.resolvers.Query().Starship(rctx, args["id"].(string)) }) if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*models.Starship) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, field.Selections, res) } -var friendsConnectionImplementors = []string{"FriendsConnection"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.SelectionSet, obj *FriendsConnection) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, friendsConnectionImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("FriendsConnection") - case "totalCount": - out.Values[i] = ec._FriendsConnection_totalCount(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "edges": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._FriendsConnection_edges(ctx, field, obj) - wg.Done() - }(i, field) - case "friends": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._FriendsConnection_friends(ctx, field, obj) - wg.Done() - }(i, field) - case "pageInfo": - out.Values[i] = ec._FriendsConnection_pageInfo(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } - wg.Wait() - if invalid { + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query___type_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) return graphql.Null } - return out + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(args["name"].(string)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsConnection", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.TotalCount(), nil + return ec.introspectSchema() }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(int) + res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsConnection", - Args: nil, - Field: field, + Object: "Review", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.FriendsConnection().Edges(rctx, obj) + return obj.Stars, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.([]FriendsEdge) + res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalNInt2int(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _Review_commentary(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsConnection", - Args: nil, - Field: field, + Object: "Review", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.FriendsConnection().Friends(rctx, obj) + return obj.Commentary, nil }) if resTmp == nil { return graphql.Null } - res := resTmp.([]Character) + res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Character(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _Review_time(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsConnection", - Args: nil, - Field: field, + Object: "Review", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.PageInfo(), nil + return obj.Time, nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(PageInfo) + res := resTmp.(time.Time) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._PageInfo(ctx, field.Selections, &res) -} - -var friendsEdgeImplementors = []string{"FriendsEdge"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionSet, obj *FriendsEdge) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, friendsEdgeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("FriendsEdge") - case "cursor": - out.Values[i] = ec._FriendsEdge_cursor(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "node": - out.Values[i] = ec._FriendsEdge_node(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsEdge", - Args: nil, - Field: field, + Object: "Starship", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Cursor, nil + return obj.ID, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1358,117 +1972,57 @@ func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNID2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "FriendsEdge", - Args: nil, - Field: field, + Object: "Starship", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Node, nil + return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(Character) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Character(ctx, field.Selections, &res) -} - -var humanImplementors = []string{"Human", "Character"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, obj *Human) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, humanImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Human") - case "id": - out.Values[i] = ec._Human_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._Human_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "height": - out.Values[i] = ec._Human_height(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mass": - out.Values[i] = ec._Human_mass(ctx, field, obj) - case "friends": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Human_friends(ctx, field, obj) - wg.Done() - }(i, field) - case "friendsConnection": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Human_friendsConnection(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "appearsIn": - out.Values[i] = ec._Human_appearsIn(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "starships": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Human_starships(ctx, field, obj) - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_id(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "Starship", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Starship_length_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ID, nil + return ec.resolvers.Starship().Length(rctx, obj, args["unit"].(*models.LengthUnit)) }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1476,26 +2030,26 @@ func (ec *executionContext) _Human_id(ctx context.Context, field graphql.Collect } return graphql.Null } - res := resTmp.(string) + res := resTmp.(float64) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNFloat2float64(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_name(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Starship_history(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "Starship", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return obj.History, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1503,32 +2057,26 @@ func (ec *executionContext) _Human_name(ctx context.Context, field graphql.Colle } return graphql.Null } - res := resTmp.(string) + res := resTmp.([][]int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNInt2ᚕᚕint(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Human_height_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Human", - Args: args, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Height(args["unit"].(LengthUnit)), nil + return obj.Name, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1536,113 +2084,77 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.(float64) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Mass, nil + return obj.Description, nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(float64) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Human().Friends(rctx, obj) + return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.([]Character) + res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Character(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Human_friendsConnection_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Human", - Args: args, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Human().FriendsConnection(rctx, obj, args["first"].(*int), args["after"].(*string)) + return obj.Args, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1650,27 +2162,26 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field } return graphql.Null } - res := resTmp.(FriendsConnection) + res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._FriendsConnection(ctx, field.Selections, &res) + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.AppearsIn, nil + return obj.Name, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1678,225 +2189,152 @@ func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.([]Episode) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return res[idx1] - }() - } - - return arr1 + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Human", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Human().Starships(rctx, obj) + return obj.Description, nil }) if resTmp == nil { return graphql.Null } - res := resTmp.([]Starship) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Starship(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalOString2string(ctx, field.Selections, res) } -var mutationImplementors = []string{"Mutation"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, mutationImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Mutation", +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil }) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Mutation") - case "createReview": - out.Values[i] = ec._Mutation_createReview(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - } - - if invalid { return graphql.Null } - return out + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Mutation_createReview_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Mutation", - Args: args, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().CreateReview(rctx, args["episode"].(Episode), args["review"].(Review)) + return obj.DeprecationReason(), nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(*Review) + res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Review(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -var pageInfoImplementors = []string{"PageInfo"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *PageInfo) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, pageInfoImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("PageInfo") - case "startCursor": - out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "endCursor": - out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "hasNextPage": - out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } - - if invalid { + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return out + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "PageInfo", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.StartCursor, nil + return obj.Description, nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "PageInfo", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.EndCursor, nil + return obj.Args, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1904,26 +2342,26 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph } return graphql.Null } - res := resTmp.(string) + res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "PageInfo", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.HasNextPage, nil + return obj.Type, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1931,145 +2369,77 @@ func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field gra } return graphql.Null } - res := resTmp.(bool) + res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -var queryImplementors = []string{"Query"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil }) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "hero": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_hero(ctx, field) - wg.Done() - }(i, field) - case "reviews": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_reviews(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "search": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_search(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "character": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_character(ctx, field) - wg.Done() - }(i, field) - case "droid": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_droid(ctx, field) - wg.Done() - }(i, field) - case "human": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_human(ctx, field) - wg.Done() - }(i, field) - case "starship": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_starship(ctx, field) - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - } - wg.Wait() - if invalid { return graphql.Null } - return out + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_hero_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Hero(rctx, args["episode"].(*Episode)) + return obj.DeprecationReason(), nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(Character) + res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Character(ctx, field.Selections, &res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_reviews_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Reviews(rctx, args["episode"].(Episode), args["since"].(*time.Time)) + return obj.Name, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -2077,65 +2447,50 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.([]Review) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Review(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if resTmp == nil { + return graphql.Null } - wg.Wait() - return arr1 + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_search_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Search(rctx, args["text"].(string)) + return obj.Type, nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -2143,201 +2498,128 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.([]SearchResult) + res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._SearchResult(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_character_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Character(rctx, args["id"].(string)) + return obj.DefaultValue, nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(Character) + res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Character(ctx, field.Selections, &res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_droid_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Droid(rctx, args["id"].(string)) + return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*Droid) + res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Droid(ctx, field.Selections, res) + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_human_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Human(rctx, args["id"].(string)) + return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*Human) + res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Human(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_starship_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Starship(rctx, args["id"].(string)) + return obj.MutationType(), nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(*Starship) + res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Starship(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.introspectType(args["name"].(string)) + return obj.SubscriptionType(), nil }) if resTmp == nil { return graphql.Null @@ -2345,933 +2627,965 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.introspectSchema() + return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*introspection.Schema) + res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - - return ec.___Schema(ctx, field.Selections, res) + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -var reviewImplementors = []string{"Review"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, obj *Review) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, reviewImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Review") - case "stars": - out.Values[i] = ec._Review_stars(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "commentary": - out.Values[i] = ec._Review_commentary(ctx, field, obj) - case "time": - out.Values[i] = ec._Review_time(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } - - if invalid { + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name(), nil + }) + if resTmp == nil { return graphql.Null } - return out + res := resTmp.(*string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Review", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Stars, nil + return obj.Description(), nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(int) + res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Review_commentary(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Review", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_fields_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Commentary, nil + return obj.Fields(args["includeDeprecated"].(bool)), nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Review_time(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Review", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Time, nil + return obj.Interfaces(), nil }) if resTmp == nil { return graphql.Null } - res := resTmp.(time.Time) + res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalTime(res) -} - -var starshipImplementors = []string{"Starship"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, obj *Starship) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, starshipImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Starship") - case "id": - out.Values[i] = ec._Starship_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec._Starship_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "length": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Starship_length(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "history": - out.Values[i] = ec._Starship_history(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Starship", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ID, nil + return obj.PossibleTypes(), nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(string) + res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Starship", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return obj.EnumValues(args["includeDeprecated"].(bool)), nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(string) + res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Starship_length_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } rctx := &graphql.ResolverContext{ - Object: "Starship", - Args: args, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Starship().Length(rctx, obj, args["unit"].(*LengthUnit)) + return obj.InputFields(), nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(float64) + res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalFloat(res) + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow -func (ec *executionContext) _Starship_history(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Starship", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.History, nil + return obj.OfType(), nil }) if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.([][]int) + res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +func (ec *executionContext) unmarshalInputReviewInput(ctx context.Context, v interface{}) (models.Review, error) { + var it models.Review + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "stars": + var err error + it.Stars, err = ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + case "commentary": + var err error + it.Commentary, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "time": + var err error + it.Time, err = ec.unmarshalOTime2timeᚐTime(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +func (ec *executionContext) _Character(ctx context.Context, sel ast.SelectionSet, obj *models.Character) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: + return graphql.Null + case models.Human: + return ec._Human(ctx, sel, &obj) + case *models.Human: + return ec._Human(ctx, sel, obj) + case models.Droid: + return ec._Droid(ctx, sel, &obj) + case *models.Droid: + return ec._Droid(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + +func (ec *executionContext) _SearchResult(ctx context.Context, sel ast.SelectionSet, obj *models.SearchResult) graphql.Marshaler { + switch obj := (*obj).(type) { + case nil: + return graphql.Null + case models.Human: + return ec._Human(ctx, sel, &obj) + case *models.Human: + return ec._Human(ctx, sel, obj) + case models.Droid: + return ec._Droid(ctx, sel, &obj) + case *models.Droid: + return ec._Droid(ctx, sel, obj) + case models.Starship: + return ec._Starship(ctx, sel, &obj) + case *models.Starship: + return ec._Starship(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + +// endregion ************************** interface.gotpl *************************** - arr1 := make(graphql.Array, len(res)) +// region **************************** object.gotpl **************************** - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { +var droidImplementors = []string{"Droid", "Character", "SearchResult"} - arr2 := make(graphql.Array, len(res[idx1])) +func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, obj *models.Droid) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, droidImplementors) - for idx2 := range res[idx1] { - arr2[idx2] = func() graphql.Marshaler { - return graphql.MarshalInt(res[idx1][idx2]) + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Droid") + case "id": + out.Values[i] = ec._Droid_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec._Droid_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "friends": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Droid_friends(ctx, field, obj) + return res + }) + case "friendsConnection": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } }() + res = ec._Droid_friendsConnection(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "appearsIn": + out.Values[i] = ec._Droid_appearsIn(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } + case "primaryFunction": + out.Values[i] = ec._Droid_primaryFunction(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var friendsConnectionImplementors = []string{"FriendsConnection"} - return arr2 - }() +func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.SelectionSet, obj *models.FriendsConnection) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, friendsConnectionImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("FriendsConnection") + case "totalCount": + out.Values[i] = ec._FriendsConnection_totalCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "edges": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._FriendsConnection_edges(ctx, field, obj) + return res + }) + case "friends": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._FriendsConnection_friends(ctx, field, obj) + return res + }) + case "pageInfo": + out.Values[i] = ec._FriendsConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var friendsEdgeImplementors = []string{"FriendsEdge"} + +func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionSet, obj *models.FriendsEdge) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, friendsEdgeImplementors) - return arr1 + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("FriendsEdge") + case "cursor": + out.Values[i] = ec._FriendsEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "node": + out.Values[i] = ec._FriendsEdge_node(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var __DirectiveImplementors = []string{"__Directive"} +var humanImplementors = []string{"Human", "Character", "SearchResult"} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) +func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, obj *models.Human) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, humanImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") + out.Values[i] = graphql.MarshalString("Human") + case "id": + out.Values[i] = ec._Human_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) + out.Values[i] = ec._Human_name(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) + case "height": + out.Values[i] = ec._Human_height(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) + case "mass": + out.Values[i] = ec._Human_mass(ctx, field, obj) + case "friends": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Human_friends(ctx, field, obj) + return res + }) + case "friendsConnection": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Human_friendsConnection(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "appearsIn": + out.Values[i] = ec._Human_appearsIn(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } + case "starships": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Human_starships(ctx, field, obj) + return res + }) default: panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +var mutationImplementors = []string{"Mutation"} -// nolint: vetshadow -func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, mutationImplementors) -// nolint: vetshadow -func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Locations, nil + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 -} -// nolint: vetshadow -func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Args, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "createReview": + out.Values[i] = ec._Mutation_createReview(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) } - return graphql.Null } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - + out.Dispatch() + if invalid { + return graphql.Null } - wg.Wait() - return arr1 + return out } -var __EnumValueImplementors = []string{"__EnumValue"} +var pageInfoImplementors = []string{"PageInfo"} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) +func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *models.PageInfo) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, pageInfoImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + out.Values[i] = graphql.MarshalString("PageInfo") + case "startCursor": + out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + case "endCursor": + out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "hasNextPage": + out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +var queryImplementors = []string{"Query"} -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.IsDeprecated(), nil + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "hero": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_hero(ctx, field) + return res + }) + case "reviews": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_reviews(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "search": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_search(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "character": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_character(ctx, field) + return res + }) + case "droid": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_droid(ctx, field) + return res + }) + case "human": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_human(ctx, field) + return res + }) + case "starship": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_starship(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return out } -// nolint: vetshadow -func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DeprecationReason(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +var reviewImplementors = []string{"Review"} + +func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, obj *models.Review) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, reviewImplementors) - if res == nil { + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Review") + case "stars": + out.Values[i] = ec._Review_stars(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "commentary": + out.Values[i] = ec._Review_commentary(ctx, field, obj) + case "time": + out.Values[i] = ec._Review_time(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalString(*res) + return out } -var __FieldImplementors = []string{"__Field"} +var starshipImplementors = []string{"Starship", "SearchResult"} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) +func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, obj *models.Starship) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, starshipImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) + out.Values[i] = graphql.MarshalString("Starship") + case "id": + out.Values[i] = ec._Starship_id(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) + case "name": + out.Values[i] = ec._Starship_name(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + case "length": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Starship_length(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + case "history": + out.Values[i] = ec._Starship_history(ctx, field, obj) if out.Values[i] == graphql.Null { invalid = true } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Args, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +var __DirectiveImplementors = []string{"__Directive"} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) } - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Type, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return out +} - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } +var __EnumValueImplementors = []string{"__EnumValue"} - return ec.___Type(ctx, field.Selections, res) -} +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) -// nolint: vetshadow -func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.IsDeprecated(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) } + } + out.Dispatch() + if invalid { return graphql.Null } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return out } -// nolint: vetshadow -func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DeprecationReason(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +var __FieldImplementors = []string{"__Field"} - if res == nil { +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { return graphql.Null } - return graphql.MarshalString(*res) + return out } var __InputValueImplementors = []string{"__InputValue"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") @@ -3293,138 +3607,21 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection panic("unknown field " + strconv.Quote(field.Name)) } } - + out.Dispatch() if invalid { return graphql.Null } return out } -// nolint: vetshadow -func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow -func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Type, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) -} - -// nolint: vetshadow -func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.DefaultValue, nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - var __SchemaImplementors = []string{"__Schema"} -// nolint: gocyclo, errcheck, gas, goconst func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - out := graphql.NewOrderedMap(len(fields)) + out := graphql.NewFieldSet(fields) invalid := false for i, field := range fields { - out.Keys[i] = field.Alias - switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") @@ -3451,910 +3648,1076 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, panic("unknown field " + strconv.Quote(field.Name)) } } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v models.Character) graphql.Marshaler { + return ec._Character(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (models.Episode, error) { + var res models.Episode + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v models.Episode) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) ([]models.Episode, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]models.Episode, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v []models.Episode) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalNFloat2float64(ctx context.Context, v interface{}) (float64, error) { + return graphql.UnmarshalFloat(v) +} + +func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { + return graphql.MarshalFloat(v) +} + +func (ec *executionContext) marshalNFriendsConnection2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v models.FriendsConnection) graphql.Marshaler { + return ec._FriendsConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v *models.FriendsConnection) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._FriendsConnection(ctx, sel, v) +} - if invalid { - return graphql.Null +func (ec *executionContext) marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v models.FriendsEdge) graphql.Marshaler { + return ec._FriendsEdge(ctx, sel, &v) +} + +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) +} + +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalNInt2ᚕint(ctx context.Context, v interface{}) ([]int, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - return out + var err error + res := make([]int, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNInt2int(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil } -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, +func (ec *executionContext) marshalNInt2ᚕint(ctx context.Context, sel ast.SelectionSet, v []int) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNInt2int(ctx, sel, v[i]) } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + + return ret +} + +func (ec *executionContext) unmarshalNInt2ᚕᚕint(ctx context.Context, v interface{}) ([][]int, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} } - return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + var err error + res := make([][]int, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNInt2ᚕint(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) marshalNInt2ᚕᚕint(ctx context.Context, sel ast.SelectionSet, v [][]int) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNInt2ᚕint(ctx, sel, v[i]) + } + + return ret +} + +func (ec *executionContext) marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v models.PageInfo) graphql.Marshaler { + return ec._PageInfo(ctx, sel, &v) +} + +func (ec *executionContext) marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v models.Review) graphql.Marshaler { + return ec._Review(ctx, sel, &v) +} - isLen1 := len(res) == 1 +func (ec *executionContext) marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v []models.Review) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, +func (ec *executionContext) unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, v interface{}) (models.Review, error) { + return ec.unmarshalInputReviewInput(ctx, v) +} + +func (ec *executionContext) marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v models.SearchResult) graphql.Marshaler { + return ec._SearchResult(ctx, sel, &v) +} + +func (ec *executionContext) marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v []models.SearchResult) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.QueryType(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], } - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx, sel, v[i]) } - return graphql.Null + if isLen1 { + f(i) + } else { + go f(i) + } + } + wg.Wait() + return ret +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v models.Starship) graphql.Marshaler { + return ec._Starship(ctx, sel, &v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.MutationType(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} - if res == nil { - return graphql.Null - } +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.SubscriptionType(), nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - if res == nil { - return graphql.Null } + wg.Wait() + return ret +} - return ec.___Type(ctx, field.Selections, res) +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) } -// nolint: vetshadow -func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Directives(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err } - return graphql.Null } - res := resTmp.([]introspection.Directive) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return res, nil +} - arr1 := make(graphql.Array, len(res)) +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) var wg sync.WaitGroup - - isLen1 := len(res) == 1 + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -var __TypeImplementors = []string{"__Type"} +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) } + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - if invalid { - return graphql.Null } - return out + wg.Wait() + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Kind(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { ec.Errorf(ctx, "must not be null") } return graphql.Null } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.___Type(ctx, sel, v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name(), nil - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) } -// nolint: vetshadow -func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Description(), nil - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err } -// nolint: vetshadow -func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) - if err != nil { - ec.Error(ctx, err) +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Fields(args["includeDeprecated"].(bool)), nil - }) - if resTmp == nil { + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v models.Character) graphql.Marshaler { + return ec._Character(ctx, sel, &v) +} + +func (ec *executionContext) marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v []models.Character) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Field) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) + ret := make(graphql.Array, len(v)) var wg sync.WaitGroup - - isLen1 := len(res) == 1 + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) marshalODroid2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx context.Context, sel ast.SelectionSet, v models.Droid) graphql.Marshaler { + return ec._Droid(ctx, sel, &v) +} + +func (ec *executionContext) marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx context.Context, sel ast.SelectionSet, v *models.Droid) graphql.Marshaler { + if v == nil { + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Interfaces(), nil - }) - if resTmp == nil { + return ec._Droid(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (models.Episode, error) { + var res models.Episode + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v models.Episode) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (*models.Episode, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v *models.Episode) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return v +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) unmarshalOFloat2float64(ctx context.Context, v interface{}) (float64, error) { + return graphql.UnmarshalFloat(v) +} + +func (ec *executionContext) marshalOFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { + return graphql.MarshalFloat(v) +} - isLen1 := len(res) == 1 +func (ec *executionContext) marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v []models.FriendsEdge) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) marshalOHuman2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx context.Context, sel ast.SelectionSet, v models.Human) graphql.Marshaler { + return ec._Human(ctx, sel, &v) +} + +func (ec *executionContext) marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx context.Context, sel ast.SelectionSet, v *models.Human) graphql.Marshaler { + if v == nil { + return graphql.Null } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.PossibleTypes(), nil - }) - if resTmp == nil { + return ec._Human(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) +} + +func (ec *executionContext) marshalOID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) +} + +func (ec *executionContext) unmarshalOID2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOID2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOID2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOID2string(ctx, sel, *v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) unmarshalOInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) marshalOInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOInt2int(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOInt2int(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, v interface{}) (models.LengthUnit, error) { + var res models.LengthUnit + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v models.LengthUnit) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, v interface{}) (*models.LengthUnit, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v *models.LengthUnit) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) marshalOReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v models.Review) graphql.Marshaler { + return ec._Review(ctx, sel, &v) +} + +func (ec *executionContext) marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v *models.Review) graphql.Marshaler { + if v == nil { + return graphql.Null } + return ec._Review(ctx, sel, v) +} + +func (ec *executionContext) marshalOStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v models.Starship) graphql.Marshaler { + return ec._Starship(ctx, sel, &v) +} - for idx1 := range res { - idx1 := idx1 +func (ec *executionContext) marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v []models.Starship) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) - if err != nil { - ec.Error(ctx, err) +func (ec *executionContext) marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v *models.Starship) graphql.Marshaler { + if v == nil { return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, + return ec._Starship(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.EnumValues(args["includeDeprecated"].(bool)), nil - }) - if resTmp == nil { + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.([]introspection.EnumValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2string(ctx, sel, *v) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup +func (ec *executionContext) unmarshalOTime2timeᚐTime(ctx context.Context, v interface{}) (time.Time, error) { + return graphql.UnmarshalTime(v) +} - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) marshalOTime2timeᚐTime(ctx context.Context, sel ast.SelectionSet, v time.Time) graphql.Marshaler { + if v.IsZero() { + return graphql.Null + } + return graphql.MarshalTime(v) +} + +func (ec *executionContext) unmarshalOTime2ᚖtimeᚐTime(ctx context.Context, v interface{}) (*time.Time, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOTime2timeᚐTime(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOTime2ᚖtimeᚐTime(ctx context.Context, sel ast.SelectionSet, v *time.Time) graphql.Marshaler { + if v == nil { + return graphql.Null } + return ec.marshalOTime2timeᚐTime(ctx, sel, *v) +} - for idx1 := range res { - idx1 := idx1 +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.InputFields(), nil - }) - if resTmp == nil { +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { return graphql.Null - } - res := resTmp.([]introspection.InputValue) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) + } + ret := make(graphql.Array, len(v)) var wg sync.WaitGroup - - isLen1 := len(res) == 1 + isLen1 := len(v) == 1 if !isLen1 { - wg.Add(len(res)) + wg.Add(len(v)) } - - for idx1 := range res { - idx1 := idx1 + for i := range v { + i := i rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + Index: &i, + Result: &v[i], } ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() if !isLen1 { defer wg.Done() } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) } if isLen1 { - f(idx1) + f(i) } else { - go f(idx1) + go f(i) } } wg.Wait() - return arr1 + return ret } -// nolint: vetshadow -func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.OfType(), nil - }) - if resTmp == nil { +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { return graphql.Null } - res := resTmp.(*introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } - return ec.___Type(ctx, field.Selections, res) + } + wg.Wait() + return ret } -func (ec *executionContext) _Character(ctx context.Context, sel ast.SelectionSet, obj *Character) graphql.Marshaler { - switch obj := (*obj).(type) { - case nil: - return graphql.Null - case Human: - return ec._Human(ctx, sel, &obj) - case *Human: - return ec._Human(ctx, sel, obj) - case Droid: - return ec._Droid(ctx, sel, &obj) - case *Droid: - return ec._Droid(ctx, sel, obj) - default: - panic(fmt.Errorf("unexpected type %T", obj)) - } +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) } -func (ec *executionContext) _SearchResult(ctx context.Context, sel ast.SelectionSet, obj *SearchResult) graphql.Marshaler { - switch obj := (*obj).(type) { - case nil: +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { return graphql.Null - case Human: - return ec._Human(ctx, sel, &obj) - case *Human: - return ec._Human(ctx, sel, obj) - case Droid: - return ec._Droid(ctx, sel, &obj) - case *Droid: - return ec._Droid(ctx, sel, obj) - case Starship: - return ec._Starship(ctx, sel, &obj) - case *Starship: - return ec._Starship(ctx, sel, obj) - default: - panic(fmt.Errorf("unexpected type %T", obj)) } + return ec.___Schema(ctx, sel, v) } -func UnmarshalReviewInput(v interface{}) (Review, error) { - var it Review - var asMap = v.(map[string]interface{}) - - for k, v := range asMap { - switch k { - case "stars": - var err error - it.Stars, err = graphql.UnmarshalInt(v) - if err != nil { - return it, err - } - case "commentary": - var err error - var ptr1 string - if v != nil { - ptr1, err = graphql.UnmarshalString(v) - it.Commentary = &ptr1 - } +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} - if err != nil { - return it, err - } - case "time": - var err error - it.Time, err = graphql.UnmarshalTime(v) - if err != nil { - return it, err +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) } - } - - return it, nil -} - -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil + if isLen1 { + f(i) + } else { + go f(i) } - }() - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil - } - return res -} -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") } - return introspection.WrapSchema(parsedSchema), nil + wg.Wait() + return ret } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + return ec.___Type(ctx, sel, v) } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `# The query type, represents all of the entry points into our object graph -type Query { - hero(episode: Episode = NEWHOPE): Character - reviews(episode: Episode!, since: Time): [Review!]! - search(text: String!): [SearchResult!]! - character(id: ID!): Character - droid(id: ID!): Droid - human(id: ID!): Human - starship(id: ID!): Starship -} -# The mutation type, represents all updates we can make to our data -type Mutation { - createReview(episode: Episode!, review: ReviewInput!): Review -} -# The episodes in the Star Wars trilogy -enum Episode { - # Star Wars Episode IV: A New Hope, released in 1977. - NEWHOPE - # Star Wars Episode V: The Empire Strikes Back, released in 1980. - EMPIRE - # Star Wars Episode VI: Return of the Jedi, released in 1983. - JEDI -} -# A character from the Star Wars universe -interface Character { - # The ID of the character - id: ID! - # The name of the character - name: String! - # The friends of the character, or an empty list if they have none - friends: [Character!] - # The friends of the character exposed as a connection with edges - friendsConnection(first: Int, after: ID): FriendsConnection! - # The movies this character appears in - appearsIn: [Episode!]! -} -# Units of height -enum LengthUnit { - # The standard unit around the world - METER - # Primarily used in the United States - FOOT -} -# A humanoid creature from the Star Wars universe -type Human implements Character { - # The ID of the human - id: ID! - # What this human calls themselves - name: String! - # Height in the preferred unit, default is meters - height(unit: LengthUnit = METER): Float! - # Mass in kilograms, or null if unknown - mass: Float - # This human's friends, or an empty list if they have none - friends: [Character!] - # The friends of the human exposed as a connection with edges - friendsConnection(first: Int, after: ID): FriendsConnection! - # The movies this human appears in - appearsIn: [Episode!]! - # A list of starships this person has piloted, or an empty list if none - starships: [Starship!] -} -# An autonomous mechanical character in the Star Wars universe -type Droid implements Character { - # The ID of the droid - id: ID! - # What others call this droid - name: String! - # This droid's friends, or an empty list if they have none - friends: [Character!] - # The friends of the droid exposed as a connection with edges - friendsConnection(first: Int, after: ID): FriendsConnection! - # The movies this droid appears in - appearsIn: [Episode!]! - # This droid's primary function - primaryFunction: String -} -# A connection object for a character's friends -type FriendsConnection { - # The total number of friends - totalCount: Int! - # The edges for each of the character's friends. - edges: [FriendsEdge!] - # A list of the friends, as a convenience when edges are not needed. - friends: [Character!] - # Information for paginating this connection - pageInfo: PageInfo! -} -# An edge object for a character's friends -type FriendsEdge { - # A cursor used for pagination - cursor: ID! - # The character represented by this friendship edge - node: Character -} -# Information for paginating this connection -type PageInfo { - startCursor: ID! - endCursor: ID! - hasNextPage: Boolean! -} -# Represents a review for a movie -type Review { - # The number of stars this review gave, 1-5 - stars: Int! - # Comment about the movie - commentary: String - # when the review was posted - time: Time -} -# The input object sent when someone is creating a new review -input ReviewInput { - # 0-5 stars - stars: Int! - # Comment about the movie, optional - commentary: String - # when the review was posted - time: Time -} -type Starship { - # The ID of the starship - id: ID! - # The name of the starship - name: String! - # Length of the starship, along the longest axis - length(unit: LengthUnit = METER): Float! - # coordinates tracking this ship - history: [[Int!]!]! -} -union SearchResult = Human | Droid | Starship -scalar Time -`}, -) +// endregion ***************************** type.gotpl ***************************** diff --git a/example/starwars/model.go b/example/starwars/model.go deleted file mode 100644 index 4ff05e0bfd..0000000000 --- a/example/starwars/model.go +++ /dev/null @@ -1,103 +0,0 @@ -package starwars - -import ( - "context" - "encoding/base64" - "fmt" - "strconv" - "strings" - "time" -) - -type CharacterFields struct { - ID string - Name string - FriendIds []string - AppearsIn []Episode -} - -type Human struct { - CharacterFields - StarshipIds []string - heightMeters float64 - Mass float64 -} - -func (h *Human) Height(unit LengthUnit) float64 { - switch unit { - case "METER", "": - return h.heightMeters - case "FOOT": - return h.heightMeters * 3.28084 - default: - panic("invalid unit") - } -} - -func (Human) IsCharacter() {} -func (Human) IsSearchResult() {} - -type Review struct { - Stars int - Commentary *string - Time time.Time -} - -type Droid struct { - CharacterFields - PrimaryFunction string -} - -func (Droid) IsCharacter() {} -func (Droid) IsSearchResult() {} - -func (r *Resolver) resolveFriendConnection(ctx context.Context, ids []string, first *int, after *string) (FriendsConnection, error) { - from := 0 - if after != nil { - b, err := base64.StdEncoding.DecodeString(*after) - if err != nil { - return FriendsConnection{}, err - } - i, err := strconv.Atoi(strings.TrimPrefix(string(b), "cursor")) - if err != nil { - return FriendsConnection{}, err - } - from = i - } - - to := len(ids) - if first != nil { - to = from + *first - if to > len(ids) { - to = len(ids) - } - } - - return FriendsConnection{ - ids: ids, - from: from, - to: to, - }, nil -} - -type FriendsConnection struct { - ids []string - from int - to int -} - -func (f *FriendsConnection) TotalCount() int { - return len(f.ids) -} - -func (f *FriendsConnection) PageInfo() PageInfo { - return PageInfo{ - StartCursor: encodeCursor(f.from), - EndCursor: encodeCursor(f.to - 1), - HasNextPage: f.to < len(f.ids), - } -} - -func encodeCursor(i int) string { - return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("cursor%d", i+1))) -} diff --git a/example/starwars/models_gen.go b/example/starwars/models/generated.go similarity index 92% rename from example/starwars/models_gen.go rename to example/starwars/models/generated.go index 4c6809ee44..2f02272c20 100644 --- a/example/starwars/models_gen.go +++ b/example/starwars/models/generated.go @@ -1,6 +1,6 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package starwars +package models import ( "fmt" @@ -12,6 +12,10 @@ type Character interface { IsCharacter() } +type SearchResult interface { + IsSearchResult() +} + type FriendsEdge struct { Cursor string `json:"cursor"` Node Character `json:"node"` @@ -23,10 +27,6 @@ type PageInfo struct { HasNextPage bool `json:"hasNextPage"` } -type SearchResult interface { - IsSearchResult() -} - type Starship struct { ID string `json:"id"` Name string `json:"name"` @@ -44,6 +44,12 @@ const ( EpisodeJedi Episode = "JEDI" ) +var AllEpisode = []Episode{ + EpisodeNewhope, + EpisodeEmpire, + EpisodeJedi, +} + func (e Episode) IsValid() bool { switch e { case EpisodeNewhope, EpisodeEmpire, EpisodeJedi: @@ -80,6 +86,11 @@ const ( LengthUnitFoot LengthUnit = "FOOT" ) +var AllLengthUnit = []LengthUnit{ + LengthUnitMeter, + LengthUnitFoot, +} + func (e LengthUnit) IsValid() bool { switch e { case LengthUnitMeter, LengthUnitFoot: diff --git a/example/starwars/models/model.go b/example/starwars/models/model.go new file mode 100644 index 0000000000..e3225b743a --- /dev/null +++ b/example/starwars/models/model.go @@ -0,0 +1,71 @@ +package models + +import ( + "encoding/base64" + "fmt" + "time" +) + +type CharacterFields struct { + ID string + Name string + FriendIds []string + AppearsIn []Episode +} + +type Human struct { + CharacterFields + StarshipIds []string + HeightMeters float64 + Mass float64 +} + +func (h *Human) Height(unit LengthUnit) float64 { + switch unit { + case "METER", "": + return h.HeightMeters + case "FOOT": + return h.HeightMeters * 3.28084 + default: + panic("invalid unit") + } +} + +func (Human) IsCharacter() {} +func (Human) IsSearchResult() {} + +type Review struct { + Stars int + Commentary *string + Time time.Time +} + +type Droid struct { + CharacterFields + PrimaryFunction string +} + +func (Droid) IsCharacter() {} +func (Droid) IsSearchResult() {} + +type FriendsConnection struct { + Ids []string + From int + To int +} + +func (f *FriendsConnection) TotalCount() int { + return len(f.Ids) +} + +func (f *FriendsConnection) PageInfo() PageInfo { + return PageInfo{ + StartCursor: EncodeCursor(f.From), + EndCursor: EncodeCursor(f.To - 1), + HasNextPage: f.To < len(f.Ids), + } +} + +func EncodeCursor(i int) string { + return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("cursor%d", i+1))) +} diff --git a/example/starwars/resolvers.go b/example/starwars/resolvers.go index 55c4c3e019..7b1f3f4b5f 100644 --- a/example/starwars/resolvers.go +++ b/example/starwars/resolvers.go @@ -1,47 +1,54 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate rm -rf generated +//go:generate go run ../../testdata/gqlgen.go package starwars import ( "context" + "encoding/base64" "errors" + "strconv" "strings" "time" + + "github.com/99designs/gqlgen/example/starwars/generated" + + "github.com/99designs/gqlgen/example/starwars/models" ) type Resolver struct { - humans map[string]Human - droid map[string]Droid - starships map[string]Starship - reviews map[Episode][]Review + humans map[string]models.Human + droid map[string]models.Droid + starships map[string]models.Starship + reviews map[models.Episode][]models.Review } -func (r *Resolver) Droid() DroidResolver { +func (r *Resolver) Droid() generated.DroidResolver { return &droidResolver{r} } -func (r *Resolver) FriendsConnection() FriendsConnectionResolver { +func (r *Resolver) FriendsConnection() generated.FriendsConnectionResolver { return &friendsConnectionResolver{r} } -func (r *Resolver) Human() HumanResolver { +func (r *Resolver) Human() generated.HumanResolver { return &humanResolver{r} } -func (r *Resolver) Mutation() MutationResolver { +func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} } -func (r *Resolver) Query() QueryResolver { +func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } -func (r *Resolver) Starship() StarshipResolver { +func (r *Resolver) Starship() generated.StarshipResolver { return &starshipResolver{r} } -func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]Character, error) { - var result []Character +func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]models.Character, error) { + var result []models.Character for _, id := range ids { char, err := r.Query().Character(ctx, id) if err != nil { @@ -54,48 +61,77 @@ func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]Chara type droidResolver struct{ *Resolver } -func (r *droidResolver) Friends(ctx context.Context, obj *Droid) ([]Character, error) { +func (r *droidResolver) Friends(ctx context.Context, obj *models.Droid) ([]models.Character, error) { return r.resolveCharacters(ctx, obj.FriendIds) } -func (r *droidResolver) FriendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (FriendsConnection, error) { +func (r *droidResolver) FriendsConnection(ctx context.Context, obj *models.Droid, first *int, after *string) (*models.FriendsConnection, error) { return r.resolveFriendConnection(ctx, obj.FriendIds, first, after) } type friendsConnectionResolver struct{ *Resolver } -func (r *friendsConnectionResolver) Edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error) { - friends, err := r.resolveCharacters(ctx, obj.ids) +func (r *Resolver) resolveFriendConnection(ctx context.Context, ids []string, first *int, after *string) (*models.FriendsConnection, error) { + from := 0 + if after != nil { + b, err := base64.StdEncoding.DecodeString(*after) + if err != nil { + return nil, err + } + i, err := strconv.Atoi(strings.TrimPrefix(string(b), "cursor")) + if err != nil { + return nil, err + } + from = i + } + + to := len(ids) + if first != nil { + to = from + *first + if to > len(ids) { + to = len(ids) + } + } + + return &models.FriendsConnection{ + Ids: ids, + From: from, + To: to, + }, nil +} + +func (r *friendsConnectionResolver) Edges(ctx context.Context, obj *models.FriendsConnection) ([]models.FriendsEdge, error) { + friends, err := r.resolveCharacters(ctx, obj.Ids) if err != nil { return nil, err } - edges := make([]FriendsEdge, obj.to-obj.from) + edges := make([]models.FriendsEdge, obj.To-obj.From) for i := range edges { - edges[i] = FriendsEdge{ - Cursor: encodeCursor(obj.from + i), - Node: friends[obj.from+i], + edges[i] = models.FriendsEdge{ + Cursor: models.EncodeCursor(obj.From + i), + Node: friends[obj.From+i], } } return edges, nil } -func (r *friendsConnectionResolver) Friends(ctx context.Context, obj *FriendsConnection) ([]Character, error) { - return r.resolveCharacters(ctx, obj.ids) +func (r *friendsConnectionResolver) Friends(ctx context.Context, obj *models.FriendsConnection) ([]models.Character, error) { + return r.resolveCharacters(ctx, obj.Ids) } type humanResolver struct{ *Resolver } -func (r *humanResolver) Friends(ctx context.Context, obj *Human) ([]Character, error) { +func (r *humanResolver) Friends(ctx context.Context, obj *models.Human) ([]models.Character, error) { return r.resolveCharacters(ctx, obj.FriendIds) } -func (r *humanResolver) FriendsConnection(ctx context.Context, obj *Human, first *int, after *string) (FriendsConnection, error) { +func (r *humanResolver) FriendsConnection(ctx context.Context, obj *models.Human, first *int, after *string) (*models.FriendsConnection, error) { return r.resolveFriendConnection(ctx, obj.FriendIds, first, after) } -func (r *humanResolver) Starships(ctx context.Context, obj *Human) ([]Starship, error) { - var result []Starship +func (r *humanResolver) Starships(ctx context.Context, obj *models.Human) ([]models.Starship, error) { + var result []models.Starship for _, id := range obj.StarshipIds { char, err := r.Query().Starship(ctx, id) if err != nil { @@ -110,7 +146,7 @@ func (r *humanResolver) Starships(ctx context.Context, obj *Human) ([]Starship, type mutationResolver struct{ *Resolver } -func (r *mutationResolver) CreateReview(ctx context.Context, episode Episode, review Review) (*Review, error) { +func (r *mutationResolver) CreateReview(ctx context.Context, episode models.Episode, review models.Review) (*models.Review, error) { review.Time = time.Now() time.Sleep(1 * time.Second) r.reviews[episode] = append(r.reviews[episode], review) @@ -119,19 +155,19 @@ func (r *mutationResolver) CreateReview(ctx context.Context, episode Episode, re type queryResolver struct{ *Resolver } -func (r *queryResolver) Hero(ctx context.Context, episode *Episode) (Character, error) { - if *episode == EpisodeEmpire { +func (r *queryResolver) Hero(ctx context.Context, episode *models.Episode) (models.Character, error) { + if *episode == models.EpisodeEmpire { return r.humans["1000"], nil } return r.droid["2001"], nil } -func (r *queryResolver) Reviews(ctx context.Context, episode Episode, since *time.Time) ([]Review, error) { +func (r *queryResolver) Reviews(ctx context.Context, episode models.Episode, since *time.Time) ([]models.Review, error) { if since == nil { return r.reviews[episode], nil } - var filtered []Review + var filtered []models.Review for _, rev := range r.reviews[episode] { if rev.Time.After(*since) { filtered = append(filtered, rev) @@ -140,8 +176,8 @@ func (r *queryResolver) Reviews(ctx context.Context, episode Episode, since *tim return filtered, nil } -func (r *queryResolver) Search(ctx context.Context, text string) ([]SearchResult, error) { - var l []SearchResult +func (r *queryResolver) Search(ctx context.Context, text string) ([]models.SearchResult, error) { + var l []models.SearchResult for _, h := range r.humans { if strings.Contains(h.Name, text) { l = append(l, h) @@ -160,7 +196,7 @@ func (r *queryResolver) Search(ctx context.Context, text string) ([]SearchResult return l, nil } -func (r *queryResolver) Character(ctx context.Context, id string) (Character, error) { +func (r *queryResolver) Character(ctx context.Context, id string) (models.Character, error) { if h, ok := r.humans[id]; ok { return &h, nil } @@ -170,21 +206,21 @@ func (r *queryResolver) Character(ctx context.Context, id string) (Character, er return nil, nil } -func (r *queryResolver) Droid(ctx context.Context, id string) (*Droid, error) { +func (r *queryResolver) Droid(ctx context.Context, id string) (*models.Droid, error) { if d, ok := r.droid[id]; ok { return &d, nil } return nil, nil } -func (r *queryResolver) Human(ctx context.Context, id string) (*Human, error) { +func (r *queryResolver) Human(ctx context.Context, id string) (*models.Human, error) { if h, ok := r.humans[id]; ok { return &h, nil } return nil, nil } -func (r *queryResolver) Starship(ctx context.Context, id string) (*Starship, error) { +func (r *queryResolver) Starship(ctx context.Context, id string) (*models.Starship, error) { if s, ok := r.starships[id]; ok { return &s, nil } @@ -193,97 +229,97 @@ func (r *queryResolver) Starship(ctx context.Context, id string) (*Starship, err type starshipResolver struct{ *Resolver } -func (r *starshipResolver) Length(ctx context.Context, obj *Starship, unit *LengthUnit) (float64, error) { +func (r *starshipResolver) Length(ctx context.Context, obj *models.Starship, unit *models.LengthUnit) (float64, error) { switch *unit { - case LengthUnitMeter, "": + case models.LengthUnitMeter, "": return obj.Length, nil - case LengthUnitFoot: + case models.LengthUnitFoot: return obj.Length * 3.28084, nil default: return 0, errors.New("invalid unit") } } -func NewResolver() Config { +func NewResolver() generated.Config { r := Resolver{} - r.humans = map[string]Human{ + r.humans = map[string]models.Human{ "1000": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1000", Name: "Luke Skywalker", FriendIds: []string{"1002", "1003", "2000", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.72, + HeightMeters: 1.72, Mass: 77, StarshipIds: []string{"3001", "3003"}, }, "1001": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1001", Name: "Darth Vader", FriendIds: []string{"1004"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 2.02, + HeightMeters: 2.02, Mass: 136, StarshipIds: []string{"3002"}, }, "1002": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1002", Name: "Han Solo", FriendIds: []string{"1000", "1003", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.8, + HeightMeters: 1.8, Mass: 80, StarshipIds: []string{"3000", "3003"}, }, "1003": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1003", Name: "Leia Organa", FriendIds: []string{"1000", "1002", "2000", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.5, + HeightMeters: 1.5, Mass: 49, }, "1004": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1004", Name: "Wilhuff Tarkin", FriendIds: []string{"1001"}, - AppearsIn: []Episode{EpisodeNewhope}, + AppearsIn: []models.Episode{models.EpisodeNewhope}, }, - heightMeters: 1.8, + HeightMeters: 1.8, Mass: 0, }, } - r.droid = map[string]Droid{ + r.droid = map[string]models.Droid{ "2000": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "2000", Name: "C-3PO", FriendIds: []string{"1000", "1002", "1003", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, PrimaryFunction: "Protocol", }, "2001": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "2001", Name: "R2-D2", FriendIds: []string{"1000", "1002", "1003"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, PrimaryFunction: "Astromech", }, } - r.starships = map[string]Starship{ + r.starships = map[string]models.Starship{ "3000": { ID: "3000", Name: "Millennium Falcon", @@ -330,9 +366,9 @@ func NewResolver() Config { }, } - r.reviews = map[Episode][]Review{} + r.reviews = map[models.Episode][]models.Review{} - return Config{ + return generated.Config{ Resolvers: &r, } } diff --git a/example/starwars/server/server.go b/example/starwars/server/server.go index 20d23cfaf0..d082d3d92e 100644 --- a/example/starwars/server/server.go +++ b/example/starwars/server/server.go @@ -7,13 +7,14 @@ import ( "net/http" "github.com/99designs/gqlgen/example/starwars" + "github.com/99designs/gqlgen/example/starwars/generated" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/handler" ) func main() { http.Handle("/", handler.Playground("Starwars", "/query")) - http.Handle("/query", handler.GraphQL(starwars.NewExecutableSchema(starwars.NewResolver()), + http.Handle("/query", handler.GraphQL(generated.NewExecutableSchema(starwars.NewResolver()), handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { rc := graphql.GetResolverContext(ctx) fmt.Println("Entered", rc.Object, rc.Field.Name) diff --git a/example/starwars/starwars_test.go b/example/starwars/starwars_test.go index d22e9b3209..53f33d34f5 100644 --- a/example/starwars/starwars_test.go +++ b/example/starwars/starwars_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/example/starwars/generated" "github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/handler" "github.com/stretchr/testify/require" ) func TestStarwars(t *testing.T) { - srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(NewResolver()))) + srv := httptest.NewServer(handler.GraphQL(generated.NewExecutableSchema(NewResolver()))) c := client.New(srv.URL) t.Run("Lukes starships", func(t *testing.T) { @@ -215,7 +216,7 @@ func TestStarwars(t *testing.T) { } }`, &resp, client.Var("episode", "INVALID")) - require.EqualError(t, err, `[{"message":"INVALID is not a valid Episode"}]`) + require.EqualError(t, err, `[{"message":"INVALID is not a valid Episode","path":["createReview"]}]`) }) t.Run("introspection", func(t *testing.T) { diff --git a/example/todo/generated.go b/example/todo/generated.go index 2fbe0d159e..08ffac652d 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -15,6 +15,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -46,20 +48,20 @@ type ComplexityRoot struct { } MyQuery struct { - Todo func(childComplexity int, id int) int LastTodo func(childComplexity int) int + Todo func(childComplexity int, id int) int Todos func(childComplexity int) int } Todo struct { - Id func(childComplexity int) int - Text func(childComplexity int) int Done func(childComplexity int) int + ID func(childComplexity int) int + Text func(childComplexity int) int } } type MyMutationResolver interface { - CreateTodo(ctx context.Context, todo TodoInput) (Todo, error) + CreateTodo(ctx context.Context, todo TodoInput) (*Todo, error) UpdateTodo(ctx context.Context, id int, changes map[string]interface{}) (*Todo, error) } type MyQueryResolver interface { @@ -68,120 +70,6 @@ type MyQueryResolver interface { Todos(ctx context.Context) ([]Todo, error) } -func field_MyMutation_createTodo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 TodoInput - if tmp, ok := rawArgs["todo"]; ok { - var err error - arg0, err = UnmarshalTodoInput(tmp) - if err != nil { - return nil, err - } - } - args["todo"] = arg0 - return args, nil - -} - -func field_MyMutation_updateTodo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - var arg1 map[string]interface{} - if tmp, ok := rawArgs["changes"]; ok { - var err error - arg1 = tmp.(map[string]interface{}) - if err != nil { - return nil, err - } - } - args["changes"] = arg1 - return args, nil - -} - -func field_MyQuery_todo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - return args, nil - -} - -func field_MyQuery___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func dir_hasRole_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 Role - if tmp, ok := rawArgs["role"]; ok { - var err error - err = (&arg0).UnmarshalGQL(tmp) - if err != nil { - return nil, err - } - } - args["role"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -193,78 +81,80 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "MyMutation.createTodo": + case "MyMutation.CreateTodo": if e.complexity.MyMutation.CreateTodo == nil { break } - args, err := field_MyMutation_createTodo_args(rawArgs) + args, err := ec.field_MyMutation_createTodo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.MyMutation.CreateTodo(childComplexity, args["todo"].(TodoInput)), true - case "MyMutation.updateTodo": + case "MyMutation.UpdateTodo": if e.complexity.MyMutation.UpdateTodo == nil { break } - args, err := field_MyMutation_updateTodo_args(rawArgs) + args, err := ec.field_MyMutation_updateTodo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.MyMutation.UpdateTodo(childComplexity, args["id"].(int), args["changes"].(map[string]interface{})), true - case "MyQuery.todo": + case "MyQuery.LastTodo": + if e.complexity.MyQuery.LastTodo == nil { + break + } + + return e.complexity.MyQuery.LastTodo(childComplexity), true + + case "MyQuery.Todo": if e.complexity.MyQuery.Todo == nil { break } - args, err := field_MyQuery_todo_args(rawArgs) + args, err := ec.field_MyQuery_todo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.MyQuery.Todo(childComplexity, args["id"].(int)), true - case "MyQuery.lastTodo": - if e.complexity.MyQuery.LastTodo == nil { - break - } - - return e.complexity.MyQuery.LastTodo(childComplexity), true - - case "MyQuery.todos": + case "MyQuery.Todos": if e.complexity.MyQuery.Todos == nil { break } return e.complexity.MyQuery.Todos(childComplexity), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "Todo.Done": + if e.complexity.Todo.Done == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.Todo.Done(childComplexity), true - case "Todo.text": - if e.complexity.Todo.Text == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Text(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.done": - if e.complexity.Todo.Done == nil { + case "Todo.Text": + if e.complexity.Todo.Text == nil { break } - return e.complexity.Todo.Done(childComplexity), true + return e.complexity.Todo.Text(childComplexity), true } return 0, false @@ -283,7 +173,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -312,186 +203,265 @@ type executionContext struct { *executableSchema } -var myMutationImplementors = []string{"MyMutation"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, myMutationImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "MyMutation", - }) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("MyMutation") - case "createTodo": - out.Values[i] = ec._MyMutation_createTodo(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + rctx := graphql.GetResolverContext(ctx) + for _, d := range rctx.Field.Definition.Directives { + switch d.Name { + case "hasRole": + if ec.directives.HasRole != nil { + rawArgs := d.ArgumentMap(ec.Variables) + args, err := ec.dir_hasRole_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return nil + } + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.HasRole(ctx, obj, n, args["role"].(Role)) + } } - case "updateTodo": - out.Values[i] = ec._MyMutation_updateTodo(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) } } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyMutation_createTodo_args(rawArgs) + res, err := ec.ResolverMiddleware(ctx, next) if err != nil { ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "MyMutation", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.MyMutation().CreateTodo(rctx, args["todo"].(TodoInput)) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null + return nil } - res := resTmp.(Todo) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Todo(ctx, field.Selections, &res) + return res } -// nolint: vetshadow -func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyMutation_updateTodo_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "MyMutation", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.MyMutation().UpdateTodo(rctx, args["id"].(int), args["changes"].(map[string]interface{})) - }) - if resTmp == nil { - return graphql.Null +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(*Todo) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return introspection.WrapSchema(parsedSchema), nil +} - if res == nil { - return graphql.Null +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - - return ec._Todo(ctx, field.Selections, res) + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var myQueryImplementors = []string{"MyQuery"} +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `schema { + query: MyQuery + mutation: MyMutation +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, myQueryImplementors) +type MyQuery { + todo(id: ID!): Todo + lastTodo: Todo + todos: [Todo!]! +} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "MyQuery", - }) +type MyMutation { + createTodo(todo: TodoInput!): Todo! + updateTodo(id: ID!, changes: Map!): Todo +} - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +type Todo { + id: ID! + text: String! + done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done +} - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("MyQuery") - case "todo": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._MyQuery_todo(ctx, field) - wg.Done() - }(i, field) - case "lastTodo": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._MyQuery_lastTodo(ctx, field) - wg.Done() - }(i, field) - case "todos": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._MyQuery_todos(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._MyQuery___type(ctx, field) - case "__schema": - out.Values[i] = ec._MyQuery___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) +"Passed to createTodo to create a new todo" +input TodoInput { + "The body text" + text: String! + "Is it done already?" + done: Boolean +} + +scalar Map + +"Prevents access to a field if the user doesnt have the matching role" +directive @hasRole(role: Role!) on FIELD_DEFINITION + +enum Role { + ADMIN + OWNER +} +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) dir_hasRole_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 Role + if tmp, ok := rawArgs["role"]; ok { + arg0, err = ec.unmarshalNRole2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐRole(ctx, tmp) + if err != nil { + return nil, err } } - wg.Wait() - if invalid { - return graphql.Null + args["role"] = arg0 + return args, nil +} + +func (ec *executionContext) field_MyMutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 TodoInput + if tmp, ok := rawArgs["todo"]; ok { + arg0, err = ec.unmarshalNTodoInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodoInput(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["todo"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) field_MyMutation_updateTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + var arg1 map[string]interface{} + if tmp, ok := rawArgs["changes"]; ok { + arg1, err = ec.unmarshalNMap2map(ctx, tmp) + if err != nil { + return nil, err + } + } + args["changes"] = arg1 + return args, nil +} + +func (ec *executionContext) field_MyQuery___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_MyQuery_todo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyMutation", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyQuery_todo_args(rawArgs) + args, err := ec.field_MyMutation_createTodo_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.MyMutation().CreateTodo(rctx, args["todo"].(TodoInput)) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*Todo) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: args, - Field: field, + Object: "MyMutation", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_MyMutation_updateTodo_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.MyQuery().Todo(rctx, args["id"].(int)) + return ec.resolvers.MyMutation().UpdateTodo(rctx, args["id"].(int), args["changes"].(map[string]interface{})) }) if resTmp == nil { return graphql.Null @@ -499,22 +469,48 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col res := resTmp.(*Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_MyQuery_todo_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) return graphql.Null } - - return ec._Todo(ctx, field.Selections, res) + rctx.Args = args + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.MyQuery().Todo(rctx, args["id"].(int)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Todo) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery_lastTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: nil, - Field: field, + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -528,22 +524,17 @@ func (ec *executionContext) _MyQuery_lastTodo(ctx context.Context, field graphql res := resTmp.(*Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Todo(ctx, field.Selections, res) + return ec.marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: nil, - Field: field, + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -560,58 +551,26 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co res := resTmp.([]Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Todo(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyQuery___type_args(rawArgs) + args, err := ec.field_MyQuery___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -623,22 +582,17 @@ func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.C res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: nil, - Field: field, + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -652,62 +606,17 @@ func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) -} - -var todoImplementors = []string{"Todo"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, todoImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Todo") - case "id": - out.Values[i] = ec._Todo_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "text": - out.Values[i] = ec._Todo_text(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "done": - out.Values[i] = ec._Todo_done(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -724,17 +633,17 @@ func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.Collecte res := resTmp.(int) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalInt(res) + return ec.marshalNID2int(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -751,17 +660,17 @@ func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -778,59 +687,17 @@ func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.Collec res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -847,17 +714,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -871,17 +738,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -898,26 +765,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -934,89 +792,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1033,17 +819,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1057,17 +843,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1084,17 +870,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1108,70 +894,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1188,17 +921,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1212,17 +945,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1239,50 +972,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1299,25 +999,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1334,17 +1026,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1358,60 +1050,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1428,17 +1077,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1452,17 +1101,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1479,25 +1128,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1511,125 +1152,44 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - return graphql.MarshalString(*res) + res := resTmp.([]introspection.Type) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]introspection.Type) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1646,25 +1206,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1678,22 +1230,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1707,22 +1254,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1739,96 +1281,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1845,17 +1308,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1869,21 +1332,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1897,25 +1356,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1927,50 +1387,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1984,50 +1411,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2041,58 +1435,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2104,50 +1466,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2161,50 +1490,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2218,15 +1514,14 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } +// endregion **************************** field.gotpl ***************************** - return ec.___Type(ctx, field.Selections, res) -} +// region **************************** input.gotpl ***************************** -func UnmarshalTodoInput(v interface{}) (TodoInput, error) { +func (ec *executionContext) unmarshalInputTodoInput(ctx context.Context, v interface{}) (TodoInput, error) { var it TodoInput var asMap = v.(map[string]interface{}) @@ -2234,18 +1529,13 @@ func UnmarshalTodoInput(v interface{}) (TodoInput, error) { switch k { case "text": var err error - it.Text, err = graphql.UnmarshalString(v) + it.Text, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } case "done": var err error - var ptr1 bool - if v != nil { - ptr1, err = graphql.UnmarshalBoolean(v) - it.Done = &ptr1 - } - + it.Done, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err } @@ -2255,92 +1545,951 @@ func UnmarshalTodoInput(v interface{}) (TodoInput, error) { return it, nil } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - rctx := graphql.GetResolverContext(ctx) - for _, d := range rctx.Field.Definition.Directives { - switch d.Name { - case "hasRole": - if ec.directives.HasRole != nil { - rawArgs := d.ArgumentMap(ec.Variables) - args, err := dir_hasRole_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return nil - } - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.HasRole(ctx, obj, n, args["role"].(Role)) - } +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var myMutationImplementors = []string{"MyMutation"} + +func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, myMutationImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyMutation", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("MyMutation") + case "createTodo": + out.Values[i] = ec._MyMutation_createTodo(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true } + case "updateTodo": + out.Values[i] = ec._MyMutation_updateTodo(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) } } - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil + out.Dispatch() + if invalid { + return graphql.Null } - return res + return out } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var myQueryImplementors = []string{"MyQuery"} + +func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, myQueryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyQuery", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("MyQuery") + case "todo": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MyQuery_todo(ctx, field) + return res + }) + case "lastTodo": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MyQuery_lastTodo(ctx, field) + return res + }) + case "todos": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MyQuery_todos(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "__type": + out.Values[i] = ec._MyQuery___type(ctx, field) + case "__schema": + out.Values[i] = ec._MyQuery___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapSchema(parsedSchema), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +var todoImplementors = []string{"Todo"} + +func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, todoImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Todo") + case "id": + out.Values[i] = ec._Todo_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "text": + out.Values[i] = ec._Todo_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "done": + out.Values[i] = ec._Todo_done(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `schema { - query: MyQuery - mutation: MyMutation -} +var __DirectiveImplementors = []string{"__Directive"} -type MyQuery { - todo(id: Int!): Todo - lastTodo: Todo - todos: [Todo!]! -} +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) -type MyMutation { - createTodo(todo: TodoInput!): Todo! - updateTodo(id: Int!, changes: Map!): Todo + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -type Todo { - id: Int! - text: String! - done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done -} +var __EnumValueImplementors = []string{"__EnumValue"} -"Passed to createTodo to create a new todo" -input TodoInput { - "The body text" - text: String! - "Is it done already?" - done: Boolean +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -scalar Map +var __FieldImplementors = []string{"__Field"} -"Prevents access to a field if the user doesnt have the matching role" -directive @hasRole(role: Role!) on FIELD_DEFINITION +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) -enum Role { - ADMIN - OWNER -} -`}, -) + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNID2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalIntID(v) +} + +func (ec *executionContext) marshalNID2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalIntID(v) +} + +func (ec *executionContext) unmarshalNMap2map(ctx context.Context, v interface{}) (map[string]interface{}, error) { + if v == nil { + return nil, nil + } + return graphql.UnmarshalMap(v) +} + +func (ec *executionContext) marshalNMap2map(ctx context.Context, sel ast.SelectionSet, v map[string]interface{}) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return graphql.MarshalMap(v) +} + +func (ec *executionContext) unmarshalNRole2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐRole(ctx context.Context, v interface{}) (Role, error) { + var res Role + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNRole2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐRole(ctx context.Context, sel ast.SelectionSet, v Role) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx context.Context, sel ast.SelectionSet, v Todo) graphql.Marshaler { + return ec._Todo(ctx, sel, &v) +} + +func (ec *executionContext) marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx context.Context, sel ast.SelectionSet, v []Todo) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx context.Context, sel ast.SelectionSet, v *Todo) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Todo(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNTodoInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodoInput(ctx context.Context, v interface{}) (TodoInput, error) { + return ec.unmarshalInputTodoInput(ctx, v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalOTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx context.Context, sel ast.SelectionSet, v Todo) graphql.Marshaler { + return ec._Todo(ctx, sel, &v) +} + +func (ec *executionContext) marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtodoᚐTodo(ctx context.Context, sel ast.SelectionSet, v *Todo) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Todo(ctx, sel, v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/todo/gqlgen.yml b/example/todo/gqlgen.yml index 5404738eb2..c9fe56375e 100644 --- a/example/todo/gqlgen.yml +++ b/example/todo/gqlgen.yml @@ -1,3 +1,7 @@ models: Todo: model: github.com/99designs/gqlgen/example/todo.Todo + ID: + model: # override the default id marshaller to use ints + - github.com/99designs/gqlgen/graphql.IntID + - github.com/99designs/gqlgen/graphql.ID diff --git a/example/todo/models_gen.go b/example/todo/models_gen.go index 2d7a219ac0..74a1c0da57 100644 --- a/example/todo/models_gen.go +++ b/example/todo/models_gen.go @@ -10,8 +10,10 @@ import ( // Passed to createTodo to create a new todo type TodoInput struct { + // The body text Text string `json:"text"` - Done *bool `json:"done"` + // Is it done already? + Done *bool `json:"done"` } type Role string @@ -21,6 +23,11 @@ const ( RoleOwner Role = "OWNER" ) +var AllRole = []Role{ + RoleAdmin, + RoleOwner, +} + func (e Role) IsValid() bool { switch e { case RoleAdmin, RoleOwner: diff --git a/example/todo/schema.graphql b/example/todo/schema.graphql index b4263454cb..8adac85147 100644 --- a/example/todo/schema.graphql +++ b/example/todo/schema.graphql @@ -4,18 +4,18 @@ schema { } type MyQuery { - todo(id: Int!): Todo + todo(id: ID!): Todo lastTodo: Todo todos: [Todo!]! } type MyMutation { createTodo(todo: TodoInput!): Todo! - updateTodo(id: Int!, changes: Map!): Todo + updateTodo(id: ID!, changes: Map!): Todo } type Todo { - id: Int! + id: ID! text: String! done: Boolean! @hasRole(role: OWNER) # only the owner can see if a todo is done } diff --git a/example/todo/todo.go b/example/todo/todo.go index 05846810e2..86efdabfed 100644 --- a/example/todo/todo.go +++ b/example/todo/todo.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package todo @@ -33,10 +33,6 @@ func New() Config { // No admin for you! return nil, nil case RoleOwner: - // This is also available in context - if obj != graphql.GetResolverContext(ctx).Parent.Result { - return nil, fmt.Errorf("parent type mismatch") - } ownable, isOwnable := obj.(Ownable) if !isOwnable { return nil, fmt.Errorf("obj cant be owned") @@ -95,7 +91,7 @@ func (r *QueryResolver) Todos(ctx context.Context) ([]Todo, error) { type MutationResolver resolvers -func (r *MutationResolver) CreateTodo(ctx context.Context, todo TodoInput) (Todo, error) { +func (r *MutationResolver) CreateTodo(ctx context.Context, todo TodoInput) (*Todo, error) { newID := r.id() newTodo := Todo{ @@ -110,7 +106,7 @@ func (r *MutationResolver) CreateTodo(ctx context.Context, todo TodoInput) (Todo r.todos = append(r.todos, newTodo) - return newTodo, nil + return &newTodo, nil } func (r *MutationResolver) UpdateTodo(ctx context.Context, id int, changes map[string]interface{}) (*Todo, error) { diff --git a/example/todo/todo_test.go b/example/todo/todo_test.go index 04a4d557ec..2b3296d72a 100644 --- a/example/todo/todo_test.go +++ b/example/todo/todo_test.go @@ -15,18 +15,18 @@ func TestTodo(t *testing.T) { c := client.New(srv.URL) var resp struct { - CreateTodo struct{ ID int } + CreateTodo struct{ ID string } } c.MustPost(`mutation { createTodo(todo:{text:"Fery important"}) { id } }`, &resp) - require.Equal(t, 5, resp.CreateTodo.ID) + require.Equal(t, "5", resp.CreateTodo.ID) t.Run("update the todo text", func(t *testing.T) { var resp struct { UpdateTodo struct{ Text string } } c.MustPost( - `mutation($id: Int!, $text: String!) { updateTodo(id: $id, changes:{text:$text}) { text } }`, + `mutation($id: ID!, $text: String!) { updateTodo(id: $id, changes:{text:$text}) { text } }`, &resp, client.Var("id", 5), client.Var("text", "Very important"), @@ -58,12 +58,12 @@ func TestTodo(t *testing.T) { t.Run("select with alias", func(t *testing.T) { var resp struct { A struct{ Text string } - B struct{ ID int } + B struct{ ID string } } c.MustPost(`{ a: todo(id:1) { text } b: todo(id:2) { id } }`, &resp) require.Equal(t, "A todo not to forget", resp.A.Text) - require.Equal(t, 2, resp.B.ID) + require.Equal(t, "2", resp.B.ID) }) t.Run("find a missing todo", func(t *testing.T) { @@ -101,17 +101,17 @@ func TestTodo(t *testing.T) { t.Run("select all", func(t *testing.T) { var resp struct { Todo struct { - ID int + ID string Text string Done bool } LastTodo struct { - ID int + ID string Text string Done bool } Todos []struct { - ID int + ID string Text string } } @@ -121,11 +121,11 @@ func TestTodo(t *testing.T) { todos { id text } }`, &resp) - require.Equal(t, 1, resp.Todo.ID) - require.Equal(t, 5, resp.LastTodo.ID) + require.Equal(t, "1", resp.Todo.ID) + require.Equal(t, "5", resp.LastTodo.ID) require.Len(t, resp.Todos, 5) require.Equal(t, "Very important", resp.LastTodo.Text) - require.Equal(t, 5, resp.LastTodo.ID) + require.Equal(t, "5", resp.LastTodo.ID) }) t.Run("introspection", func(t *testing.T) { diff --git a/example/type-system-extension/generated.go b/example/type-system-extension/generated.go index 065da51a59..d15500fd9f 100644 --- a/example/type-system-extension/generated.go +++ b/example/type-system-extension/generated.go @@ -16,6 +16,8 @@ import ( "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -58,101 +60,26 @@ type ComplexityRoot struct { } MyQuery struct { - Todos func(childComplexity int) int Todo func(childComplexity int, id string) int + Todos func(childComplexity int) int } Todo struct { - Id func(childComplexity int) int - Text func(childComplexity int) int + ID func(childComplexity int) int State func(childComplexity int) int + Text func(childComplexity int) int Verified func(childComplexity int) int } } type MyMutationResolver interface { - CreateTodo(ctx context.Context, todo TodoInput) (Todo, error) + CreateTodo(ctx context.Context, todo TodoInput) (*Todo, error) } type MyQueryResolver interface { Todos(ctx context.Context) ([]Todo, error) Todo(ctx context.Context, id string) (*Todo, error) } -func field_MyMutation_createTodo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 TodoInput - if tmp, ok := rawArgs["todo"]; ok { - var err error - arg0, err = UnmarshalTodoInput(tmp) - if err != nil { - return nil, err - } - } - args["todo"] = arg0 - return args, nil - -} - -func field_MyQuery_todo_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["id"]; ok { - var err error - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - return args, nil - -} - -func field_MyQuery___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -164,61 +91,63 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "MyMutation.createTodo": + case "MyMutation.CreateTodo": if e.complexity.MyMutation.CreateTodo == nil { break } - args, err := field_MyMutation_createTodo_args(rawArgs) + args, err := ec.field_MyMutation_createTodo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.MyMutation.CreateTodo(childComplexity, args["todo"].(TodoInput)), true - case "MyQuery.todos": - if e.complexity.MyQuery.Todos == nil { - break - } - - return e.complexity.MyQuery.Todos(childComplexity), true - - case "MyQuery.todo": + case "MyQuery.Todo": if e.complexity.MyQuery.Todo == nil { break } - args, err := field_MyQuery_todo_args(rawArgs) + args, err := ec.field_MyQuery_todo_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.MyQuery.Todo(childComplexity, args["id"].(string)), true - case "Todo.id": - if e.complexity.Todo.Id == nil { + case "MyQuery.Todos": + if e.complexity.MyQuery.Todos == nil { break } - return e.complexity.Todo.Id(childComplexity), true + return e.complexity.MyQuery.Todos(childComplexity), true - case "Todo.text": - if e.complexity.Todo.Text == nil { + case "Todo.ID": + if e.complexity.Todo.ID == nil { break } - return e.complexity.Todo.Text(childComplexity), true + return e.complexity.Todo.ID(childComplexity), true - case "Todo.state": + case "Todo.State": if e.complexity.Todo.State == nil { break } return e.complexity.Todo.State(childComplexity), true - case "Todo.verified": + case "Todo.Text": + if e.complexity.Todo.Text == nil { + break + } + + return e.complexity.Todo.Text(childComplexity), true + + case "Todo.Verified": if e.complexity.Todo.Verified == nil { break } @@ -242,7 +171,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -271,137 +201,266 @@ type executionContext struct { *executableSchema } -var myMutationImplementors = []string{"MyMutation"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, myMutationImplementors) - - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "MyMutation", - }) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("MyMutation") - case "createTodo": - out.Values[i] = ec._MyMutation_createTodo(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + rctx := graphql.GetResolverContext(ctx) + for _, d := range rctx.Field.Definition.Directives { + switch d.Name { + case "enumLogging": + if ec.directives.EnumLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.EnumLogging(ctx, obj, n) + } + } + case "fieldLogging": + if ec.directives.FieldLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.FieldLogging(ctx, obj, n) + } + } + case "inputLogging": + if ec.directives.InputLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.InputLogging(ctx, obj, n) + } + } + case "interfaceLogging": + if ec.directives.InterfaceLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.InterfaceLogging(ctx, obj, n) + } + } + case "objectLogging": + if ec.directives.ObjectLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.ObjectLogging(ctx, obj, n) + } + } + case "scalarLogging": + if ec.directives.ScalarLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.ScalarLogging(ctx, obj, n) + } + } + case "unionLogging": + if ec.directives.UnionLogging != nil { + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.UnionLogging(ctx, obj, n) + } } - default: - panic("unknown field " + strconv.Quote(field.Name)) } } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyMutation_createTodo_args(rawArgs) + res, err := ec.ResolverMiddleware(ctx, next) if err != nil { ec.Error(ctx, err) - return graphql.Null - } - rctx := &graphql.ResolverContext{ - Object: "MyMutation", - Args: args, - Field: field, + return nil } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.MyMutation().CreateTodo(rctx, args["todo"].(TodoInput)) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null + return res +} + +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(Todo) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) + return introspection.WrapSchema(parsedSchema), nil +} - return ec._Todo(ctx, field.Selections, &res) +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -var myQueryImplementors = []string{"MyQuery"} +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schemas/enum-extension.graphql", Input: `directive @enumLogging on ENUM -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, myQueryImplementors) +extend enum State @enumLogging +`}, + &ast.Source{Name: "schemas/input-object-extension.graphql", Input: `directive @inputLogging on INPUT_OBJECT - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "MyQuery", - }) +extend input TodoInput @inputLogging +`}, + &ast.Source{Name: "schemas/interface-extension.graphql", Input: `directive @interfaceLogging on INTERFACE - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +extend interface Node @interfaceLogging +`}, + &ast.Source{Name: "schemas/object-extension.graphql", Input: `directive @objectLogging on OBJECT - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("MyQuery") - case "todos": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._MyQuery_todos(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "todo": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._MyQuery_todo(ctx, field) - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._MyQuery___type(ctx, field) - case "__schema": - out.Values[i] = ec._MyQuery___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out +extend type Todo @objectLogging +`}, + &ast.Source{Name: "schemas/scalar-extension.graphql", Input: `directive @scalarLogging on SCALAR + +extend scalar ID @scalarLogging +`}, + &ast.Source{Name: "schemas/schema-extension.graphql", Input: `extend schema { + mutation: MyMutation } -// nolint: vetshadow -func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() +extend type MyQuery { + todo(id: ID!): Todo +} + +type MyMutation { + createTodo(todo: TodoInput!): Todo! +} + +input TodoInput { + text: String! +} +`}, + &ast.Source{Name: "schemas/schema.graphql", Input: `# GraphQL schema example +# +# https://gqlgen.com/getting-started/ + +schema { + query: MyQuery +} + +interface Node { + id: ID! +} + +type Todo implements Node { + id: ID! + text: String! + state: State! +} + +type MyQuery { + todos: [Todo!]! +} + +union Data = Todo + +enum State { + NOT_YET + DONE +} +`}, + &ast.Source{Name: "schemas/type-extension.graphql", Input: `directive @fieldLogging on FIELD_DEFINITION + +extend type Todo { + verified: Boolean! @fieldLogging +} +`}, + &ast.Source{Name: "schemas/union-extension.graphql", Input: `directive @unionLogging on UNION + +extend union Data @unionLogging +`}, +) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_MyMutation_createTodo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 TodoInput + if tmp, ok := rawArgs["todo"]; ok { + arg0, err = ec.unmarshalNTodoInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodoInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["todo"] = arg0 + return args, nil +} + +func (ec *executionContext) field_MyQuery___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_MyQuery_todo_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: nil, - Field: field, + Object: "MyMutation", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_MyMutation_createTodo_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.MyQuery().Todos(rctx) + return ec.resolvers.MyMutation().CreateTodo(rctx, args["todo"].(TodoInput)) }) if resTmp == nil { if !ec.HasError(rctx) { @@ -409,61 +468,56 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.([]Todo) + res := resTmp.(*Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec._Todo(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.MyQuery().Todos(rctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - + return graphql.Null } - wg.Wait() - return arr1 + res := resTmp.([]Todo) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyQuery_todo_args(rawArgs) + args, err := ec.field_MyQuery_todo_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -475,30 +529,26 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col res := resTmp.(*Todo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Todo(ctx, field.Selections, res) + return ec.marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_MyQuery___type_args(rawArgs) + args, err := ec.field_MyQuery___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -510,22 +560,17 @@ func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.C res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "MyQuery", - Args: nil, - Field: field, + Object: "MyQuery", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -539,67 +584,17 @@ func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Schema(ctx, field.Selections, res) -} - -var todoImplementors = []string{"Todo", "Node"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, todoImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Todo") - case "id": - out.Values[i] = ec._Todo_id(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "text": - out.Values[i] = ec._Todo_text(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "state": - out.Values[i] = ec._Todo_state(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "verified": - out.Values[i] = ec._Todo_verified(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -616,17 +611,17 @@ func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.Collecte res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalID(res) + return ec.marshalNID2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -643,17 +638,17 @@ func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.Collec res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_state(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -670,17 +665,17 @@ func (ec *executionContext) _Todo_state(ctx context.Context, field graphql.Colle res := resTmp.(State) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return res + return ec.marshalNState2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐState(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Todo_verified(ctx context.Context, field graphql.CollectedField, obj *Todo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Todo", - Args: nil, - Field: field, + Object: "Todo", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -697,86 +692,44 @@ func (ec *executionContext) _Todo_verified(ctx context.Context, field graphql.Co res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) +} - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -790,17 +743,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -817,26 +770,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -853,89 +797,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -952,17 +824,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -976,17 +848,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1003,17 +875,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1027,70 +899,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1107,17 +926,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1131,17 +950,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1158,50 +977,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1218,25 +1004,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1253,17 +1031,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1277,60 +1055,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1347,17 +1082,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1371,17 +1106,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1398,25 +1133,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1430,125 +1157,44 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Types(), nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1565,25 +1211,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1597,22 +1235,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1626,22 +1259,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1658,96 +1286,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1764,17 +1313,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1788,21 +1337,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1816,25 +1361,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -1846,50 +1392,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1903,50 +1416,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1960,58 +1440,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2023,50 +1471,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2080,50 +1495,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2137,14 +1519,35 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +func (ec *executionContext) unmarshalInputTodoInput(ctx context.Context, v interface{}) (TodoInput, error) { + var it TodoInput + var asMap = v.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "text": + var err error + it.Text, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + } } - return ec.___Type(ctx, field.Selections, res) + return it, nil } +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + func (ec *executionContext) _Data(ctx context.Context, sel ast.SelectionSet, obj *Data) graphql.Marshaler { switch obj := (*obj).(type) { case nil: @@ -2171,181 +1574,922 @@ func (ec *executionContext) _Node(ctx context.Context, sel ast.SelectionSet, obj } } -func UnmarshalTodoInput(v interface{}) (TodoInput, error) { - var it TodoInput - var asMap = v.(map[string]interface{}) +// endregion ************************** interface.gotpl *************************** - for k, v := range asMap { - switch k { - case "text": - var err error - it.Text, err = graphql.UnmarshalString(v) - if err != nil { - return it, err +// region **************************** object.gotpl **************************** + +var myMutationImplementors = []string{"MyMutation"} + +func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, myMutationImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyMutation", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("MyMutation") + case "createTodo": + out.Values[i] = ec._MyMutation_createTodo(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true } + default: + panic("unknown field " + strconv.Quote(field.Name)) } } - - return it, nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - rctx := graphql.GetResolverContext(ctx) - for _, d := range rctx.Field.Definition.Directives { - switch d.Name { - case "enumLogging": - if ec.directives.EnumLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.EnumLogging(ctx, obj, n) - } - } - case "fieldLogging": - if ec.directives.FieldLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.FieldLogging(ctx, obj, n) - } - } - case "inputLogging": - if ec.directives.InputLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.InputLogging(ctx, obj, n) - } - } - case "interfaceLogging": - if ec.directives.InterfaceLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.InterfaceLogging(ctx, obj, n) +var myQueryImplementors = []string{"MyQuery"} + +func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, myQueryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "MyQuery", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("MyQuery") + case "todos": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MyQuery_todos(ctx, field) + if res == graphql.Null { + invalid = true } + return res + }) + case "todo": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MyQuery_todo(ctx, field) + return res + }) + case "__type": + out.Values[i] = ec._MyQuery___type(ctx, field) + case "__schema": + out.Values[i] = ec._MyQuery___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var todoImplementors = []string{"Todo", "Node", "Data"} + +func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj *Todo) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, todoImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Todo") + case "id": + out.Values[i] = ec._Todo_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - case "objectLogging": - if ec.directives.ObjectLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.ObjectLogging(ctx, obj, n) - } + case "text": + out.Values[i] = ec._Todo_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - case "scalarLogging": - if ec.directives.ScalarLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.ScalarLogging(ctx, obj, n) - } + case "state": + out.Values[i] = ec._Todo_state(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } - case "unionLogging": - if ec.directives.UnionLogging != nil { - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.UnionLogging(ctx, obj, n) - } + case "verified": + out.Values[i] = ec._Todo_verified(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true } + default: + panic("unknown field " + strconv.Quote(field.Name)) } } - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil + out.Dispatch() + if invalid { + return graphql.Null } - return res + return out } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") - } - return introspection.WrapSchema(parsedSchema), nil -} +var __DirectiveImplementors = []string{"__Directive"} -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schemas/enum-extension.graphql", Input: `directive @enumLogging on ENUM +var __EnumValueImplementors = []string{"__EnumValue"} -extend enum State @enumLogging -`}, - &ast.Source{Name: "schemas/input-object-extension.graphql", Input: `directive @inputLogging on INPUT_OBJECT +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) -extend input TodoInput @inputLogging -`}, - &ast.Source{Name: "schemas/interface-extension.graphql", Input: `directive @interfaceLogging on INTERFACE + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} -extend interface Node @interfaceLogging -`}, - &ast.Source{Name: "schemas/object-extension.graphql", Input: `directive @objectLogging on OBJECT +var __FieldImplementors = []string{"__Field"} -extend type Todo @objectLogging -`}, - &ast.Source{Name: "schemas/scalar-extension.graphql", Input: `directive @scalarLogging on SCALAR +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) -extend scalar ID @scalarLogging -`}, - &ast.Source{Name: "schemas/schema-extension.graphql", Input: `extend schema { - mutation: MyMutation + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -extend type MyQuery { - todo(id: ID!): Todo +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -type MyMutation { - createTodo(todo: TodoInput!): Todo! +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -input TodoInput { - text: String! +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -`}, - &ast.Source{Name: "schemas/schema.graphql", Input: `# GraphQL schema example -# -# https://gqlgen.com/getting-started/ -schema { - query: MyQuery +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) } -interface Node { - id: ID! +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) } -type Todo implements Node { - id: ID! - text: String! - state: State! +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalID(v) } -type MyQuery { - todos: [Todo!]! +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalID(v) } -union Data = Todo +func (ec *executionContext) unmarshalNState2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐState(ctx context.Context, v interface{}) (State, error) { + var res State + return res, res.UnmarshalGQL(v) +} -enum State { - NOT_YET - DONE +func (ec *executionContext) marshalNState2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐState(ctx context.Context, sel ast.SelectionSet, v State) graphql.Marshaler { + return v } -`}, - &ast.Source{Name: "schemas/type-extension.graphql", Input: `directive @fieldLogging on FIELD_DEFINITION -extend type Todo { - verified: Boolean! @fieldLogging +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) } -`}, - &ast.Source{Name: "schemas/union-extension.graphql", Input: `directive @unionLogging on UNION -extend union Data @unionLogging -`}, -) +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx context.Context, sel ast.SelectionSet, v Todo) graphql.Marshaler { + return ec._Todo(ctx, sel, &v) +} + +func (ec *executionContext) marshalNTodo2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx context.Context, sel ast.SelectionSet, v []Todo) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx context.Context, sel ast.SelectionSet, v *Todo) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Todo(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNTodoInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodoInput(ctx context.Context, v interface{}) (TodoInput, error) { + return ec.unmarshalInputTodoInput(ctx, v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalOTodo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx context.Context, sel ast.SelectionSet, v Todo) graphql.Marshaler { + return ec._Todo(ctx, sel, &v) +} + +func (ec *executionContext) marshalOTodo2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋtypeᚑsystemᚑextensionᚐTodo(ctx context.Context, sel ast.SelectionSet, v *Todo) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Todo(ctx, sel, v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/example/type-system-extension/models_gen.go b/example/type-system-extension/models_gen.go index f11cbc58ee..ece1b800b2 100644 --- a/example/type-system-extension/models_gen.go +++ b/example/type-system-extension/models_gen.go @@ -37,6 +37,11 @@ const ( StateDone State = "DONE" ) +var AllState = []State{ + StateNotYet, + StateDone, +} + func (e State) IsValid() bool { switch e { case StateNotYet, StateDone: diff --git a/example/type-system-extension/resolver.go b/example/type-system-extension/resolver.go index 73215cb8b2..5158534b83 100644 --- a/example/type-system-extension/resolver.go +++ b/example/type-system-extension/resolver.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../../testdata/gqlgen.go package type_system_extension @@ -65,7 +65,7 @@ func (r *queryResolver) Todo(ctx context.Context, id string) (*Todo, error) { type mutationResolver struct{ *resolver } -func (r *mutationResolver) CreateTodo(ctx context.Context, todoInput TodoInput) (Todo, error) { +func (r *mutationResolver) CreateTodo(ctx context.Context, todoInput TodoInput) (*Todo, error) { newID := fmt.Sprintf("Todo:%d", len(r.todos)+1) newTodo := &Todo{ ID: newID, @@ -74,5 +74,5 @@ func (r *mutationResolver) CreateTodo(ctx context.Context, todoInput TodoInput) } r.todos = append(r.todos, newTodo) - return *newTodo, nil + return newTodo, nil } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000..f1b37d7d00 --- /dev/null +++ b/go.mod @@ -0,0 +1,29 @@ +module github.com/99designs/gqlgen + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-chi/chi v3.3.2+incompatible + github.com/gogo/protobuf v1.0.0 // indirect + github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect + github.com/gorilla/mux v1.6.1 // indirect + github.com/gorilla/websocket v1.2.0 + github.com/hashicorp/golang-lru v0.5.0 + github.com/kr/pretty v0.1.0 // indirect + github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047 + github.com/opentracing/basictracer-go v1.0.0 // indirect + github.com/opentracing/opentracing-go v1.0.2 + github.com/pkg/errors v0.8.1 + github.com/rs/cors v1.6.0 + github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 // indirect + github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0 // indirect + github.com/stretchr/testify v1.3.0 + github.com/urfave/cli v1.20.0 + github.com/vektah/dataloaden v0.2.0 + github.com/vektah/gqlparser v1.1.2 + golang.org/x/net v0.0.0-20180404174746-b3c676e531a6 // indirect + golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + gopkg.in/yaml.v2 v2.2.2 + sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755 + sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000..90b3684dc6 --- /dev/null +++ b/go.sum @@ -0,0 +1,68 @@ +github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ= +github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-chi/chi v3.3.2+incompatible h1:uQNcQN3NsV1j4ANsPh42P4ew4t6rnRbJb8frvpp31qQ= +github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= +github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM= +github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f h1:9oNbS1z4rVpbnkHBdPZU4jo9bSmrLpII768arSyMFgk= +github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.1 h1:KOwqsTYZdeuMacU7CxjMNYEKeBvLbxW+psodrbcEa3A= +github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ= +github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047 h1:zCoDWFD5nrJJVjbXiDZcVhOBSzKn3o9LgRLLMRNuru8= +github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo= +github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= +github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= +github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 h1:SWV2fHctRpRrp49VXJ6UZja7gU9QLHwRpIPBN89SKEo= +github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0 h1:JJV9CsgM9EC9w2iVkwuz+sMx8yRFe89PJRUrv6hPCIA= +github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/vektah/dataloaden v0.2.0 h1:lhynDrG7c8mNLahboCo0Wq82tMjmu5yOUv2ds/tBmss= +github.com/vektah/dataloaden v0.2.0/go.mod h1:vxM6NuRlgiR0M6wbVTJeKp9vQIs81ZMfCYO+4yq/jbE= +github.com/vektah/gqlparser v1.1.2 h1:ZsyLGn7/7jDNI+y4SEhI4yAxRChlv15pUHMjijT+e68= +github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= +golang.org/x/net v0.0.0-20180404174746-b3c676e531a6 h1:mge3qS/eMvcfyIAzTMOAy0XUzWG6Lk0N4M8zjuSmdco= +golang.org/x/net v0.0.0-20180404174746-b3c676e531a6/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6 h1:iZgcI2DDp6zW5v9Z/5+f0NuqoxNdmzg4hivjk2WLXpY= +golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755 h1:d2maSb13hr/ArmfK3rW+wNUKKfytCol7W1/vDHxMPiE= +sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= +sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 h1:e1sMhtVq9AfcEy8AXNb8eSg6gbzfdpYhoNqnPJa+GzI= +sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k= diff --git a/graphql/bool.go b/graphql/bool.go index 7053bbcaa3..b175ca9862 100644 --- a/graphql/bool.go +++ b/graphql/bool.go @@ -19,7 +19,7 @@ func MarshalBoolean(b bool) Marshaler { func UnmarshalBoolean(v interface{}) (bool, error) { switch v := v.(type) { case string: - return "true" == strings.ToLower(v), nil + return strings.ToLower(v) == "true", nil case int: return v != 0, nil case bool: diff --git a/graphql/context.go b/graphql/context.go index f83fa36f4e..58d3c741e1 100644 --- a/graphql/context.go +++ b/graphql/context.go @@ -12,6 +12,7 @@ import ( type Resolver func(ctx context.Context) (res interface{}, err error) type FieldMiddleware func(ctx context.Context, next Resolver) (res interface{}, err error) type RequestMiddleware func(ctx context.Context, next func(ctx context.Context) []byte) []byte +type ComplexityLimitFunc func(ctx context.Context) int type RequestContext struct { RawQuery string @@ -71,12 +72,10 @@ const ( ) func GetRequestContext(ctx context.Context) *RequestContext { - val := ctx.Value(request) - if val == nil { - return nil + if val, ok := ctx.Value(request).(*RequestContext); ok { + return val } - - return val.(*RequestContext) + return nil } func WithRequestContext(ctx context.Context, rc *RequestContext) context.Context { @@ -95,6 +94,8 @@ type ResolverContext struct { Index *int // The result object of resolver Result interface{} + // IsMethod indicates if the resolver is a method + IsMethod bool } func (r *ResolverContext) Path() []interface{} { @@ -117,8 +118,10 @@ func (r *ResolverContext) Path() []interface{} { } func GetResolverContext(ctx context.Context) *ResolverContext { - val, _ := ctx.Value(resolver).(*ResolverContext) - return val + if val, ok := ctx.Value(resolver).(*ResolverContext); ok { + return val + } + return nil } func WithResolverContext(ctx context.Context, rc *ResolverContext) context.Context { @@ -132,6 +135,24 @@ func CollectFieldsCtx(ctx context.Context, satisfies []string) []CollectedField return CollectFields(ctx, resctx.Field.Selections, satisfies) } +// CollectAllFields returns a slice of all GraphQL field names that were selected for the current resolver context. +// The slice will contain the unique set of all field names requested regardless of fragment type conditions. +func CollectAllFields(ctx context.Context) []string { + resctx := GetResolverContext(ctx) + collected := CollectFields(ctx, resctx.Field.Selections, nil) + uniq := make([]string, 0, len(collected)) +Next: + for _, f := range collected { + for _, name := range uniq { + if name == f.Name { + continue Next + } + } + uniq = append(uniq, f.Name) + } + return uniq +} + // Errorf sends an error string to the client, passing it through the formatter. func (c *RequestContext) Errorf(ctx context.Context, format string, args ...interface{}) { c.errorsMu.Lock() @@ -217,3 +238,37 @@ func (c *RequestContext) RegisterExtension(key string, value interface{}) error c.Extensions[key] = value return nil } + +// ChainFieldMiddleware add chain by FieldMiddleware +func ChainFieldMiddleware(handleFunc ...FieldMiddleware) FieldMiddleware { + n := len(handleFunc) + + if n > 1 { + lastI := n - 1 + return func(ctx context.Context, next Resolver) (interface{}, error) { + var ( + chainHandler Resolver + curI int + ) + chainHandler = func(currentCtx context.Context) (interface{}, error) { + if curI == lastI { + return next(currentCtx) + } + curI++ + res, err := handleFunc[curI](currentCtx, chainHandler) + curI-- + return res, err + + } + return handleFunc[0](ctx, chainHandler) + } + } + + if n == 1 { + return handleFunc[0] + } + + return func(ctx context.Context, next Resolver) (interface{}, error) { + return next(ctx) + } +} diff --git a/graphql/context_test.go b/graphql/context_test.go index 78683bfd31..85387e930d 100644 --- a/graphql/context_test.go +++ b/graphql/context_test.go @@ -6,7 +6,9 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/vektah/gqlparser/ast" + "github.com/vektah/gqlparser/gqlerror" ) func TestRequestContext_GetErrors(t *testing.T) { @@ -32,8 +34,21 @@ func TestRequestContext_GetErrors(t *testing.T) { Parent: root, Index: &index, } + userProvidedPath := &ResolverContext{ + Parent: child, + Field: CollectedField{ + Field: &ast.Field{ + Alias: "works", + }, + }, + } + ctx = WithResolverContext(ctx, child) c.Error(ctx, errors.New("bar")) + c.Error(ctx, &gqlerror.Error{ + Message: "foo3", + Path: append(child.Path(), "works"), + }) specs := []struct { Name string @@ -50,6 +65,11 @@ func TestRequestContext_GetErrors(t *testing.T) { RCtx: child, Messages: []string{"bar"}, }, + { + Name: "with user provided path", + RCtx: userProvidedPath, + Messages: []string{"foo3"}, + }, } for _, spec := range specs { @@ -63,3 +83,86 @@ func TestRequestContext_GetErrors(t *testing.T) { }) } } + +func TestGetRequestContext(t *testing.T) { + require.Nil(t, GetRequestContext(context.Background())) + + rc := &RequestContext{} + require.Equal(t, rc, GetRequestContext(WithRequestContext(context.Background(), rc))) +} + +func TestGetResolverContext(t *testing.T) { + require.Nil(t, GetResolverContext(context.Background())) + + rc := &ResolverContext{} + require.Equal(t, rc, GetResolverContext(WithResolverContext(context.Background(), rc))) +} + +func testContext(sel ast.SelectionSet) context.Context { + + ctx := context.Background() + + rqCtx := &RequestContext{} + ctx = WithRequestContext(ctx, rqCtx) + + root := &ResolverContext{ + Field: CollectedField{ + Selections: sel, + }, + } + ctx = WithResolverContext(ctx, root) + + return ctx +} + +func TestCollectAllFields(t *testing.T) { + t.Run("collect fields", func(t *testing.T) { + ctx := testContext(ast.SelectionSet{ + &ast.Field{ + Name: "field", + }, + }) + s := CollectAllFields(ctx) + require.Equal(t, []string{"field"}, s) + }) + + t.Run("unique field names", func(t *testing.T) { + ctx := testContext(ast.SelectionSet{ + &ast.Field{ + Name: "field", + }, + &ast.Field{ + Name: "field", + Alias: "field alias", + }, + }) + s := CollectAllFields(ctx) + require.Equal(t, []string{"field"}, s) + }) + + t.Run("collect fragments", func(t *testing.T) { + ctx := testContext(ast.SelectionSet{ + &ast.Field{ + Name: "fieldA", + }, + &ast.InlineFragment{ + TypeCondition: "ExampleTypeA", + SelectionSet: ast.SelectionSet{ + &ast.Field{ + Name: "fieldA", + }, + }, + }, + &ast.InlineFragment{ + TypeCondition: "ExampleTypeB", + SelectionSet: ast.SelectionSet{ + &ast.Field{ + Name: "fieldB", + }, + }, + }, + }) + s := CollectAllFields(ctx) + require.Equal(t, []string{"fieldA", "fieldB"}, s) + }) +} diff --git a/graphql/error.go b/graphql/error.go index 7f161a4306..af8b4ce408 100644 --- a/graphql/error.go +++ b/graphql/error.go @@ -14,7 +14,9 @@ type ExtendedError interface { func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error { if gqlerr, ok := err.(*gqlerror.Error); ok { - gqlerr.Path = GetResolverContext(ctx).Path() + if gqlerr.Path == nil { + gqlerr.Path = GetResolverContext(ctx).Path() + } return gqlerr } diff --git a/graphql/exec.go b/graphql/exec.go index 9beb314907..17c57bf67a 100644 --- a/graphql/exec.go +++ b/graphql/exec.go @@ -16,6 +16,9 @@ type ExecutableSchema interface { Subscription(ctx context.Context, op *ast.OperationDefinition) func() *Response } +// CollectFields returns the set of fields from an ast.SelectionSet where all collected fields satisfy at least one of the GraphQL types +// passed through satisfies. Providing an empty or nil slice for satisfies will return collect all fields regardless of fragment +// type conditions. func CollectFields(ctx context.Context, selSet ast.SelectionSet, satisfies []string) []CollectedField { return collectFields(GetRequestContext(ctx), selSet, satisfies, map[string]bool{}) } @@ -35,7 +38,10 @@ func collectFields(reqCtx *RequestContext, selSet ast.SelectionSet, satisfies [] f.Selections = append(f.Selections, sel.SelectionSet...) case *ast.InlineFragment: - if !shouldIncludeNode(sel.Directives, reqCtx.Variables) || !instanceOf(sel.TypeCondition, satisfies) { + if !shouldIncludeNode(sel.Directives, reqCtx.Variables) { + continue + } + if len(satisfies) > 0 && !instanceOf(sel.TypeCondition, satisfies) { continue } for _, childField := range collectFields(reqCtx, sel.SelectionSet, satisfies, visited) { @@ -59,7 +65,7 @@ func collectFields(reqCtx *RequestContext, selSet ast.SelectionSet, satisfies [] panic(fmt.Errorf("missing fragment %s", fragmentName)) } - if !instanceOf(fragment.TypeCondition, satisfies) { + if len(satisfies) > 0 && !instanceOf(fragment.TypeCondition, satisfies) { continue } diff --git a/graphql/fieldset.go b/graphql/fieldset.go new file mode 100644 index 0000000000..351e266fdb --- /dev/null +++ b/graphql/fieldset.go @@ -0,0 +1,63 @@ +package graphql + +import ( + "io" + "sync" +) + +type FieldSet struct { + fields []CollectedField + Values []Marshaler + delayed []delayedResult +} + +type delayedResult struct { + i int + f func() Marshaler +} + +func NewFieldSet(fields []CollectedField) *FieldSet { + return &FieldSet{ + fields: fields, + Values: make([]Marshaler, len(fields)), + } +} + +func (m *FieldSet) Concurrently(i int, f func() Marshaler) { + m.delayed = append(m.delayed, delayedResult{i: i, f: f}) +} + +func (m *FieldSet) Dispatch() { + if len(m.delayed) == 1 { + // only one concurrent task, no need to spawn a goroutine or deal create waitgroups + d := m.delayed[0] + m.Values[d.i] = d.f() + } else if len(m.delayed) > 1 { + // more than one concurrent task, use the main goroutine to do one, only spawn goroutines for the others + + var wg sync.WaitGroup + for _, d := range m.delayed[1:] { + wg.Add(1) + go func(d delayedResult) { + m.Values[d.i] = d.f() + wg.Done() + }(d) + } + + m.Values[m.delayed[0].i] = m.delayed[0].f() + wg.Wait() + } +} + +func (m *FieldSet) MarshalGQL(writer io.Writer) { + writer.Write(openBrace) + for i, field := range m.fields { + if i != 0 { + writer.Write(comma) + } + writeQuotedString(writer, field.Alias) + writer.Write(colon) + m.Values[i].MarshalGQL(writer) + } + writer.Write(closeBrace) +} diff --git a/graphql/id.go b/graphql/id.go index a5a7960f34..4f532037d0 100644 --- a/graphql/id.go +++ b/graphql/id.go @@ -34,3 +34,24 @@ func UnmarshalID(v interface{}) (string, error) { return "", fmt.Errorf("%T is not a string", v) } } + +func MarshalIntID(i int) Marshaler { + return WriterFunc(func(w io.Writer) { + writeQuotedString(w, strconv.Itoa(i)) + }) +} + +func UnmarshalIntID(v interface{}) (int, error) { + switch v := v.(type) { + case string: + return strconv.Atoi(v) + case int: + return v, nil + case int64: + return int(v), nil + case json.Number: + return strconv.Atoi(string(v)) + default: + return 0, fmt.Errorf("%T is not an int", v) + } +} diff --git a/graphql/int.go b/graphql/int.go index ff87574cab..57d0d589ba 100644 --- a/graphql/int.go +++ b/graphql/int.go @@ -27,3 +27,53 @@ func UnmarshalInt(v interface{}) (int, error) { return 0, fmt.Errorf("%T is not an int", v) } } + +func MarshalInt64(i int64) Marshaler { + return WriterFunc(func(w io.Writer) { + io.WriteString(w, strconv.FormatInt(i, 10)) + }) +} + +func UnmarshalInt64(v interface{}) (int64, error) { + switch v := v.(type) { + case string: + return strconv.ParseInt(v, 10, 64) + case int: + return int64(v), nil + case int64: + return v, nil + case json.Number: + return strconv.ParseInt(string(v), 10, 64) + default: + return 0, fmt.Errorf("%T is not an int", v) + } +} + +func MarshalInt32(i int32) Marshaler { + return WriterFunc(func(w io.Writer) { + io.WriteString(w, strconv.FormatInt(int64(i), 10)) + }) +} + +func UnmarshalInt32(v interface{}) (int32, error) { + switch v := v.(type) { + case string: + iv, err := strconv.ParseInt(v, 10, 32) + if err != nil { + return 0, err + } + return int32(iv), nil + case int: + return int32(v), nil + case int64: + return int32(v), nil + case json.Number: + iv, err := strconv.ParseInt(string(v), 10, 32) + if err != nil { + return 0, err + } + return int32(iv), nil + default: + return 0, fmt.Errorf("%T is not an int", v) + } +} diff --git a/graphql/int_test.go b/graphql/int_test.go new file mode 100644 index 0000000000..ada9ca5d8b --- /dev/null +++ b/graphql/int_test.go @@ -0,0 +1,71 @@ +package graphql + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestInt(t *testing.T) { + t.Run("marshal", func(t *testing.T) { + assert.Equal(t, "123", m2s(MarshalInt(123))) + }) + + t.Run("unmarshal", func(t *testing.T) { + assert.Equal(t, 123, mustUnmarshalInt(123)) + assert.Equal(t, 123, mustUnmarshalInt(int64(123))) + assert.Equal(t, 123, mustUnmarshalInt(json.Number("123"))) + assert.Equal(t, 123, mustUnmarshalInt("123")) + }) +} + +func mustUnmarshalInt(v interface{}) int { + res, err := UnmarshalInt(v) + if err != nil { + panic(err) + } + return res +} + +func TestInt32(t *testing.T) { + t.Run("marshal", func(t *testing.T) { + assert.Equal(t, "123", m2s(MarshalInt32(123))) + }) + + t.Run("unmarshal", func(t *testing.T) { + assert.Equal(t, int32(123), mustUnmarshalInt32(123)) + assert.Equal(t, int32(123), mustUnmarshalInt32(int64(123))) + assert.Equal(t, int32(123), mustUnmarshalInt32(json.Number("123"))) + assert.Equal(t, int32(123), mustUnmarshalInt32("123")) + }) +} + +func mustUnmarshalInt32(v interface{}) int32 { + res, err := UnmarshalInt32(v) + if err != nil { + panic(err) + } + return res +} + +func TestInt64(t *testing.T) { + t.Run("marshal", func(t *testing.T) { + assert.Equal(t, "123", m2s(MarshalInt32(123))) + }) + + t.Run("unmarshal", func(t *testing.T) { + assert.Equal(t, int64(123), mustUnmarshalInt64(123)) + assert.Equal(t, int64(123), mustUnmarshalInt64(int64(123))) + assert.Equal(t, int64(123), mustUnmarshalInt64(json.Number("123"))) + assert.Equal(t, int64(123), mustUnmarshalInt64("123")) + }) +} + +func mustUnmarshalInt64(v interface{}) int64 { + res, err := UnmarshalInt64(v) + if err != nil { + panic(err) + } + return res +} diff --git a/graphql/introspection/type.go b/graphql/introspection/type.go index b963aa0e27..f1228edf62 100644 --- a/graphql/introspection/type.go +++ b/graphql/introspection/type.go @@ -62,9 +62,9 @@ func (t *Type) Description() string { func (t *Type) Fields(includeDeprecated bool) []Field { if t.def == nil || (t.def.Kind != ast.Object && t.def.Kind != ast.Interface) { - return nil + return []Field{} } - var fields []Field + fields := []Field{} for _, f := range t.def.Fields { if strings.HasPrefix(f.Name, "__") { continue @@ -93,10 +93,10 @@ func (t *Type) Fields(includeDeprecated bool) []Field { func (t *Type) InputFields() []InputValue { if t.def == nil || t.def.Kind != ast.InputObject { - return nil + return []InputValue{} } - var res []InputValue + res := []InputValue{} for _, f := range t.def.Fields { res = append(res, InputValue{ Name: f.Name, @@ -118,10 +118,10 @@ func defaultValue(value *ast.Value) *string { func (t *Type) Interfaces() []Type { if t.def == nil || t.def.Kind != ast.Object { - return nil + return []Type{} } - var res []Type + res := []Type{} for _, intf := range t.def.Interfaces { res = append(res, *WrapTypeFromDef(t.schema, t.schema.Types[intf])) } @@ -131,10 +131,10 @@ func (t *Type) Interfaces() []Type { func (t *Type) PossibleTypes() []Type { if t.def == nil || (t.def.Kind != ast.Interface && t.def.Kind != ast.Union) { - return nil + return []Type{} } - var res []Type + res := []Type{} for _, pt := range t.schema.GetPossibleTypes(t.def) { res = append(res, *WrapTypeFromDef(t.schema, pt)) } @@ -143,10 +143,10 @@ func (t *Type) PossibleTypes() []Type { func (t *Type) EnumValues(includeDeprecated bool) []EnumValue { if t.def == nil || t.def.Kind != ast.Enum { - return nil + return []EnumValue{} } - var res []EnumValue + res := []EnumValue{} for _, val := range t.def.EnumValues { res = append(res, EnumValue{ Name: val.Name, diff --git a/graphql/jsonw.go b/graphql/jsonw.go index c112444a7e..db95d8e441 100644 --- a/graphql/jsonw.go +++ b/graphql/jsonw.go @@ -2,7 +2,6 @@ package graphql import ( "io" - "strconv" ) var nullLit = []byte(`null`) @@ -27,42 +26,12 @@ type Unmarshaler interface { UnmarshalGQL(v interface{}) error } -type OrderedMap struct { - Keys []string - Values []Marshaler -} - type WriterFunc func(writer io.Writer) func (f WriterFunc) MarshalGQL(w io.Writer) { f(w) } -func NewOrderedMap(len int) *OrderedMap { - return &OrderedMap{ - Keys: make([]string, len), - Values: make([]Marshaler, len), - } -} - -func (m *OrderedMap) Add(key string, value Marshaler) { - m.Keys = append(m.Keys, key) - m.Values = append(m.Values, value) -} - -func (m *OrderedMap) MarshalGQL(writer io.Writer) { - writer.Write(openBrace) - for i, key := range m.Keys { - if i != 0 { - writer.Write(comma) - } - io.WriteString(writer, strconv.Quote(key)) - writer.Write(colon) - m.Values[i].MarshalGQL(writer) - } - writer.Write(closeBrace) -} - type Array []Marshaler func (a Array) MarshalGQL(writer io.Writer) { diff --git a/graphql/jsonw_test.go b/graphql/jsonw_test.go index 00f01cf57b..856f1b9cdd 100644 --- a/graphql/jsonw_test.go +++ b/graphql/jsonw_test.go @@ -5,13 +5,19 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/vektah/gqlparser/ast" ) func TestJsonWriter(t *testing.T) { - obj := &OrderedMap{} - obj.Add("test", MarshalInt(10)) + obj := NewFieldSet([]CollectedField{ + {Field: &ast.Field{Alias: "test"}}, + {Field: &ast.Field{Alias: "array"}}, + {Field: &ast.Field{Alias: "emptyArray"}}, + {Field: &ast.Field{Alias: "child"}}, + }) + obj.Values[0] = MarshalInt(10) - obj.Add("array", &Array{ + obj.Values[1] = &Array{ MarshalInt(1), MarshalString("2"), MarshalBoolean(true), @@ -19,17 +25,21 @@ func TestJsonWriter(t *testing.T) { Null, MarshalFloat(1.3), True, - }) + } - obj.Add("emptyArray", &Array{}) + obj.Values[2] = &Array{} - child2 := &OrderedMap{} - child2.Add("child", Null) + child2 := NewFieldSet([]CollectedField{ + {Field: &ast.Field{Alias: "child"}}, + }) + child2.Values[0] = Null - child1 := &OrderedMap{} - child1.Add("child", child2) + child1 := NewFieldSet([]CollectedField{ + {Field: &ast.Field{Alias: "child"}}, + }) + child1.Values[0] = child2 - obj.Add("child", child1) + obj.Values[3] = child1 b := &bytes.Buffer{} obj.MarshalGQL(b) diff --git a/graphql/root.go b/graphql/root.go new file mode 100644 index 0000000000..3405d18054 --- /dev/null +++ b/graphql/root.go @@ -0,0 +1,7 @@ +package graphql + +type Query struct{} + +type Mutation struct{} + +type Subscription struct{} diff --git a/graphql/string.go b/graphql/string.go index d5fb32947d..7c1b7d9577 100644 --- a/graphql/string.go +++ b/graphql/string.go @@ -10,37 +10,42 @@ const encodeHex = "0123456789ABCDEF" func MarshalString(s string) Marshaler { return WriterFunc(func(w io.Writer) { - start := 0 - io.WriteString(w, `"`) - - for i, c := range s { - if c < 0x20 || c == '\\' || c == '"' { - io.WriteString(w, s[start:i]) - - switch c { - case '\t': - io.WriteString(w, `\t`) - case '\r': - io.WriteString(w, `\r`) - case '\n': - io.WriteString(w, `\n`) - case '\\': - io.WriteString(w, `\\`) - case '"': - io.WriteString(w, `\"`) - default: - io.WriteString(w, `\u00`) - w.Write([]byte{encodeHex[c>>4], encodeHex[c&0xf]}) - } - - start = i + 1 + writeQuotedString(w, s) + }) +} + +func writeQuotedString(w io.Writer, s string) { + start := 0 + io.WriteString(w, `"`) + + for i, c := range s { + if c < 0x20 || c == '\\' || c == '"' { + io.WriteString(w, s[start:i]) + + switch c { + case '\t': + io.WriteString(w, `\t`) + case '\r': + io.WriteString(w, `\r`) + case '\n': + io.WriteString(w, `\n`) + case '\\': + io.WriteString(w, `\\`) + case '"': + io.WriteString(w, `\"`) + default: + io.WriteString(w, `\u00`) + w.Write([]byte{encodeHex[c>>4], encodeHex[c&0xf]}) } + + start = i + 1 } + } - io.WriteString(w, s[start:]) - io.WriteString(w, `"`) - }) + io.WriteString(w, s[start:]) + io.WriteString(w, `"`) } + func UnmarshalString(v interface{}) (string, error) { switch v := v.(type) { case string: diff --git a/handler/graphql.go b/handler/graphql.go index 8a36db3ad3..09a0dbc117 100644 --- a/handler/graphql.go +++ b/handler/graphql.go @@ -39,6 +39,7 @@ type Config struct { requestHook graphql.RequestMiddleware tracer graphql.Tracer complexityLimit int + complexityLimitFunc graphql.ComplexityLimitFunc disableIntrospection bool connectionKeepAlivePingInterval time.Duration } @@ -65,11 +66,9 @@ func (c *Config) newRequestContext(es graphql.ExecutableSchema, doc *ast.QueryDo if hook := c.tracer; hook != nil { reqCtx.Tracer = hook - } else { - reqCtx.Tracer = &graphql.NopTracer{} } - if c.complexityLimit > 0 { + if c.complexityLimit > 0 || c.complexityLimitFunc != nil { reqCtx.ComplexityLimit = c.complexityLimit operationComplexity := complexity.Calculate(es, op, variables) reqCtx.OperationComplexity = operationComplexity @@ -117,6 +116,15 @@ func ComplexityLimit(limit int) Option { } } +// ComplexityLimitFunc allows you to define a function to dynamically set the maximum query complexity that is allowed +// to be executed. +// If a query is submitted that exceeds the limit, a 422 status code will be returned. +func ComplexityLimitFunc(complexityLimitFunc graphql.ComplexityLimitFunc) Option { + return func(cfg *Config) { + cfg.complexityLimitFunc = complexityLimitFunc + } +} + // ResolverMiddleware allows you to define a function that will be called around every resolver, // useful for logging. func ResolverMiddleware(middleware graphql.FieldMiddleware) Option { @@ -248,19 +256,23 @@ func CacheSize(size int) Option { } } -const DefaultCacheSize = 1000 - -// WebsocketKeepAliveDuration allows you to reconfigure the keepAlive behavior. -// By default, keep-alive is disabled. +// WebsocketKeepAliveDuration allows you to reconfigure the keepalive behavior. +// By default, keepalive is enabled with a DefaultConnectionKeepAlivePingInterval +// duration. Set handler.connectionKeepAlivePingInterval = 0 to disable keepalive +// altogether. func WebsocketKeepAliveDuration(duration time.Duration) Option { return func(cfg *Config) { cfg.connectionKeepAlivePingInterval = duration } } +const DefaultCacheSize = 1000 +const DefaultConnectionKeepAlivePingInterval = 25 * time.Second + func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc { cfg := &Config{ - cacheSize: DefaultCacheSize, + cacheSize: DefaultCacheSize, + connectionKeepAlivePingInterval: DefaultConnectionKeepAlivePingInterval, upgrader: websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, @@ -274,7 +286,7 @@ func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc var cache *lru.Cache if cfg.cacheSize > 0 { var err error - cache, err = lru.New(DefaultCacheSize) + cache, err = lru.New(cfg.cacheSize) if err != nil { // An error is only returned for non-positive cache size // and we already checked for that. @@ -310,10 +322,11 @@ func (gh *graphqlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if strings.Contains(r.Header.Get("Upgrade"), "websocket") { - connectWs(gh.exec, w, r, gh.cfg) + connectWs(gh.exec, w, r, gh.cfg, gh.cache) return } + w.Header().Set("Content-Type", "application/json") var reqParams params switch r.Method { case http.MethodGet: @@ -343,7 +356,6 @@ func (gh *graphqlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusMethodNotAllowed) return } - w.Header().Set("Content-Type", "application/json") ctx := r.Context() @@ -392,6 +404,10 @@ func (gh *graphqlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } }() + if gh.cfg.complexityLimitFunc != nil { + reqCtx.ComplexityLimit = gh.cfg.complexityLimitFunc(ctx) + } + if reqCtx.ComplexityLimit > 0 && reqCtx.OperationComplexity > reqCtx.ComplexityLimit { sendErrorf(w, http.StatusUnprocessableEntity, "operation has complexity %d, which exceeds the limit of %d", reqCtx.OperationComplexity, reqCtx.ComplexityLimit) return diff --git a/handler/graphql_test.go b/handler/graphql_test.go index 8dff6c182e..f938640716 100644 --- a/handler/graphql_test.go +++ b/handler/graphql_test.go @@ -1,11 +1,14 @@ package handler import ( + "context" "net/http" "net/http/httptest" "strings" "testing" + "github.com/99designs/gqlgen/graphql" + "github.com/stretchr/testify/assert" ) @@ -45,30 +48,35 @@ func TestHandlerPOST(t *testing.T) { t.Run("decode failure", func(t *testing.T) { resp := doRequest(h, "POST", "/graphql", "notjson") assert.Equal(t, http.StatusBadRequest, resp.Code) + assert.Equal(t, resp.Header().Get("Content-Type"), "application/json") assert.Equal(t, `{"errors":[{"message":"json body could not be decoded: invalid character 'o' in literal null (expecting 'u')"}],"data":null}`, resp.Body.String()) }) t.Run("parse failure", func(t *testing.T) { resp := doRequest(h, "POST", "/graphql", `{"query": "!"}`) assert.Equal(t, http.StatusUnprocessableEntity, resp.Code) + assert.Equal(t, resp.Header().Get("Content-Type"), "application/json") assert.Equal(t, `{"errors":[{"message":"Unexpected !","locations":[{"line":1,"column":1}]}],"data":null}`, resp.Body.String()) }) t.Run("validation failure", func(t *testing.T) { resp := doRequest(h, "POST", "/graphql", `{"query": "{ me { title }}"}`) assert.Equal(t, http.StatusUnprocessableEntity, resp.Code) + assert.Equal(t, resp.Header().Get("Content-Type"), "application/json") assert.Equal(t, `{"errors":[{"message":"Cannot query field \"title\" on type \"User\".","locations":[{"line":1,"column":8}]}],"data":null}`, resp.Body.String()) }) t.Run("invalid variable", func(t *testing.T) { resp := doRequest(h, "POST", "/graphql", `{"query": "query($id:Int!){user(id:$id){name}}","variables":{"id":false}}`) assert.Equal(t, http.StatusUnprocessableEntity, resp.Code) + assert.Equal(t, resp.Header().Get("Content-Type"), "application/json") assert.Equal(t, `{"errors":[{"message":"cannot use bool as Int","path":["variable","id"]}],"data":null}`, resp.Body.String()) }) t.Run("execution failure", func(t *testing.T) { resp := doRequest(h, "POST", "/graphql", `{"query": "mutation { me { name } }"}`) assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, resp.Header().Get("Content-Type"), "application/json") assert.Equal(t, `{"errors":[{"message":"mutations are not supported"}],"data":null}`, resp.Body.String()) }) } @@ -112,7 +120,7 @@ func TestHandlerOptions(t *testing.T) { resp := doRequest(h, "OPTIONS", "/graphql?query={me{name}}", ``) assert.Equal(t, http.StatusOK, resp.Code) - assert.Equal(t, "OPTIONS, GET, POST", resp.HeaderMap.Get("Allow")) + assert.Equal(t, "OPTIONS, GET, POST", resp.Header().Get("Allow")) } func TestHandlerHead(t *testing.T) { @@ -122,6 +130,52 @@ func TestHandlerHead(t *testing.T) { assert.Equal(t, http.StatusMethodNotAllowed, resp.Code) } +func TestHandlerComplexity(t *testing.T) { + t.Run("static complexity", func(t *testing.T) { + h := GraphQL(&executableSchemaStub{}, ComplexityLimit(2)) + + t.Run("below complexity limit", func(t *testing.T) { + resp := doRequest(h, "POST", "/graphql", `{"query":"{ me { name } }"}`) + assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String()) + }) + + t.Run("above complexity limit", func(t *testing.T) { + resp := doRequest(h, "POST", "/graphql", `{"query":"{ a: me { name } b: me { name } }"}`) + assert.Equal(t, http.StatusUnprocessableEntity, resp.Code) + assert.Equal(t, `{"errors":[{"message":"operation has complexity 4, which exceeds the limit of 2"}],"data":null}`, resp.Body.String()) + }) + }) + + t.Run("dynamic complexity", func(t *testing.T) { + h := GraphQL(&executableSchemaStub{}, ComplexityLimitFunc(func(ctx context.Context) int { + reqCtx := graphql.GetRequestContext(ctx) + if strings.Contains(reqCtx.RawQuery, "dummy") { + return 4 + } + return 2 + })) + + t.Run("below complexity limit", func(t *testing.T) { + resp := doRequest(h, "POST", "/graphql", `{"query":"{ me { name } }"}`) + assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String()) + }) + + t.Run("above complexity limit", func(t *testing.T) { + resp := doRequest(h, "POST", "/graphql", `{"query":"{ a: me { name } b: me { name } }"}`) + assert.Equal(t, http.StatusUnprocessableEntity, resp.Code) + assert.Equal(t, `{"errors":[{"message":"operation has complexity 4, which exceeds the limit of 2"}],"data":null}`, resp.Body.String()) + }) + + t.Run("within dynamic complexity limit", func(t *testing.T) { + resp := doRequest(h, "POST", "/graphql", `{"query":"{ a: me { name } dummy: me { name } }"}`) + assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String()) + }) + }) +} + func doRequest(handler http.Handler, method string, target string, body string) *httptest.ResponseRecorder { r := httptest.NewRequest(method, target, strings.NewReader(body)) w := httptest.NewRecorder() diff --git a/handler/playground.go b/handler/playground.go index f1687defb7..0e1ca76863 100644 --- a/handler/playground.go +++ b/handler/playground.go @@ -11,9 +11,12 @@ var page = template.Must(template.New("graphiql").Parse(` - - - + + + {{.title}} @@ -42,10 +45,14 @@ var page = template.Must(template.New("graphiql").Parse(` func Playground(title string, endpoint string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/html") err := page.Execute(w, map[string]string{ - "title": title, - "endpoint": endpoint, - "version": "1.7.8", + "title": title, + "endpoint": endpoint, + "version": "1.7.20", + "cssSRI": "sha256-cS9Vc2OBt9eUf4sykRWukeFYaInL29+myBmFDSa7F/U=", + "faviconSRI": "sha256-GhTyE+McTU79R4+pRO6ih+4TfsTOrpPwD8ReKFzb3PM=", + "jsSRI": "sha256-4QG1Uza2GgGdlBL3RCBCGtGeZB6bDbsw8OltCMGeJsA=", }) if err != nil { panic(err) diff --git a/handler/websocket.go b/handler/websocket.go index 09800c172b..58f38e5d48 100644 --- a/handler/websocket.go +++ b/handler/websocket.go @@ -12,6 +12,7 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/gorilla/websocket" + "github.com/hashicorp/golang-lru" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" "github.com/vektah/gqlparser/gqlerror" @@ -44,12 +45,13 @@ type wsConnection struct { active map[string]context.CancelFunc mu sync.Mutex cfg *Config + cache *lru.Cache keepAliveTicker *time.Ticker initPayload InitPayload } -func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, cfg *Config) { +func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Request, cfg *Config, cache *lru.Cache) { ws, err := cfg.upgrader.Upgrade(w, r, http.Header{ "Sec-Websocket-Protocol": []string{"graphql-ws"}, }) @@ -65,6 +67,7 @@ func connectWs(exec graphql.ExecutableSchema, w http.ResponseWriter, r *http.Req conn: ws, ctx: r.Context(), cfg: cfg, + cache: cache, } if !conn.init() { @@ -176,10 +179,27 @@ func (c *wsConnection) subscribe(message *operationMessage) bool { return false } - doc, qErr := gqlparser.LoadQuery(c.exec.Schema(), reqParams.Query) - if qErr != nil { - c.sendError(message.ID, qErr...) - return true + var ( + doc *ast.QueryDocument + cacheHit bool + ) + if c.cache != nil { + val, ok := c.cache.Get(reqParams.Query) + if ok { + doc = val.(*ast.QueryDocument) + cacheHit = true + } + } + if !cacheHit { + var qErr gqlerror.List + doc, qErr = gqlparser.LoadQuery(c.exec.Schema(), reqParams.Query) + if qErr != nil { + c.sendError(message.ID, qErr...) + return true + } + if c.cache != nil { + c.cache.Add(reqParams.Query, doc) + } } op := doc.Operations.ForName(reqParams.OperationName) diff --git a/integration/generated.go b/integration/generated.go index 008cf1959a..6b17e93743 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -6,17 +6,19 @@ import ( "bytes" "context" "errors" - "remote_api" "strconv" "sync" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/integration/models-go" + "github.com/99designs/gqlgen/integration/remote_api" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast" ) +// region ************************** generated!.gotpl ************************** + // NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { return &executableSchema{ @@ -50,16 +52,16 @@ type ComplexityRoot struct { } Query struct { - Path func(childComplexity int) int Date func(childComplexity int, filter models.DateFilter) int - Viewer func(childComplexity int) int - JsonEncoding func(childComplexity int) int Error func(childComplexity int, typeArg *models.ErrorType) int + JSONEncoding func(childComplexity int) int + Path func(childComplexity int) int + Viewer func(childComplexity int) int } User struct { - Name func(childComplexity int) int Likes func(childComplexity int) int + Name func(childComplexity int) int } Viewer struct { @@ -68,7 +70,7 @@ type ComplexityRoot struct { } type ElementResolver interface { - Child(ctx context.Context, obj *models.Element) (models.Element, error) + Child(ctx context.Context, obj *models.Element) (*models.Element, error) Error(ctx context.Context, obj *models.Element) (bool, error) Mismatched(ctx context.Context, obj *models.Element) ([]bool, error) } @@ -83,106 +85,6 @@ type UserResolver interface { Likes(ctx context.Context, obj *remote_api.User) ([]string, error) } -func field_Query_date_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 models.DateFilter - if tmp, ok := rawArgs["filter"]; ok { - var err error - arg0, err = UnmarshalDateFilter(tmp) - if err != nil { - return nil, err - } - } - args["filter"] = arg0 - return args, nil - -} - -func field_Query_error_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *models.ErrorType - if tmp, ok := rawArgs["type"]; ok { - var err error - var ptr1 models.ErrorType - if tmp != nil { - err = (&ptr1).UnmarshalGQL(tmp) - arg0 = &ptr1 - } - - if err != nil { - return nil, err - } - } - args["type"] = arg0 - return args, nil - -} - -func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - return nil, err - } - } - args["name"] = arg0 - return args, nil - -} - -func field___Type_fields_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func field___Type_enumValues_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - var err error - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil - -} - -func dir_magic_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { - args := map[string]interface{}{} - var arg0 *int - if tmp, ok := rawArgs["kind"]; ok { - var err error - var ptr1 int - if tmp != nil { - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - } - - if err != nil { - return nil, err - } - } - args["kind"] = arg0 - return args, nil - -} - type executableSchema struct { resolvers ResolverRoot directives DirectiveRoot @@ -194,89 +96,91 @@ func (e *executableSchema) Schema() *ast.Schema { } func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec switch typeName + "." + field { - case "Element.child": + case "Element.Child": if e.complexity.Element.Child == nil { break } return e.complexity.Element.Child(childComplexity), true - case "Element.error": + case "Element.Error": if e.complexity.Element.Error == nil { break } return e.complexity.Element.Error(childComplexity), true - case "Element.mismatched": + case "Element.Mismatched": if e.complexity.Element.Mismatched == nil { break } return e.complexity.Element.Mismatched(childComplexity), true - case "Query.path": - if e.complexity.Query.Path == nil { - break - } - - return e.complexity.Query.Path(childComplexity), true - - case "Query.date": + case "Query.Date": if e.complexity.Query.Date == nil { break } - args, err := field_Query_date_args(rawArgs) + args, err := ec.field_Query_date_args(context.TODO(), rawArgs) if err != nil { return 0, false } return e.complexity.Query.Date(childComplexity, args["filter"].(models.DateFilter)), true - case "Query.viewer": - if e.complexity.Query.Viewer == nil { + case "Query.Error": + if e.complexity.Query.Error == nil { break } - return e.complexity.Query.Viewer(childComplexity), true - - case "Query.jsonEncoding": - if e.complexity.Query.JsonEncoding == nil { - break + args, err := ec.field_Query_error_args(context.TODO(), rawArgs) + if err != nil { + return 0, false } - return e.complexity.Query.JsonEncoding(childComplexity), true + return e.complexity.Query.Error(childComplexity, args["type"].(*models.ErrorType)), true - case "Query.error": - if e.complexity.Query.Error == nil { + case "Query.JSONEncoding": + if e.complexity.Query.JSONEncoding == nil { break } - args, err := field_Query_error_args(rawArgs) - if err != nil { - return 0, false + return e.complexity.Query.JSONEncoding(childComplexity), true + + case "Query.Path": + if e.complexity.Query.Path == nil { + break } - return e.complexity.Query.Error(childComplexity, args["type"].(*models.ErrorType)), true + return e.complexity.Query.Path(childComplexity), true - case "User.name": - if e.complexity.User.Name == nil { + case "Query.Viewer": + if e.complexity.Query.Viewer == nil { break } - return e.complexity.User.Name(childComplexity), true + return e.complexity.Query.Viewer(childComplexity), true - case "User.likes": + case "User.Likes": if e.complexity.User.Likes == nil { break } return e.complexity.User.Likes(childComplexity), true - case "Viewer.user": + case "User.Name": + if e.complexity.User.Name == nil { + break + } + + return e.complexity.User.Name(childComplexity), true + + case "Viewer.User": if e.complexity.Viewer.User == nil { break } @@ -300,7 +204,8 @@ func (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinitio return &graphql.Response{ Data: buf, Errors: ec.Errors, - Extensions: ec.Extensions} + Extensions: ec.Extensions, + } } func (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response { @@ -316,294 +221,318 @@ type executionContext struct { *executableSchema } -var elementImplementors = []string{"Element"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, obj *models.Element) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, elementImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Element") - case "child": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Element_child(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true +func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + rctx := graphql.GetResolverContext(ctx) + for _, d := range rctx.Field.Definition.Directives { + switch d.Name { + case "magic": + if ec.directives.Magic != nil { + rawArgs := d.ArgumentMap(ec.Variables) + args, err := ec.dir_magic_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return nil } - wg.Done() - }(i, field) - case "error": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Element_error(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true + n := next + next = func(ctx context.Context) (interface{}, error) { + return ec.directives.Magic(ctx, obj, n, args["kind"].(*int)) } - wg.Done() - }(i, field) - case "mismatched": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Element_mismatched(ctx, field, obj) - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) + } } } - wg.Wait() - if invalid { - return graphql.Null + res, err := ec.ResolverMiddleware(ctx, next) + if err != nil { + ec.Error(ctx, err) + return nil } - return out + return res } -// nolint: vetshadow -func (ec *executionContext) _Element_child(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Element", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Element().Child(rctx, obj) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(models.Element) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - - return ec._Element(ctx, field.Selections, &res) + return introspection.WrapSchema(parsedSchema), nil } -// nolint: vetshadow -func (ec *executionContext) _Element_error(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Element", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Element().Error(rctx, obj) - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") } - res := resTmp.(bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil } -// nolint: vetshadow -func (ec *executionContext) _Element_mismatched(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "Element", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Element().Mismatched(rctx, obj) - }) - if resTmp == nil { - return graphql.Null - } - res := resTmp.([]bool) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) +var parsedSchema = gqlparser.MustLoadSchema( + &ast.Source{Name: "schema.graphql", Input: `"This directive does magical things" +directive @magic(kind: Int) on FIELD_DEFINITION - arr1 := make(graphql.Array, len(res)) +type Element { + child: Element! + error: Boolean! + mismatched: [Boolean!] +} - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalBoolean(res[idx1]) - }() - } +enum DATE_FILTER_OP { + # multi + # line + # comment + EQ + NEQ + GT + GTE + LT + LTE +} - return arr1 +input DateFilter { + value: String! + timezone: String = "UTC" + op: DATE_FILTER_OP = EQ } -var queryImplementors = []string{"Query"} +type Viewer { + user: User +} -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, queryImplementors) +type Query { + path: [Element] + date(filter: DateFilter!): Boolean! + viewer: Viewer + jsonEncoding: String! + error(type: ErrorType = NORMAL): Boolean! +} - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Query", - }) +enum ErrorType { + CUSTOM + NORMAL +} - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias +# this is a comment with a ` + "`" + `backtick` + "`" + ` +`}, + &ast.Source{Name: "user.graphql", Input: `type User { + name: String! + likes: [String!]! +} +`}, +) - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Query") - case "path": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_path(ctx, field) - wg.Done() - }(i, field) - case "date": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_date(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "viewer": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_viewer(ctx, field) - wg.Done() - }(i, field) - case "jsonEncoding": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_jsonEncoding(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "error": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._Query_error(ctx, field) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - case "__type": - out.Values[i] = ec._Query___type(ctx, field) - case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) dir_magic_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["kind"]; ok { + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err } } - wg.Wait() - if invalid { - return graphql.Null + args["kind"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } } - return out + args["name"] = arg0 + return args, nil } -// nolint: vetshadow -func (ec *executionContext) _Query_path(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { +func (ec *executionContext) field_Query_date_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 models.DateFilter + if tmp, ok := rawArgs["filter"]; ok { + arg0, err = ec.unmarshalNDateFilter2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilter(ctx, tmp) + if err != nil { + return nil, err + } + } + args["filter"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_error_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *models.ErrorType + if tmp, ok := rawArgs["type"]; ok { + arg0, err = ec.unmarshalOErrorType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx, tmp) + if err != nil { + return nil, err + } + } + args["type"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _Element_child(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Element", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Path(rctx) + return ec.resolvers.Element().Child(rctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.([]*models.Element) + res := resTmp.(*models.Element) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNElement2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) _Element_error(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Element", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Element().Error(rctx, obj) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - if res[idx1] == nil { - return graphql.Null - } + return graphql.Null + } + res := resTmp.(bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} - return ec._Element(ctx, field.Selections, res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } +func (ec *executionContext) _Element_mismatched(ctx context.Context, field graphql.CollectedField, obj *models.Element) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Element", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Element().Mismatched(rctx, obj) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]bool) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOBoolean2ᚕbool(ctx, field.Selections, res) +} +func (ec *executionContext) _Query_path(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } - wg.Wait() - return arr1 + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Path(rctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*models.Element) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOElement2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_date(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_date_args(rawArgs) + args, err := ec.field_Query_date_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -618,17 +547,17 @@ func (ec *executionContext) _Query_date(ctx context.Context, field graphql.Colle res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_viewer(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -642,22 +571,17 @@ func (ec *executionContext) _Query_viewer(ctx context.Context, field graphql.Col res := resTmp.(*models.Viewer) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._Viewer(ctx, field.Selections, res) + return ec.marshalOViewer2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐViewer(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_jsonEncoding(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -674,25 +598,26 @@ func (ec *executionContext) _Query_jsonEncoding(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query_error(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query_error_args(rawArgs) + args, err := ec.field_Query_error_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -707,25 +632,26 @@ func (ec *executionContext) _Query_error(ctx context.Context, field graphql.Coll res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field_Query___type_args(rawArgs) + args, err := ec.field_Query___type_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "Query", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -737,22 +663,17 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Query", - Args: nil, - Field: field, + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -766,89 +687,44 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C res := resTmp.(*introspection.Schema) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} - if res == nil { +func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *remote_api.User) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "User", + Field: field, + Args: nil, + IsMethod: false, + } + ctx = graphql.WithResolverContext(ctx, rctx) + ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - - return ec.___Schema(ctx, field.Selections, res) + res := resTmp.(string) + rctx.Result = res + ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalNString2string(ctx, field.Selections, res) } -var userImplementors = []string{"User"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *remote_api.User) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, userImplementors) - - var wg sync.WaitGroup - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("User") - case "name": - out.Values[i] = ec._User_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "likes": - wg.Add(1) - go func(i int, field graphql.CollectedField) { - out.Values[i] = ec._User_likes(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - wg.Done() - }(i, field) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - wg.Wait() - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow -func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *remote_api.User) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() - rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) - ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) - resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if resTmp == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - rctx.Result = res - ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) -} - -// nolint: vetshadow func (ec *executionContext) _User_likes(ctx context.Context, field graphql.CollectedField, obj *remote_api.User) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "User", - Args: nil, - Field: field, + Object: "User", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -865,53 +741,17 @@ func (ec *executionContext) _User_likes(ctx context.Context, field graphql.Colle res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 -} - -var viewerImplementors = []string{"Viewer"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, obj *models.Viewer) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, viewerImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("Viewer") - case "user": - out.Values[i] = ec._Viewer_user(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalNString2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) _Viewer_user(ctx context.Context, field graphql.CollectedField, obj *models.Viewer) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "Viewer", - Args: nil, - Field: field, + Object: "Viewer", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -925,64 +765,17 @@ func (ec *executionContext) _Viewer_user(ctx context.Context, field graphql.Coll res := resTmp.(*remote_api.User) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec._User(ctx, field.Selections, res) -} - -var __DirectiveImplementors = []string{"__Directive"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Directive") - case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) - case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋremote_apiᚐUser(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -999,17 +792,17 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1023,17 +816,17 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1050,26 +843,17 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr res := resTmp.([]string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - - for idx1 := range res { - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - } - - return arr1 + return ec.marshalN__DirectiveLocation2ᚕstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Directive", - Args: nil, - Field: field, + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1086,89 +870,17 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __EnumValueImplementors = []string{"__EnumValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__EnumValue") - case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) - case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1185,17 +897,17 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1209,17 +921,17 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1236,17 +948,17 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__EnumValue", - Args: nil, - Field: field, + Object: "__EnumValue", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1260,70 +972,17 @@ func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __FieldImplementors = []string{"__Field"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __FieldImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Field") - case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) - case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1340,17 +999,17 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1364,17 +1023,17 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1391,50 +1050,17 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1451,25 +1077,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1486,17 +1104,17 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra res := resTmp.(bool) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalBoolean(res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Field", - Args: nil, - Field: field, + Object: "__Field", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1510,60 +1128,17 @@ func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __InputValueImplementors = []string{"__InputValue"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__InputValue") - case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) - case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out -} - -// nolint: vetshadow func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1580,17 +1155,17 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalNString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1604,17 +1179,17 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1631,25 +1206,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__InputValue", - Args: nil, - Field: field, + Object: "__InputValue", + Field: field, + Args: nil, + IsMethod: false, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1663,65 +1230,17 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) -} - -var __SchemaImplementors = []string{"__Schema"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Schema") - case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) - case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) - case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1738,50 +1257,17 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1798,25 +1284,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - if !ec.HasError(rctx) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1830,22 +1308,17 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1859,22 +1332,17 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - - return ec.___Type(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Schema", - Args: nil, - Field: field, + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1891,96 +1359,17 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap res := resTmp.([]introspection.Directive) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -var __TypeImplementors = []string{"__Type"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { - fields := graphql.CollectFields(ctx, sel, __TypeImplementors) - - out := graphql.NewOrderedMap(len(fields)) - invalid := false - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("__Type") - case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalid = true - } - case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) - case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) - case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) - case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) - case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) - case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) - case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) - case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - if invalid { - return graphql.Null - } - return out + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -1997,17 +1386,17 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2021,21 +1410,17 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll res := resTmp.(*string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - if res == nil { - return graphql.Null - } - return graphql.MarshalString(*res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2049,25 +1434,26 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph res := resTmp.(string) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return graphql.MarshalString(res) + return ec.marshalOString2string(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + } + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_fields_args(rawArgs) + args, err := ec.field___Type_fields_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2079,50 +1465,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co res := resTmp.([]introspection.Field) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Field(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2136,50 +1489,17 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2193,58 +1513,26 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra res := resTmp.([]introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + ctx = ec.Tracer.StartFieldExecution(ctx, field) + defer func() { ec.Tracer.EndFieldExecution(ctx) }() + rctx := &graphql.ResolverContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___Type(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 -} - -// nolint: vetshadow -func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { - ctx = ec.Tracer.StartFieldExecution(ctx, field) - defer func() { ec.Tracer.EndFieldExecution(ctx) }() + ctx = graphql.WithResolverContext(ctx, rctx) rawArgs := field.ArgumentMap(ec.Variables) - args, err := field___Type_enumValues_args(rawArgs) + args, err := ec.field___Type_enumValues_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null } - rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: args, - Field: field, - } - ctx = graphql.WithResolverContext(ctx, rctx) + rctx.Args = args ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children @@ -2256,50 +1544,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq res := resTmp.([]introspection.EnumValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2313,50 +1568,17 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph res := resTmp.([]introspection.InputValue) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - - arr1 := make(graphql.Array, len(res)) - var wg sync.WaitGroup - - isLen1 := len(res) == 1 - if !isLen1 { - wg.Add(len(res)) - } - - for idx1 := range res { - idx1 := idx1 - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - f := func(idx1 int) { - if !isLen1 { - defer wg.Done() - } - arr1[idx1] = func() graphql.Marshaler { - - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }() - } - if isLen1 { - f(idx1) - } else { - go f(idx1) - } - - } - wg.Wait() - return arr1 + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, field.Selections, res) } -// nolint: vetshadow func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ - Object: "__Type", - Args: nil, - Field: field, + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, } ctx = graphql.WithResolverContext(ctx, rctx) ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) @@ -2370,15 +1592,14 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co res := resTmp.(*introspection.Type) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} - if res == nil { - return graphql.Null - } +// endregion **************************** field.gotpl ***************************** - return ec.___Type(ctx, field.Selections, res) -} +// region **************************** input.gotpl ***************************** -func UnmarshalDateFilter(v interface{}) (models.DateFilter, error) { +func (ec *executionContext) unmarshalInputDateFilter(ctx context.Context, v interface{}) (models.DateFilter, error) { var it models.DateFilter var asMap = v.(map[string]interface{}) @@ -2393,29 +1614,19 @@ func UnmarshalDateFilter(v interface{}) (models.DateFilter, error) { switch k { case "value": var err error - it.Value, err = graphql.UnmarshalString(v) + it.Value, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } case "timezone": var err error - var ptr1 string - if v != nil { - ptr1, err = graphql.UnmarshalString(v) - it.Timezone = &ptr1 - } - + it.Timezone, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } case "op": var err error - var ptr1 models.DateFilterOp - if v != nil { - err = (&ptr1).UnmarshalGQL(v) - it.Op = &ptr1 - } - + it.Op, err = ec.unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx, v) if err != nil { return it, err } @@ -2425,103 +1636,1158 @@ func UnmarshalDateFilter(v interface{}) (models.DateFilter, error) { return it, nil } -func (ec *executionContext) FieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) (ret interface{}) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - rctx := graphql.GetResolverContext(ctx) - for _, d := range rctx.Field.Definition.Directives { - switch d.Name { - case "magic": - if ec.directives.Magic != nil { - rawArgs := d.ArgumentMap(ec.Variables) - args, err := dir_magic_args(rawArgs) - if err != nil { - ec.Error(ctx, err) - return nil +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var elementImplementors = []string{"Element"} + +func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, obj *models.Element) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, elementImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Element") + case "child": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Element_child(ctx, field, obj) + if res == graphql.Null { + invalid = true } - n := next - next = func(ctx context.Context) (interface{}, error) { - return ec.directives.Magic(ctx, obj, n, args["kind"].(*int)) + return res + }) + case "error": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Element_error(ctx, field, obj) + if res == graphql.Null { + invalid = true } - } + return res + }) + case "mismatched": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Element_mismatched(ctx, field, obj) + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) } } - res, err := ec.ResolverMiddleware(ctx, next) - if err != nil { - ec.Error(ctx, err) - return nil + out.Dispatch() + if invalid { + return graphql.Null } - return res + return out } -func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") - } - return introspection.WrapSchema(parsedSchema), nil -} +var queryImplementors = []string{"Query"} -func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { - if ec.DisableIntrospection { - return nil, errors.New("introspection disabled") +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, queryImplementors) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "path": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_path(ctx, field) + return res + }) + case "date": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_date(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "viewer": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_viewer(ctx, field) + return res + }) + case "jsonEncoding": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_jsonEncoding(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "error": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_error(ctx, field) + if res == graphql.Null { + invalid = true + } + return res + }) + case "__type": + out.Values[i] = ec._Query___type(ctx, field) + case "__schema": + out.Values[i] = ec._Query___schema(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } } - return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -var parsedSchema = gqlparser.MustLoadSchema( - &ast.Source{Name: "schema.graphql", Input: `"This directive does magical things" -directive @magic(kind: Int) on FIELD_DEFINITION +var userImplementors = []string{"User"} -type Element { - child: Element! - error: Boolean! - mismatched: [Boolean!] -} +func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *remote_api.User) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, userImplementors) -enum DATE_FILTER_OP { - # multi - # line - # comment - EQ - NEQ - GT - GTE - LT - LTE + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("User") + case "name": + out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "likes": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._User_likes(ctx, field, obj) + if res == graphql.Null { + invalid = true + } + return res + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -input DateFilter { - value: String! - timezone: String = "UTC" - op: DATE_FILTER_OP = EQ -} +var viewerImplementors = []string{"Viewer"} -type Viewer { - user: User -} +func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, obj *models.Viewer) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, viewerImplementors) -type Query { - path: [Element] - date(filter: DateFilter!): Boolean! - viewer: Viewer - jsonEncoding: String! - error(type: ErrorType = NORMAL): Boolean! + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Viewer") + case "user": + out.Values[i] = ec._Viewer_user(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out } -enum ErrorType { - CUSTOM - NORMAL -} +var __DirectiveImplementors = []string{"__Directive"} -# this is a comment with a ` + "`" + `backtick` + "`" + ` -`}, - &ast.Source{Name: "user.graphql", Input: `type User { - name: String! - likes: [String!]! -} -`}, -) +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Directive_description(ctx, field, obj) + case "locations": + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "args": + out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + case "isDeprecated": + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __FieldImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___Field_description(ctx, field, obj) + case "args": + out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "type": + out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "isDeprecated": + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "deprecationReason": + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "description": + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + case "type": + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "defaultValue": + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "types": + out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "queryType": + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "mutationType": + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + case "subscriptionType": + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + case "directives": + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, __TypeImplementors) + + out := graphql.NewFieldSet(fields) + invalid := false + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "name": + out.Values[i] = ec.___Type_name(ctx, field, obj) + case "description": + out.Values[i] = ec.___Type_description(ctx, field, obj) + case "fields": + out.Values[i] = ec.___Type_fields(ctx, field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalid { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalNDateFilter2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilter(ctx context.Context, v interface{}) (models.DateFilter, error) { + return ec.unmarshalInputDateFilter(ctx, v) +} + +func (ec *executionContext) marshalNElement2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx context.Context, sel ast.SelectionSet, v models.Element) graphql.Marshaler { + return ec._Element(ctx, sel, &v) +} + +func (ec *executionContext) marshalNElement2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx context.Context, sel ast.SelectionSet, v *models.Element) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Element(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalNString2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNString2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalNString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNString2string(ctx, sel, v[i]) + } + + return ret +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstring(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !ec.HasError(graphql.GetResolverContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + return graphql.UnmarshalBoolean(v) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + return graphql.MarshalBoolean(v) +} + +func (ec *executionContext) unmarshalOBoolean2ᚕbool(ctx context.Context, v interface{}) ([]bool, error) { + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]bool, len(vSlice)) + for i := range vSlice { + res[i], err = ec.unmarshalNBoolean2bool(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOBoolean2ᚕbool(ctx context.Context, sel ast.SelectionSet, v []bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNBoolean2bool(ctx, sel, v[i]) + } + + return ret +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOBoolean2bool(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOBoolean2bool(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalODATE_FILTER_OP2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, v interface{}) (models.DateFilterOp, error) { + var res models.DateFilterOp + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalODATE_FILTER_OP2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, sel ast.SelectionSet, v models.DateFilterOp) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, v interface{}) (*models.DateFilterOp, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalODATE_FILTER_OP2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, sel ast.SelectionSet, v *models.DateFilterOp) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) marshalOElement2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx context.Context, sel ast.SelectionSet, v models.Element) graphql.Marshaler { + return ec._Element(ctx, sel, &v) +} + +func (ec *executionContext) marshalOElement2ᚕᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx context.Context, sel ast.SelectionSet, v []*models.Element) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOElement2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalOElement2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐElement(ctx context.Context, sel ast.SelectionSet, v *models.Element) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Element(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOErrorType2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx context.Context, v interface{}) (models.ErrorType, error) { + var res models.ErrorType + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalOErrorType2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx context.Context, sel ast.SelectionSet, v models.ErrorType) graphql.Marshaler { + return v +} + +func (ec *executionContext) unmarshalOErrorType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx context.Context, v interface{}) (*models.ErrorType, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOErrorType2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOErrorType2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐErrorType(ctx context.Context, sel ast.SelectionSet, v *models.ErrorType) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + +func (ec *executionContext) unmarshalOInt2int(ctx context.Context, v interface{}) (int, error) { + return graphql.UnmarshalInt(v) +} + +func (ec *executionContext) marshalOInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + return graphql.MarshalInt(v) +} + +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOInt2int(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOInt2int(ctx, sel, *v) +} + +func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { + return graphql.UnmarshalString(v) +} + +func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + return graphql.MarshalString(v) +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalOString2string(ctx, v) + return &res, err +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOString2string(ctx, sel, *v) +} + +func (ec *executionContext) marshalOUser2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋremote_apiᚐUser(ctx context.Context, sel ast.SelectionSet, v remote_api.User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} + +func (ec *executionContext) marshalOUser2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋremote_apiᚐUser(ctx context.Context, sel ast.SelectionSet, v *remote_api.User) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._User(ctx, sel, v) +} + +func (ec *executionContext) marshalOViewer2githubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐViewer(ctx context.Context, sel ast.SelectionSet, v models.Viewer) graphql.Marshaler { + return ec._Viewer(ctx, sel, &v) +} + +func (ec *executionContext) marshalOViewer2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋmodelsᚑgoᚐViewer(ctx context.Context, sel ast.SelectionSet, v *models.Viewer) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Viewer(ctx, sel, v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Schema2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v introspection.Schema) graphql.Marshaler { + return ec.___Schema(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + rctx := &graphql.ResolverContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/integration/gqlgen.yml b/integration/gqlgen.yml index dcd0c0122c..e3ca845f94 100644 --- a/integration/gqlgen.yml +++ b/integration/gqlgen.yml @@ -16,7 +16,7 @@ models: Viewer: model: github.com/99designs/gqlgen/integration/models-go.Viewer User: - model: remote_api.User + model: github.com/99designs/gqlgen/integration/remote_api.User fields: likes: resolver: true diff --git a/integration/integration-test.js b/integration/integration-test.js index e7bcc4871a..43414ec17d 100644 --- a/integration/integration-test.js +++ b/integration/integration-test.js @@ -68,6 +68,6 @@ describe('Errors', () => { query: gql`{ error(type: NORMAL) }`, }); - expect(res.errors[0].message).toEqual('Normal error'); + expect(res.errors[0].message).toEqual('normal error'); }); }); diff --git a/integration/models-go/generated.go b/integration/models-go/generated.go index f3d8f92172..7d4b611e83 100644 --- a/integration/models-go/generated.go +++ b/integration/models-go/generated.go @@ -25,6 +25,15 @@ const ( DateFilterOpLte DateFilterOp = "LTE" ) +var AllDateFilterOp = []DateFilterOp{ + DateFilterOpEq, + DateFilterOpNeq, + DateFilterOpGt, + DateFilterOpGte, + DateFilterOpLt, + DateFilterOpLte, +} + func (e DateFilterOp) IsValid() bool { switch e { case DateFilterOpEq, DateFilterOpNeq, DateFilterOpGt, DateFilterOpGte, DateFilterOpLt, DateFilterOpLte: @@ -61,6 +70,11 @@ const ( ErrorTypeNormal ErrorType = "NORMAL" ) +var AllErrorType = []ErrorType{ + ErrorTypeCustom, + ErrorTypeNormal, +} + func (e ErrorType) IsValid() bool { switch e { case ErrorTypeCustom, ErrorTypeNormal: diff --git a/integration/models-go/viewer.go b/integration/models-go/viewer.go index 9b0c981127..a0201a54e3 100644 --- a/integration/models-go/viewer.go +++ b/integration/models-go/viewer.go @@ -1,6 +1,6 @@ package models -import "remote_api" +import "github.com/99designs/gqlgen/integration/remote_api" type Viewer struct { User *remote_api.User diff --git a/integration/vendor/remote_api/user.go b/integration/remote_api/user.go similarity index 100% rename from integration/vendor/remote_api/user.go rename to integration/remote_api/user.go diff --git a/integration/resolver.go b/integration/resolver.go index c0486f7b87..5e685ceb19 100644 --- a/integration/resolver.go +++ b/integration/resolver.go @@ -1,14 +1,14 @@ -//go:generate gorunpkg github.com/99designs/gqlgen +//go:generate go run ../testdata/gqlgen.go package integration import ( "context" "fmt" - "remote_api" "time" - "github.com/99designs/gqlgen/integration/models-go" + models "github.com/99designs/gqlgen/integration/models-go" + "github.com/99designs/gqlgen/integration/remote_api" ) type CustomError struct { @@ -47,8 +47,8 @@ func (r *elementResolver) Mismatched(ctx context.Context, obj *models.Element) ( return []bool{true}, nil } -func (r *elementResolver) Child(ctx context.Context, obj *models.Element) (models.Element, error) { - return models.Element{ID: obj.ID * 10}, nil +func (r *elementResolver) Child(ctx context.Context, obj *models.Element) (*models.Element, error) { + return &models.Element{ID: obj.ID * 10}, nil } type queryResolver struct{ *Resolver } @@ -58,11 +58,11 @@ func (r *queryResolver) Error(ctx context.Context, typeArg *models.ErrorType) (b return false, &CustomError{"User message", "Internal Message"} } - return false, fmt.Errorf("Normal error") + return false, fmt.Errorf("normal error") } func (r *queryResolver) Path(ctx context.Context) ([]*models.Element, error) { - return []*models.Element{{1}, {2}, {3}, {4}}, nil + return []*models.Element{{ID: 1}, {ID: 2}, {ID: 3}, {ID: 4}}, nil } func (r *queryResolver) Date(ctx context.Context, filter models.DateFilter) (bool, error) { diff --git a/internal/code/compare.go b/internal/code/compare.go new file mode 100644 index 0000000000..dce9aea558 --- /dev/null +++ b/internal/code/compare.go @@ -0,0 +1,163 @@ +package code + +import ( + "fmt" + "go/types" +) + +// CompatibleTypes isnt a strict comparison, it allows for pointer differences +func CompatibleTypes(expected types.Type, actual types.Type) error { + //fmt.Println("Comparing ", expected.String(), actual.String()) + + // Special case to deal with pointer mismatches + { + expectedPtr, expectedIsPtr := expected.(*types.Pointer) + actualPtr, actualIsPtr := actual.(*types.Pointer) + + if expectedIsPtr && actualIsPtr { + return CompatibleTypes(expectedPtr.Elem(), actualPtr.Elem()) + } + if expectedIsPtr && !actualIsPtr { + return CompatibleTypes(expectedPtr.Elem(), actual) + } + if !expectedIsPtr && actualIsPtr { + return CompatibleTypes(expected, actualPtr.Elem()) + } + } + + switch expected := expected.(type) { + case *types.Slice: + if actual, ok := actual.(*types.Slice); ok { + return CompatibleTypes(expected.Elem(), actual.Elem()) + } + + case *types.Array: + if actual, ok := actual.(*types.Array); ok { + if expected.Len() != actual.Len() { + return fmt.Errorf("array length differs") + } + + return CompatibleTypes(expected.Elem(), actual.Elem()) + } + + case *types.Basic: + if actual, ok := actual.(*types.Basic); ok { + if actual.Kind() != expected.Kind() { + return fmt.Errorf("basic kind differs, %s != %s", expected.Name(), actual.Name()) + } + + return nil + } + + case *types.Struct: + if actual, ok := actual.(*types.Struct); ok { + if expected.NumFields() != actual.NumFields() { + return fmt.Errorf("number of struct fields differ") + } + + for i := 0; i < expected.NumFields(); i++ { + if expected.Field(i).Name() != actual.Field(i).Name() { + return fmt.Errorf("struct field %d name differs, %s != %s", i, expected.Field(i).Name(), actual.Field(i).Name()) + } + if err := CompatibleTypes(expected.Field(i).Type(), actual.Field(i).Type()); err != nil { + return err + } + } + return nil + } + + case *types.Tuple: + if actual, ok := actual.(*types.Tuple); ok { + if expected.Len() != actual.Len() { + return fmt.Errorf("tuple length differs, %d != %d", expected.Len(), actual.Len()) + } + + for i := 0; i < expected.Len(); i++ { + if err := CompatibleTypes(expected.At(i).Type(), actual.At(i).Type()); err != nil { + return err + } + } + + return nil + } + + case *types.Signature: + if actual, ok := actual.(*types.Signature); ok { + if err := CompatibleTypes(expected.Params(), actual.Params()); err != nil { + return err + } + if err := CompatibleTypes(expected.Results(), actual.Results()); err != nil { + return err + } + + return nil + } + case *types.Interface: + if actual, ok := actual.(*types.Interface); ok { + if expected.NumMethods() != actual.NumMethods() { + return fmt.Errorf("interface method count differs, %d != %d", expected.NumMethods(), actual.NumMethods()) + } + + for i := 0; i < expected.NumMethods(); i++ { + if expected.Method(i).Name() != actual.Method(i).Name() { + return fmt.Errorf("interface method %d name differs, %s != %s", i, expected.Method(i).Name(), actual.Method(i).Name()) + } + if err := CompatibleTypes(expected.Method(i).Type(), actual.Method(i).Type()); err != nil { + return err + } + } + + return nil + } + + case *types.Map: + if actual, ok := actual.(*types.Map); ok { + if err := CompatibleTypes(expected.Key(), actual.Key()); err != nil { + return err + } + + if err := CompatibleTypes(expected.Elem(), actual.Elem()); err != nil { + return err + } + + return nil + } + + case *types.Chan: + if actual, ok := actual.(*types.Chan); ok { + return CompatibleTypes(expected.Elem(), actual.Elem()) + } + + case *types.Named: + if actual, ok := actual.(*types.Named); ok { + if NormalizeVendor(expected.Obj().Pkg().Path()) != NormalizeVendor(actual.Obj().Pkg().Path()) { + return fmt.Errorf( + "package name of named type differs, %s != %s", + NormalizeVendor(expected.Obj().Pkg().Path()), + NormalizeVendor(actual.Obj().Pkg().Path()), + ) + } + + if expected.Obj().Name() != actual.Obj().Name() { + return fmt.Errorf( + "named type name differs, %s != %s", + NormalizeVendor(expected.Obj().Name()), + NormalizeVendor(actual.Obj().Name()), + ) + } + + return nil + } + + // Before models are generated all missing references will be Invalid Basic references. + // lets assume these are valid too. + if actual, ok := actual.(*types.Basic); ok && actual.Kind() == types.Invalid { + return nil + } + + default: + return fmt.Errorf("missing support for %T", expected) + } + + return fmt.Errorf("type mismatch %T != %T", expected, actual) +} diff --git a/internal/code/compare_test.go b/internal/code/compare_test.go new file mode 100644 index 0000000000..0100d57423 --- /dev/null +++ b/internal/code/compare_test.go @@ -0,0 +1,85 @@ +package code + +import ( + "go/ast" + "go/importer" + "go/parser" + "go/token" + "go/types" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCompatibleTypes(t *testing.T) { + valid := []struct { + expected string + actual string + }{ + {"string", "string"}, + {"*string", "string"}, + {"string", "*string"}, + {"*string", "*string"}, + {"[]string", "[]string"}, + {"*[]string", "[]string"}, + {"*[]string", "[]*string"}, + {"*[]*[]*[]string", "[][][]string"}, + {"map[string]interface{}", "map[string]interface{}"}, + {"map[string]string", "map[string]string"}, + {"Bar", "Bar"}, + {"interface{}", "interface{}"}, + {"interface{Foo() bool}", "interface{Foo() bool}"}, + {"struct{Foo bool}", "struct{Foo bool}"}, + } + + for _, tc := range valid { + t.Run(tc.expected+"="+tc.actual, func(t *testing.T) { + expectedType := parseTypeStr(t, tc.expected) + actualType := parseTypeStr(t, tc.actual) + require.NoError(t, CompatibleTypes(expectedType, actualType)) + }) + } + + invalid := []struct { + expected string + actual string + }{ + {"string", "int"}, + {"*string", "[]string"}, + {"[]string", "[][]string"}, + {"Bar", "Baz"}, + {"map[string]interface{}", "map[string]string"}, + {"map[string]string", "[]string"}, + {"interface{Foo() bool}", "interface{}"}, + {"struct{Foo bool}", "struct{Bar bool}"}, + } + + for _, tc := range invalid { + t.Run(tc.expected+"!="+tc.actual, func(t *testing.T) { + expectedType := parseTypeStr(t, tc.expected) + actualType := parseTypeStr(t, tc.actual) + require.Error(t, CompatibleTypes(expectedType, actualType)) + }) + } +} + +func parseTypeStr(t *testing.T, s string) types.Type { + t.Helper() + + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "test.go", `package test + type Bar string + type Baz string + + type Foo struct { + Field `+s+` + } + `, 0) + require.NoError(t, err) + + conf := types.Config{Importer: importer.Default()} + pkg, err := conf.Check("test", fset, []*ast.File{f}, nil) + require.NoError(t, err) + + return pkg.Scope().Lookup("Foo").Type().(*types.Named).Underlying().(*types.Struct).Field(0).Type() +} diff --git a/internal/code/imports.go b/internal/code/imports.go new file mode 100644 index 0000000000..2384e87da9 --- /dev/null +++ b/internal/code/imports.go @@ -0,0 +1,60 @@ +package code + +import ( + "errors" + "path/filepath" + "sync" + + "golang.org/x/tools/go/packages" +) + +var pathForDirCache = sync.Map{} + +// ImportPathFromDir takes an *absolute* path and returns a golang import path for the package, and returns an error if it isn't on the gopath +func ImportPathForDir(dir string) string { + if v, ok := pathForDirCache.Load(dir); ok { + return v.(string) + } + + p, _ := packages.Load(&packages.Config{ + Dir: dir, + }, ".") + + // If the dir dosent exist yet, keep walking up the directory tree trying to find a match + if len(p) != 1 { + parent, err := filepath.Abs(filepath.Join(dir, "..")) + if err != nil { + panic(err) + } + // Walked all the way to the root and didnt find anything :'( + if parent == dir { + return "" + } + return ImportPathForDir(parent) + "/" + filepath.Base(dir) + } + + pathForDirCache.Store(dir, p[0].PkgPath) + + return p[0].PkgPath +} + +var nameForPackageCache = sync.Map{} + +func NameForPackage(importPath string) string { + if importPath == "" { + panic(errors.New("import path can not be empty")) + } + if v, ok := nameForPackageCache.Load(importPath); ok { + return v.(string) + } + importPath = QualifyPackagePath(importPath) + p, _ := packages.Load(nil, importPath) + + if len(p) != 1 || p[0].Name == "" { + return SanitizePackageName(filepath.Base(importPath)) + } + + nameForPackageCache.Store(importPath, p[0].Name) + + return p[0].Name +} diff --git a/internal/code/imports_test.go b/internal/code/imports_test.go new file mode 100644 index 0000000000..b1493375ca --- /dev/null +++ b/internal/code/imports_test.go @@ -0,0 +1,32 @@ +package code + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestImportPathForDir(t *testing.T) { + wd, err := os.Getwd() + require.NoError(t, err) + + assert.Equal(t, "github.com/99designs/gqlgen/internal/code", ImportPathForDir(wd)) + assert.Equal(t, "github.com/99designs/gqlgen/api", ImportPathForDir(filepath.Join(wd, "..", "..", "api"))) + + // doesnt contain go code, but should still give a valid import path + assert.Equal(t, "github.com/99designs/gqlgen/docs", ImportPathForDir(filepath.Join(wd, "..", "..", "docs"))) + + // directory does not exist + assert.Equal(t, "github.com/99designs/gqlgen/dos", ImportPathForDir(filepath.Join(wd, "..", "..", "dos"))) +} + +func TestNameForPackage(t *testing.T) { + assert.Equal(t, "api", NameForPackage("github.com/99designs/gqlgen/api")) + + // does not contain go code, should still give a valid name + assert.Equal(t, "docs", NameForPackage("github.com/99designs/gqlgen/docs")) + assert.Equal(t, "github_com", NameForPackage("github.com")) +} diff --git a/internal/code/util.go b/internal/code/util.go new file mode 100644 index 0000000000..2be83a23ce --- /dev/null +++ b/internal/code/util.go @@ -0,0 +1,56 @@ +package code + +import ( + "go/build" + "os" + "path/filepath" + "regexp" + "strings" +) + +// take a string in the form github.com/package/blah.Type and split it into package and type +func PkgAndType(name string) (string, string) { + parts := strings.Split(name, ".") + if len(parts) == 1 { + return "", name + } + + return strings.Join(parts[:len(parts)-1], "."), parts[len(parts)-1] +} + +var modsRegex = regexp.MustCompile(`^(\*|\[\])*`) + +// NormalizeVendor takes a qualified package path and turns it into normal one. +// eg . +// github.com/foo/vendor/github.com/99designs/gqlgen/graphql becomes +// github.com/99designs/gqlgen/graphql +func NormalizeVendor(pkg string) string { + modifiers := modsRegex.FindAllString(pkg, 1)[0] + pkg = strings.TrimPrefix(pkg, modifiers) + parts := strings.Split(pkg, "/vendor/") + return modifiers + parts[len(parts)-1] +} + +// QualifyPackagePath takes an import and fully qualifies it with a vendor dir, if one is required. +// eg . +// github.com/99designs/gqlgen/graphql becomes +// github.com/foo/vendor/github.com/99designs/gqlgen/graphql +// +// x/tools/packages only supports 'qualified package paths' so this will need to be done prior to calling it +// See https://github.com/golang/go/issues/30289 +func QualifyPackagePath(importPath string) string { + wd, _ := os.Getwd() + + pkg, err := build.Import(importPath, wd, 0) + if err != nil { + return importPath + } + + return pkg.ImportPath +} + +var invalidPackageNameChar = regexp.MustCompile(`[^\w]`) + +func SanitizePackageName(pkg string) string { + return invalidPackageNameChar.ReplaceAllLiteralString(filepath.Base(pkg), "_") +} diff --git a/internal/code/util_test.go b/internal/code/util_test.go new file mode 100644 index 0000000000..6aa7ce68b2 --- /dev/null +++ b/internal/code/util_test.go @@ -0,0 +1,15 @@ +package code + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNormalizeVendor(t *testing.T) { + require.Equal(t, "bar/baz", NormalizeVendor("foo/vendor/bar/baz")) + require.Equal(t, "[]bar/baz", NormalizeVendor("[]foo/vendor/bar/baz")) + require.Equal(t, "*bar/baz", NormalizeVendor("*foo/vendor/bar/baz")) + require.Equal(t, "*[]*bar/baz", NormalizeVendor("*[]*foo/vendor/bar/baz")) + require.Equal(t, "[]*bar/baz", NormalizeVendor("[]*foo/vendor/bar/baz")) +} diff --git a/internal/gopath/gopath.go b/internal/gopath/gopath.go deleted file mode 100644 index c9b66167a3..0000000000 --- a/internal/gopath/gopath.go +++ /dev/null @@ -1,37 +0,0 @@ -package gopath - -import ( - "fmt" - "go/build" - "path/filepath" - "strings" -) - -var NotFound = fmt.Errorf("not on GOPATH") - -// Contains returns true if the given directory is in the GOPATH -func Contains(dir string) bool { - _, err := Dir2Import(dir) - return err == nil -} - -// Dir2Import takes an *absolute* path and returns a golang import path for the package, and returns an error if it isn't on the gopath -func Dir2Import(dir string) (string, error) { - dir = filepath.ToSlash(dir) - for _, gopath := range filepath.SplitList(build.Default.GOPATH) { - gopath = filepath.ToSlash(filepath.Join(gopath, "src")) - if len(gopath) < len(dir) && strings.EqualFold(gopath, dir[0:len(gopath)]) { - return dir[len(gopath)+1:], nil - } - } - return "", NotFound -} - -// MustDir2Import takes an *absolute* path and returns a golang import path for the package, and panics if it isn't on the gopath -func MustDir2Import(dir string) string { - pkg, err := Dir2Import(dir) - if err != nil { - panic(err) - } - return pkg -} diff --git a/internal/gopath/gopath_test.go b/internal/gopath/gopath_test.go deleted file mode 100644 index 847ad1e856..0000000000 --- a/internal/gopath/gopath_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package gopath - -import ( - "go/build" - "runtime" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestContains(t *testing.T) { - origBuildContext := build.Default - defer func() { build.Default = origBuildContext }() - - if runtime.GOOS == "windows" { - build.Default.GOPATH = `C:\go;C:\Users\user\go` - - assert.True(t, Contains(`C:\go\src\github.com\vektah\gqlgen`)) - assert.True(t, Contains(`C:\go\src\fpp`)) - assert.True(t, Contains(`C:/go/src/github.com/vektah/gqlgen`)) - assert.True(t, Contains(`C:\Users\user\go\src\foo`)) - assert.False(t, Contains(`C:\tmp`)) - assert.False(t, Contains(`C:\Users\user`)) - assert.False(t, Contains(`C:\Users\another\go`)) - } else { - build.Default.GOPATH = "/go:/home/user/go" - - assert.True(t, Contains("/go/src/github.com/vektah/gqlgen")) - assert.True(t, Contains("/go/src/foo")) - assert.True(t, Contains("/home/user/go/src/foo")) - assert.False(t, Contains("/tmp")) - assert.False(t, Contains("/home/user")) - assert.False(t, Contains("/home/another/go")) - } -} - -func TestDir2Package(t *testing.T) { - origBuildContext := build.Default - defer func() { build.Default = origBuildContext }() - - if runtime.GOOS == "windows" { - build.Default.GOPATH = "C:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;C:/a/y;C:/b/" - - assert.Equal(t, "foo/bar", MustDir2Import("C:/a/y/src/foo/bar")) - assert.Equal(t, "foo/bar", MustDir2Import(`C:\a\y\src\foo\bar`)) - assert.Equal(t, "foo/bar", MustDir2Import("C:/b/src/foo/bar")) - assert.Equal(t, "foo/bar", MustDir2Import(`C:\b\src\foo\bar`)) - - assert.PanicsWithValue(t, NotFound, func() { - MustDir2Import("C:/tmp/foo") - }) - } else { - build.Default.GOPATH = "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:/a/y:/b/" - - assert.Equal(t, "foo/bar", MustDir2Import("/a/y/src/foo/bar")) - assert.Equal(t, "foo/bar", MustDir2Import("/b/src/foo/bar")) - - assert.PanicsWithValue(t, NotFound, func() { - MustDir2Import("/tmp/foo") - }) - } -} diff --git a/internal/imports/prune.go b/internal/imports/prune.go index d2469e8370..d678870efa 100644 --- a/internal/imports/prune.go +++ b/internal/imports/prune.go @@ -5,16 +5,15 @@ package imports import ( "bytes" "go/ast" - "go/build" "go/parser" "go/printer" "go/token" - "path/filepath" "strings" - "golang.org/x/tools/imports" + "github.com/99designs/gqlgen/internal/code" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/imports" ) type visitFn func(node ast.Node) @@ -54,12 +53,6 @@ func getUnusedImports(file ast.Node, filename string) (map[string]string, error) imported := map[string]*ast.ImportSpec{} used := map[string]bool{} - abs, err := filepath.Abs(filename) - if err != nil { - return nil, err - } - srcDir := filepath.Dir(abs) - ast.Walk(visitFn(func(node ast.Node) { if node == nil { return @@ -75,7 +68,7 @@ func getUnusedImports(file ast.Node, filename string) (map[string]string, error) break } - local := importPathToName(ipath, srcDir) + local := code.NameForPackage(ipath) imported[local] = v case *ast.SelectorExpr: @@ -108,12 +101,3 @@ func getUnusedImports(file ast.Node, filename string) (map[string]string, error) return unusedImport, nil } - -func importPathToName(importPath, srcDir string) (packageName string) { - pkg, err := build.Default.Import(importPath, srcDir, 0) - if err != nil { - return "" - } - - return pkg.Name -} diff --git a/internal/imports/testdata/unused.go b/internal/imports/testdata/unused.go index 63ea8d7f84..db4c9b4d27 100644 --- a/internal/imports/testdata/unused.go +++ b/internal/imports/testdata/unused.go @@ -1,6 +1,5 @@ package testdata -import "unused" import _ "underscore" import a "fmt" import "time" @@ -14,8 +13,8 @@ func fn() { } type Message struct { - ID string `json:"id"` - Text string `json:"text"` - CreatedBy string `json:"createdBy"` + ID string `json:"id"` + Text string `json:"text"` + CreatedBy string `json:"createdBy"` CreatedAt time.Time `json:"createdAt"` } diff --git a/main.go b/main.go index 04c2bf5400..dbc2413538 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,9 @@ package main import ( - "fmt" - "os" - "github.com/99designs/gqlgen/cmd" ) func main() { - fmt.Fprintf(os.Stderr, "warning: running gqlgen from this binary is deprecated and may be removed in a future release. See https://github.com/99designs/gqlgen/issues/415\n") cmd.Execute() } diff --git a/plugin/modelgen/models.go b/plugin/modelgen/models.go new file mode 100644 index 0000000000..508cc14d07 --- /dev/null +++ b/plugin/modelgen/models.go @@ -0,0 +1,207 @@ +package modelgen + +import ( + "go/types" + "sort" + + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/99designs/gqlgen/internal/code" + "github.com/99designs/gqlgen/plugin" + "github.com/vektah/gqlparser/ast" +) + +type ModelBuild struct { + PackageName string + Interfaces []*Interface + Models []*Object + Enums []*Enum + Scalars []string +} + +type Interface struct { + Description string + Name string +} + +type Object struct { + Description string + Name string + Fields []*Field + Implements []string +} + +type Field struct { + Description string + Name string + Type types.Type + Tag string +} + +type Enum struct { + Description string + Name string + Values []*EnumValue +} + +type EnumValue struct { + Description string + Name string +} + +func New() plugin.Plugin { + return &Plugin{} +} + +type Plugin struct{} + +var _ plugin.ConfigMutator = &Plugin{} + +func (m *Plugin) Name() string { + return "modelgen" +} + +func (m *Plugin) MutateConfig(cfg *config.Config) error { + if err := cfg.Check(); err != nil { + return err + } + + schema, _, err := cfg.LoadSchema() + if err != nil { + return err + } + + cfg.InjectBuiltins(schema) + + binder, err := cfg.NewBinder(schema) + if err != nil { + return err + } + + b := &ModelBuild{ + PackageName: cfg.Model.Package, + } + + for _, schemaType := range schema.Types { + if cfg.Models.UserDefined(schemaType.Name) { + continue + } + + switch schemaType.Kind { + case ast.Interface, ast.Union: + it := &Interface{ + Description: schemaType.Description, + Name: schemaType.Name, + } + + b.Interfaces = append(b.Interfaces, it) + case ast.Object, ast.InputObject: + if schemaType == schema.Query || schemaType == schema.Mutation || schemaType == schema.Subscription { + continue + } + it := &Object{ + Description: schemaType.Description, + Name: schemaType.Name, + } + + for _, implementor := range schema.GetImplements(schemaType) { + it.Implements = append(it.Implements, implementor.Name) + } + + for _, field := range schemaType.Fields { + var typ types.Type + + if cfg.Models.UserDefined(field.Type.Name()) { + pkg, typeName := code.PkgAndType(cfg.Models[field.Type.Name()].Model[0]) + typ, err = binder.FindType(pkg, typeName) + if err != nil { + return err + } + } else { + fieldDef := schema.Types[field.Type.Name()] + switch fieldDef.Kind { + case ast.Scalar: + // no user defined model, referencing a default scalar + typ = types.NewNamed( + types.NewTypeName(0, cfg.Model.Pkg(), "string", nil), + nil, + nil, + ) + case ast.Interface, ast.Union: + // no user defined model, referencing a generated interface type + typ = types.NewNamed( + types.NewTypeName(0, cfg.Model.Pkg(), templates.ToGo(field.Type.Name()), nil), + types.NewInterfaceType([]*types.Func{}, []types.Type{}), + nil, + ) + default: + // no user defined model, must reference another generated model + typ = types.NewNamed( + types.NewTypeName(0, cfg.Model.Pkg(), templates.ToGo(field.Type.Name()), nil), + nil, + nil, + ) + } + } + + name := field.Name + if nameOveride := cfg.Models[schemaType.Name].Fields[field.Name].FieldName; nameOveride != "" { + name = nameOveride + } + + it.Fields = append(it.Fields, &Field{ + Name: name, + Type: binder.CopyModifiersFromAst(field.Type, typ), + Description: field.Description, + Tag: `json:"` + field.Name + `"`, + }) + } + + 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 { + return nil + } + + return templates.Render(templates.Options{ + PackageName: cfg.Model.Package, + Filename: cfg.Model.Filename, + Data: b, + GeneratedHeader: true, + }) +} diff --git a/plugin/modelgen/models.gotpl b/plugin/modelgen/models.gotpl new file mode 100644 index 0000000000..d06cf050f7 --- /dev/null +++ b/plugin/modelgen/models.gotpl @@ -0,0 +1,85 @@ +{{ reserveImport "context" }} +{{ reserveImport "fmt" }} +{{ reserveImport "io" }} +{{ reserveImport "strconv" }} +{{ reserveImport "time" }} +{{ reserveImport "sync" }} +{{ reserveImport "errors" }} +{{ reserveImport "bytes" }} + +{{ reserveImport "github.com/vektah/gqlparser" }} +{{ reserveImport "github.com/vektah/gqlparser/ast" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} + +{{- range $model := .Interfaces }} + {{ with .Description }} {{.|prefixLines "// "}} {{ end }} + type {{.Name|go }} interface { + Is{{.Name|go }}() + } +{{- end }} + +{{ range $model := .Models }} + {{with .Description }} {{.|prefixLines "// "}} {{end}} + type {{ .Name|go }} struct { + {{- range $field := .Fields }} + {{- with .Description }} + {{.|prefixLines "// "}} + {{- end}} + {{ $field.Name|go }} {{$field.Type | ref}} `{{$field.Tag}}` + {{- end }} + } + + {{- range $iface := .Implements }} + func ({{ $model.Name|go }}) Is{{ $iface }}() {} + {{- end }} +{{- end}} + +{{ range $enum := .Enums }} + {{ with .Description|go }} {{.|prefixLines "// "}} {{end}} + type {{.Name|go }} string + const ( + {{- range $value := .Values}} + {{- with .Description}} + {{.|prefixLines "// "}} + {{- end}} + {{ $enum.Name|go }}{{ .Name|go }} {{$enum.Name|go }} = {{.Name|quote}} + {{- end }} + ) + + var All{{.Name|go }} = []{{ .Name|go }}{ + {{- range $value := .Values}} + {{$enum.Name|go }}{{ .Name|go }}, + {{- end }} + } + + func (e {{.Name|go }}) IsValid() bool { + switch e { + case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.Name|go }}{{ $element.Name|go }}{{end}}: + return true + } + return false + } + + func (e {{.Name|go }}) String() string { + return string(e) + } + + func (e *{{.Name|go }}) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = {{ .Name|go }}(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid {{ .Name }}", str) + } + return nil + } + + func (e {{.Name|go }}) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) + } + +{{- end }} diff --git a/plugin/modelgen/models_test.go b/plugin/modelgen/models_test.go new file mode 100644 index 0000000000..49ea8c16ac --- /dev/null +++ b/plugin/modelgen/models_test.go @@ -0,0 +1,20 @@ +package modelgen + +import ( + "testing" + + "github.com/99designs/gqlgen/codegen/config" + "github.com/stretchr/testify/require" +) + +func TestModelGeneration(t *testing.T) { + cfg, err := config.LoadConfig("testdata/gqlgen.yml") + require.NoError(t, err) + p := Plugin{} + require.NoError(t, p.MutateConfig(cfg)) + + require.True(t, cfg.Models.UserDefined("MissingType")) + require.True(t, cfg.Models.UserDefined("MissingEnum")) + require.True(t, cfg.Models.UserDefined("MissingUnion")) + require.True(t, cfg.Models.UserDefined("MissingInterface")) +} diff --git a/plugin/modelgen/out/existing.go b/plugin/modelgen/out/existing.go new file mode 100644 index 0000000000..6e91b1eeb8 --- /dev/null +++ b/plugin/modelgen/out/existing.go @@ -0,0 +1,23 @@ +package out + +type ExistingModel struct { + Name string + Enum ExistingEnum + Int ExistingInterface +} + +type ExistingInput struct { + Name string + Enum ExistingEnum + Int ExistingInterface +} + +type ExistingEnum string + +type ExistingInterface interface { + IsExistingInterface() +} + +type ExistingUnion interface { + IsExistingUnion() +} diff --git a/plugin/modelgen/out/generated.go b/plugin/modelgen/out/generated.go new file mode 100644 index 0000000000..6d6cd6c1ea --- /dev/null +++ b/plugin/modelgen/out/generated.go @@ -0,0 +1,87 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package out + +import ( + "fmt" + "io" + "strconv" +) + +type MissingInterface interface { + IsMissingInterface() +} + +type MissingUnion interface { + IsMissingUnion() +} + +type ExistingType struct { + Name *string `json:"name"` + Enum *ExistingEnum `json:"enum"` + Int ExistingInterface `json:"int"` + Existing *MissingType `json:"existing"` +} + +func (ExistingType) IsMissingUnion() {} +func (ExistingType) IsMissingInterface() {} +func (ExistingType) IsExistingInterface() {} +func (ExistingType) IsExistingUnion() {} + +type MissingInput struct { + Name *string `json:"name"` + Enum *MissingEnum `json:"enum"` +} + +type MissingType struct { + Name *string `json:"name"` + Enum *MissingEnum `json:"enum"` + Int MissingInterface `json:"int"` + Existing *ExistingType `json:"existing"` +} + +func (MissingType) IsMissingInterface() {} +func (MissingType) IsExistingInterface() {} +func (MissingType) IsMissingUnion() {} +func (MissingType) IsExistingUnion() {} + +type MissingEnum string + +const ( + MissingEnumHello MissingEnum = "Hello" + MissingEnumGoodbye MissingEnum = "Goodbye" +) + +var AllMissingEnum = []MissingEnum{ + MissingEnumHello, + MissingEnumGoodbye, +} + +func (e MissingEnum) IsValid() bool { + switch e { + case MissingEnumHello, MissingEnumGoodbye: + return true + } + return false +} + +func (e MissingEnum) String() string { + return string(e) +} + +func (e *MissingEnum) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = MissingEnum(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid MissingEnum", str) + } + return nil +} + +func (e MissingEnum) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} diff --git a/plugin/modelgen/testdata/gqlgen.yml b/plugin/modelgen/testdata/gqlgen.yml new file mode 100644 index 0000000000..9c01c79b68 --- /dev/null +++ b/plugin/modelgen/testdata/gqlgen.yml @@ -0,0 +1,21 @@ +schema: + - "testdata/schema.graphql" + +exec: + filename: out/ignored.go +model: + filename: out/generated.go + +models: + ExistingModel: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingModel + ExistingInput: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInput + ExistingEnum: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingEnum + ExistingInterface: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingInterface + ExistingUnion: + model: github.com/99designs/gqlgen/plugin/modelgen/out.ExistingUnion + + diff --git a/plugin/modelgen/testdata/schema.graphql b/plugin/modelgen/testdata/schema.graphql new file mode 100644 index 0000000000..ada18dfa1a --- /dev/null +++ b/plugin/modelgen/testdata/schema.graphql @@ -0,0 +1,58 @@ +type Query { + thisShoudlntGetGenerated: Boolean +} + +type Mutation { + thisShoudlntGetGenerated: Boolean +} + +type Subscription { + thisShoudlntGetGenerated: Boolean +} + +type MissingType implements MissingInterface & ExistingInterface { + name: String + enum: MissingEnum + int: MissingInterface + existing: ExistingType +} + +input MissingInput { + name: String + enum: MissingEnum +} + +enum MissingEnum { + Hello + Goodbye +} + +interface MissingInterface { + name: String +} + +union MissingUnion = MissingType | ExistingType + +type ExistingType implements MissingInterface & ExistingInterface { + name: String + enum: ExistingEnum + int: ExistingInterface + existing: MissingType +} + +input ExistingInput { + name: String + enum: ExistingEnum +} + +enum ExistingEnum { + Hello + Goodbye +} + +interface ExistingInterface { + name: String +} + +union ExistingUnion = MissingType | ExistingType + diff --git a/plugin/plugin.go b/plugin/plugin.go new file mode 100644 index 0000000000..a84bfd3273 --- /dev/null +++ b/plugin/plugin.go @@ -0,0 +1,20 @@ +// plugin package interfaces are EXPERIMENTAL. + +package plugin + +import ( + "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/codegen/config" +) + +type Plugin interface { + Name() string +} + +type ConfigMutator interface { + MutateConfig(cfg *config.Config) error +} + +type CodeGenerator interface { + GenerateCode(cfg *codegen.Data) error +} diff --git a/plugin/resolvergen/resolver.go b/plugin/resolvergen/resolver.go new file mode 100644 index 0000000000..00a6d5c9d4 --- /dev/null +++ b/plugin/resolvergen/resolver.go @@ -0,0 +1,53 @@ +package resolvergen + +import ( + "log" + "os" + + "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/99designs/gqlgen/plugin" + "github.com/pkg/errors" +) + +func New() plugin.Plugin { + return &Plugin{} +} + +type Plugin struct{} + +var _ plugin.CodeGenerator = &Plugin{} + +func (m *Plugin) Name() string { + return "resovlergen" +} +func (m *Plugin) GenerateCode(data *codegen.Data) error { + if !data.Config.Resolver.IsDefined() { + return nil + } + + resolverBuild := &ResolverBuild{ + Data: data, + PackageName: data.Config.Resolver.Package, + ResolverType: data.Config.Resolver.Type, + } + filename := data.Config.Resolver.Filename + + if _, err := os.Stat(filename); os.IsNotExist(errors.Cause(err)) { + return templates.Render(templates.Options{ + PackageName: data.Config.Resolver.Package, + Filename: data.Config.Resolver.Filename, + Data: resolverBuild, + }) + } + + log.Printf("Skipped resolver: %s already exists\n", filename) + return nil +} + +type ResolverBuild struct { + *codegen.Data + + PackageName string + ResolverType string +} diff --git a/plugin/resolvergen/resolver.gotpl b/plugin/resolvergen/resolver.gotpl new file mode 100644 index 0000000000..7d95e6903c --- /dev/null +++ b/plugin/resolvergen/resolver.gotpl @@ -0,0 +1,40 @@ +// THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES. + +{{ reserveImport "context" }} +{{ reserveImport "fmt" }} +{{ reserveImport "io" }} +{{ reserveImport "strconv" }} +{{ reserveImport "time" }} +{{ reserveImport "sync" }} +{{ reserveImport "errors" }} +{{ reserveImport "bytes" }} + +{{ reserveImport "github.com/99designs/gqlgen/handler" }} +{{ reserveImport "github.com/vektah/gqlparser" }} +{{ reserveImport "github.com/vektah/gqlparser/ast" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} + +type {{.ResolverType}} struct {} + +{{ range $object := .Objects -}} + {{- if $object.HasResolvers -}} + func (r *{{$.ResolverType}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} { + return &{{lcFirst $object.Name}}Resolver{r} + } + {{ end -}} +{{ end }} + +{{ range $object := .Objects -}} + {{- if $object.HasResolvers -}} + type {{lcFirst $object.Name}}Resolver struct { *Resolver } + + {{ range $field := $object.Fields -}} + {{- if $field.IsResolver -}} + func (r *{{lcFirst $object.Name}}Resolver) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} { + panic("not implemented") + } + {{ end -}} + {{ end -}} + {{ end -}} +{{ end }} diff --git a/plugin/servergen/server.go b/plugin/servergen/server.go new file mode 100644 index 0000000000..22289c0254 --- /dev/null +++ b/plugin/servergen/server.go @@ -0,0 +1,49 @@ +package servergen + +import ( + "log" + "os" + + "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/99designs/gqlgen/plugin" + "github.com/pkg/errors" +) + +func New(filename string) plugin.Plugin { + return &Plugin{filename} +} + +type Plugin struct { + filename string +} + +var _ plugin.CodeGenerator = &Plugin{} + +func (m *Plugin) Name() string { + return "servergen" +} +func (m *Plugin) GenerateCode(data *codegen.Data) error { + serverBuild := &ServerBuild{ + ExecPackageName: data.Config.Exec.ImportPath(), + ResolverPackageName: data.Config.Resolver.ImportPath(), + } + + if _, err := os.Stat(m.filename); os.IsNotExist(errors.Cause(err)) { + return templates.Render(templates.Options{ + PackageName: "main", + Filename: m.filename, + Data: serverBuild, + }) + } + + log.Printf("Skipped server: %s already exists\n", m.filename) + return nil +} + +type ServerBuild struct { + codegen.Data + + ExecPackageName string + ResolverPackageName string +} diff --git a/codegen/templates/server.gotpl b/plugin/servergen/server.gotpl similarity index 70% rename from codegen/templates/server.gotpl rename to plugin/servergen/server.gotpl index 38dc0d1822..fca71c53cd 100644 --- a/codegen/templates/server.gotpl +++ b/plugin/servergen/server.gotpl @@ -1,14 +1,8 @@ -package main - -import ( - %%%IMPORTS%%% - - {{ reserveImport "context" }} - {{ reserveImport "log" }} - {{ reserveImport "net/http" }} - {{ reserveImport "os" }} - {{ reserveImport "github.com/99designs/gqlgen/handler" }} -) +{{ reserveImport "context" }} +{{ reserveImport "log" }} +{{ reserveImport "net/http" }} +{{ reserveImport "os" }} +{{ reserveImport "github.com/99designs/gqlgen/handler" }} const defaultPort = "8080" diff --git a/plugin/stubgen/stubs.go b/plugin/stubgen/stubs.go new file mode 100644 index 0000000000..1dc29ee7da --- /dev/null +++ b/plugin/stubgen/stubs.go @@ -0,0 +1,55 @@ +package stubgen + +import ( + "path/filepath" + "syscall" + + "github.com/99designs/gqlgen/internal/code" + + "github.com/99designs/gqlgen/codegen" + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/codegen/templates" + "github.com/99designs/gqlgen/plugin" +) + +func New(filename string, typename string) plugin.Plugin { + return &Plugin{filename: filename, typeName: typename} +} + +type Plugin struct { + filename string + typeName string +} + +var _ plugin.CodeGenerator = &Plugin{} +var _ plugin.ConfigMutator = &Plugin{} + +func (m *Plugin) Name() string { + return "stubgen" +} + +func (m *Plugin) MutateConfig(cfg *config.Config) error { + _ = syscall.Unlink(m.filename) + return nil +} + +func (m *Plugin) GenerateCode(data *codegen.Data) error { + pkgPath := code.ImportPathForDir(filepath.Dir(m.filename)) + pkgName := code.NameForPackage(pkgPath) + + return templates.Render(templates.Options{ + PackageName: pkgName, + Filename: m.filename, + Data: &ResolverBuild{ + Data: data, + TypeName: m.typeName, + }, + GeneratedHeader: true, + }) +} + +type ResolverBuild struct { + *codegen.Data + + TypeName string +} diff --git a/plugin/stubgen/stubs.gotpl b/plugin/stubgen/stubs.gotpl new file mode 100644 index 0000000000..c1e9b31314 --- /dev/null +++ b/plugin/stubgen/stubs.gotpl @@ -0,0 +1,57 @@ +{{ reserveImport "context" }} +{{ reserveImport "fmt" }} +{{ reserveImport "io" }} +{{ reserveImport "strconv" }} +{{ reserveImport "time" }} +{{ reserveImport "sync" }} +{{ reserveImport "errors" }} +{{ reserveImport "bytes" }} + +{{ reserveImport "github.com/99designs/gqlgen/handler" }} +{{ reserveImport "github.com/vektah/gqlparser" }} +{{ reserveImport "github.com/vektah/gqlparser/ast" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql" }} +{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }} + +{{ $root := . }} + +type {{$root.TypeName}} struct { + {{ range $object := .Objects }} + {{- if $object.HasResolvers }} + {{$object.Name}}Resolver struct { + {{- range $field := $object.Fields }} + {{- if $field.IsResolver }} + {{- $field.GoFieldName}} func{{ $field.ShortResolverDeclaration }} + {{ end }} + {{- end }} + } + {{- end }} + {{- end }} +} + +{{ range $object := .Objects -}} + {{- if $object.HasResolvers -}} + func (r *{{$.TypeName}}) {{$object.Name}}() {{ $object.ResolverInterface | ref }} { + return &{{lcFirst $root.TypeName}}{{$object.Name}}{r} + } + {{ end -}} +{{ end }} + +{{ range $object := .Objects -}} + {{- if $object.HasResolvers -}} + type {{lcFirst $root.TypeName}}{{$object.Name}} struct { *{{$root.TypeName}} } + + {{ range $field := $object.Fields -}} + {{- if $field.IsResolver -}} + func (r *{{lcFirst $root.TypeName}}{{$object.Name}}) {{$field.GoFieldName}}{{ $field.ShortResolverDeclaration }} { + return r.{{$object.Name}}Resolver.{{$field.GoFieldName}}(ctx, + {{- if not $object.Root }}obj,{{end -}} + {{- range $arg := $field.Args}} + {{- $arg.VarName}}, + {{- end }} + ) + } + {{ end -}} + {{ end -}} + {{ end -}} +{{ end }} diff --git a/testdata/gqlgen.go b/testdata/gqlgen.go new file mode 100644 index 0000000000..f4bbe75507 --- /dev/null +++ b/testdata/gqlgen.go @@ -0,0 +1,42 @@ +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "time" + + "github.com/99designs/gqlgen/api" + "github.com/99designs/gqlgen/codegen/config" + "github.com/99designs/gqlgen/plugin/stubgen" +) + +func main() { + stub := flag.String("stub", "", "name of stub file to generate") + flag.Parse() + + log.SetOutput(ioutil.Discard) + + start := time.Now() + + cfg, err := config.LoadConfigFromDefaultLocations() + if err != nil { + fmt.Fprintln(os.Stderr, "failed to load config", err.Error()) + os.Exit(2) + } + + var options []api.Option + if *stub != "" { + options = append(options, api.AddPlugin(stubgen.New(*stub, "Stub"))) + } + + err = api.Generate(cfg, options...) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(3) + } + + fmt.Printf("Generated %s in %4.2fs\n", cfg.Exec.ImportPath(), time.Since(start).Seconds()) +} diff --git a/tools.go b/tools.go new file mode 100644 index 0000000000..912fc0d635 --- /dev/null +++ b/tools.go @@ -0,0 +1,5 @@ +// +build tools + +package main + +import _ "github.com/vektah/dataloaden"