Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 2450afb

Browse files
authored
Merge pull request #5 from Code-Hex/fix/support-glob
support glob
2 parents ef39bfa + 0534860 commit 2450afb

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ If you want to specify multiple schema, you can use `--schema` flag repeatedly.
3434
$ gqldoc -s a.graphql -s b.graphql -o ./doc_dir
3535
```
3636

37+
You can also use glob.
38+
39+
```sh
40+
$ gqldoc -s "schema/**/*.graphql" -o ./doc_dir
41+
```
42+
3743
## Installation
3844

3945
### Mac and Linux users via Homebrew

cmd/gqldoc/main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/Code-Hex/gqldoc/loader"
1414
"github.com/machinebox/graphql"
1515
gqlcli "github.com/machinebox/graphql"
16+
"github.com/mattn/go-zglob"
1617
"github.com/pkg/errors"
1718
"github.com/urfave/cli/v2"
1819
)
@@ -122,15 +123,23 @@ func convertSchemaTree(schemaFiles []string) (*introspection.Root, error) {
122123
return nil, errHelp
123124
}
124125

126+
gqlfiles := make([]string, 0, len(schemaFiles))
125127
for _, schema := range schemaFiles {
126-
switch filepath.Ext(schema) {
127-
case ".graphqls", ".graphql", ".gql":
128-
default:
129-
return nil, errHelp
128+
matches, err := zglob.Glob(schema)
129+
if err != nil {
130+
return nil, errors.WithStack(err)
131+
}
132+
for _, maybeSchema := range matches {
133+
switch filepath.Ext(maybeSchema) {
134+
case ".graphqls", ".graphql", ".gql":
135+
gqlfiles = append(gqlfiles, maybeSchema)
136+
default:
137+
return nil, errHelp
138+
}
130139
}
131140
}
132141

133-
schema, err := loader.LoadSchema(schemaFiles...)
142+
schema, err := loader.LoadSchema(gqlfiles...)
134143
if err != nil {
135144
return nil, errors.WithStack(err)
136145
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/99designs/gqlgen v0.13.0
77
github.com/machinebox/graphql v0.2.2
88
github.com/matryer/is v1.4.0 // indirect
9+
github.com/mattn/go-zglob v0.0.3
910
github.com/pkg/errors v0.8.1
1011
github.com/russross/blackfriday/v2 v2.1.0
1112
github.com/urfave/cli/v2 v2.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIG
3333
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
3434
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
3535
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
36+
github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To=
37+
github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
3638
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
3739
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
3840
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=

0 commit comments

Comments
 (0)