-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat-directive-parent
- Loading branch information
Showing
17 changed files
with
247 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Describe your PR and link to any relevant issues. | ||
|
||
I have: | ||
- [ ] Added tests covering the bug / feature (see [testing](https://github.com/99designs/gqlgen/blob/master/TESTING.md)) | ||
- [ ] Updated any relevant documentation (see [docs](https://github.com/99designs/gqlgen/tree/master/docs/content)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
How to write tests for gqlgen | ||
=== | ||
|
||
Testing generated code is a little tricky, heres how its currently set up. | ||
|
||
### Testing responses from a server | ||
|
||
There is a server in `codegen/testserver` that is generated as part | ||
of `go generate ./...`, and tests written against it. | ||
|
||
There are also a bunch of tests in against the examples, feel free to take examples from there. | ||
|
||
|
||
### Testing the errors generated by the binary | ||
|
||
These tests are **really** slow, because they need to run the whole codegen step. Use them very sparingly. If you can, find a way to unit test it instead. | ||
|
||
Take a look at `codegen/input_test.go` for an example. | ||
|
||
### Testing introspection | ||
|
||
Introspection is tested by diffing the output of `graphql get-schema` against an expected output. | ||
|
||
Setting up the integration environment is a little tricky: | ||
```bash | ||
cd integration | ||
go generate ./... | ||
go run ./server/server.go | ||
``` | ||
in another terminal | ||
```bash | ||
cd integration | ||
npm install | ||
SERVER_URL=http://localhost:8080/query ./node_modules/.bin/graphql get-schema | ||
``` | ||
|
||
will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql` | ||
|
||
CI will run this and fail the build if the two files dont match. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
{{ range .Data.Pages }} | ||
{{ if or .Description (eq .Kind "home") }} | ||
<url> | ||
<loc>{{ .Permalink }}</loc> | ||
{{ if not .Lastmod.IsZero }}<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }} | ||
{{ with .Sitemap.ChangeFreq }}<changefreq>{{ . }}</changefreq>{{ end }} | ||
{{ if ge .Sitemap.Priority 0.0 }}<priority>{{ .Sitemap.Priority }}</priority>{{ end }} | ||
</url> | ||
{{ end }} | ||
{{ end }} | ||
</urlset> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 | ||
} |
Oops, something went wrong.