forked from arsmn/fastgql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 99designs#874 from 99designs/configurable-slice-el…
…ement-pointers Add config option to omit pointers to slice elements
- Loading branch information
Showing
4 changed files
with
74 additions
and
9 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
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,61 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/vektah/gqlparser" | ||
"github.com/vektah/gqlparser/ast" | ||
) | ||
|
||
func TestSlicePointerBinding(t *testing.T) { | ||
t.Run("without OmitSliceElementPointers", func(t *testing.T) { | ||
binder, schema := createBinder(Config{ | ||
OmitSliceElementPointers: false, | ||
}) | ||
|
||
ta, err := binder.TypeReference(schema.Query.Fields.ForName("messages").Type, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
require.Equal(t, ta.GO.String(), "[]*github.com/99designs/gqlgen/example/chat.Message") | ||
}) | ||
|
||
t.Run("with OmitSliceElementPointers", func(t *testing.T) { | ||
binder, schema := createBinder(Config{ | ||
OmitSliceElementPointers: true, | ||
}) | ||
|
||
ta, err := binder.TypeReference(schema.Query.Fields.ForName("messages").Type, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
require.Equal(t, ta.GO.String(), "[]github.com/99designs/gqlgen/example/chat.Message") | ||
}) | ||
} | ||
|
||
func createBinder(cfg Config) (*Binder, *ast.Schema) { | ||
cfg.Models = TypeMap{ | ||
"Message": TypeMapEntry{ | ||
Model: []string{"github.com/99designs/gqlgen/example/chat.Message"}, | ||
}, | ||
} | ||
|
||
s := gqlparser.MustLoadSchema(&ast.Source{Name: "TestAutobinding.schema", Input: ` | ||
type Message { id: ID } | ||
type Query { | ||
messages: [Message!]! | ||
} | ||
`}) | ||
|
||
b, err := cfg.NewBinder(s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return b, s | ||
} |
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