Skip to content

Commit

Permalink
updated imports (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Mar 23, 2020
1 parent d8a3582 commit e4986d4
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 16 deletions.
66 changes: 66 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package graphql

import (
"fmt"
"strings"

"github.com/vektah/gqlparser/v2/ast"
)

func formatIndentPrefix(level int) string {
acc := "\n"
// build up the prefix
for i := 0; i <= level; i++ {
acc += " "
}

return acc
}
func formatSelectionSelectionSet(level int, selectionSet ast.SelectionSet) string {
acc := " {"
// and any sub selection
acc += formatSelection(level+1, selectionSet)
acc += formatIndentPrefix(level) + "}"

return acc
}

func formatSelection(level int, selectionSet ast.SelectionSet) string {
acc := ""

for _, selection := range selectionSet {
acc += formatIndentPrefix(level)
switch selection := selection.(type) {
case *ast.Field:
// add the field name
acc += selection.Name
if len(selection.SelectionSet) > 0 {
acc += formatSelectionSelectionSet(level, selection.SelectionSet)
}
case *ast.InlineFragment:
// print the fragment name
acc += fmt.Sprintf("... on %v", selection.TypeCondition) +
formatSelectionSelectionSet(level, selection.SelectionSet)
case *ast.FragmentSpread:
// print the fragment name
acc += "..." + selection.Name
}
}

return acc
}

// FormatSelectionSet returns a pretty printed version of a selection set
func FormatSelectionSet(selection ast.SelectionSet) string {
acc := "{"

insides := formatSelection(0, selection)

if strings.TrimSpace(insides) != "" {
acc += insides + "\n}"
} else {
acc += "}"
}

return acc
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ require (
github.com/graphql-go/graphql v0.7.7
github.com/mitchellh/mapstructure v1.1.2
github.com/opentracing/opentracing-go v1.0.2 // indirect
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.4.0
github.com/vektah/gqlparser v1.1.0
github.com/vektah/gqlparser/v2 v2.0.1
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect
)

go 1.13
14 changes: 14 additions & 0 deletions go.sum
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,38 @@ github.com/carted/graphql v0.7.6 h1:1DAom3l7Irln/hHlPMBR6w/RirCXjopsCY9WCZc7WUc=
github.com/carted/graphql v0.7.6/go.mod h1:aIVByVaa4avHzEnahcnHbP48OrkT/+gTtxBT+dPV2R0=
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/graph-gophers/dataloader v5.0.0+incompatible h1:R+yjsbrNq1Mo3aPG+Z/EKYrXrXXUNJHOgbRt+U6jOug=
github.com/graph-gophers/dataloader v5.0.0+incompatible/go.mod h1:jk4jk0c5ZISbKaMe8WsVopGB5/15GvGHMdMdPtwlRp4=
github.com/graphql-go/graphql v0.7.7 h1:nwEsJGwPq9N6cElOO+NYyoWuELAQZ4GuJks0Rlco5og=
github.com/graphql-go/graphql v0.7.7/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI=
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/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/vektah/gqlparser v1.1.0 h1:3668p2gUlO+PiS81x957Rpr3/FPRWG6cxgCXAvTS1hw=
github.com/vektah/gqlparser v1.1.0/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqfU=
github.com/vektah/gqlparser/v2 v2.0.1 h1:xgl5abVnsd4hkN9rk65OJID9bfcLSMuTaTcZj777q1o=
github.com/vektah/gqlparser/v2 v2.0.1/go.mod h1:SyUiHgLATUR8BiYURfTirrTcGpcE+4XkV2se04Px1Ms=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
4 changes: 2 additions & 2 deletions graphql.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package graphql

import (
"github.com/vektah/gqlparser"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2"
"github.com/vektah/gqlparser/v2/ast"
)

// LoadSchema takes an SDL string and returns the parsed version
Expand Down
2 changes: 1 addition & 1 deletion introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

// IntrospectRemoteSchema is used to build a RemoteSchema by firing the introspection query
Expand Down
2 changes: 1 addition & 1 deletion introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

func TestIntrospectQuery_savesQueryType(t *testing.T) {
Expand Down
11 changes: 4 additions & 7 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphql
import (
"fmt"

"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

// CollectedField is a representations of a field with the list of selection sets that
Expand Down Expand Up @@ -43,17 +43,14 @@ func (c *CollectedFieldList) GetOrCreateForAlias(alias string, creator func() *C
// ApplyFragments takes a list of selections and merges them into one, embedding any fragments it
// runs into along the way
func ApplyFragments(selectionSet ast.SelectionSet, fragmentDefs ast.FragmentDefinitionList) (ast.SelectionSet, error) {
// build up a list of selection sets
final := ast.SelectionSet{}

// look for all of the collected fields
// apply the fragments
collectedFields, err := collectFields([]ast.SelectionSet{selectionSet}, fragmentDefs)
if err != nil {
return nil, err
}

// the final result of collecting fields should have a single selection in its selection set
// which should be a selection for the same field referenced by collected.Field
// turn the CollectedField list into a selection set
final := ast.SelectionSet{}
for _, collected := range *collectedFields {
final = append(final, collected.Field)
}
Expand Down
2 changes: 1 addition & 1 deletion language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

func TestApplyFragments_mergesFragments(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/carted/graphql/language/printer"
gAst "github.com/graphql-go/graphql/language/ast"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

// PrintQuery creates a string representation of an operation
Expand Down
2 changes: 1 addition & 1 deletion printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

func TestPrintQuery(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion queryer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"reflect"

"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/v2/ast"
)

// RemoteSchema encapsulates a particular schema that can be executed by sending network requests to the
Expand Down

0 comments on commit e4986d4

Please sign in to comment.