Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devsergiy committed Oct 2, 2024
1 parent d7f6a41 commit 5476393
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 98 deletions.
41 changes: 29 additions & 12 deletions v2/pkg/engine/plan/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/jensneuse/abstractlogger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/wundergraph/graphql-go-tools/v2/pkg/ast"
"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/datasource/httpclient"

Expand Down Expand Up @@ -100,7 +101,9 @@ func TestPlanner_Plan(t *testing.T) {
Path: []string{"searchResults"},
Nullable: true,
Item: &resolve.Object{
Nullable: true,
Nullable: true,
TypeName: "SearchResult",
PossibleTypes: map[string]struct{}{"Human": {}, "Droid": {}, "Starship": {}},
Fields: []*resolve.Field{
{
Name: []byte("name"),
Expand Down Expand Up @@ -160,8 +163,10 @@ func TestPlanner_Plan(t *testing.T) {
{
Name: []byte("hero"),
Value: &resolve.Object{
Path: []string{"hero"},
Nullable: true,
Path: []string{"hero"},
Nullable: true,
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Human": {}, "Droid": {}},
Fields: []*resolve.Field{
{
Name: []byte("name"),
Expand Down Expand Up @@ -225,8 +230,10 @@ func TestPlanner_Plan(t *testing.T) {
{
Name: []byte("hero"),
Value: &resolve.Object{
Path: []string{"hero"},
Nullable: true,
Path: []string{"hero"},
Nullable: true,
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Human": {}, "Droid": {}},
Fields: []*resolve.Field{
{
Name: []byte("name"),
Expand Down Expand Up @@ -390,7 +397,9 @@ func TestPlanner_Plan(t *testing.T) {
{
Name: []byte("hero"),
Value: &resolve.Object{
Path: []string{"hero"},
Path: []string{"hero"},
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Character": {}},
Fields: []*resolve.Field{
{
Name: []byte("info"),
Expand Down Expand Up @@ -441,7 +450,9 @@ func TestPlanner_Plan(t *testing.T) {
{
Name: []byte("hero"),
Value: &resolve.Object{
Path: []string{"hero"},
Path: []string{"hero"},
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Character": {}},
Fields: []*resolve.Field{
{
Name: []byte("infos"),
Expand Down Expand Up @@ -499,7 +510,9 @@ func TestPlanner_Plan(t *testing.T) {
{
Name: []byte("hero"),
Value: &resolve.Object{
Path: []string{"hero"},
Path: []string{"hero"},
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Character": {}},
Fields: []*resolve.Field{
{
Name: []byte("info"),
Expand Down Expand Up @@ -544,8 +557,10 @@ var expectedMyHeroPlan = &SynchronousResponsePlan{
Column: 6,
},
Value: &resolve.Object{
Path: []string{"hero"},
Nullable: true,
Path: []string{"hero"},
Nullable: true,
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Human": {}, "Droid": {}},
Fields: []*resolve.Field{
{
Name: []byte("name"),
Expand Down Expand Up @@ -585,8 +600,10 @@ var expectedMyHeroPlanWithFragment = &SynchronousResponsePlan{
Column: 6,
},
Value: &resolve.Object{
Path: []string{"hero"},
Nullable: true,
Path: []string{"hero"},
Nullable: true,
TypeName: "Character",
PossibleTypes: map[string]struct{}{"Human": {}, "Droid": {}},
Fields: []*resolve.Field{
{
Name: []byte("name"),
Expand Down
61 changes: 41 additions & 20 deletions v2/pkg/engine/plan/subscription_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/wundergraph/graphql-go-tools/v2/pkg/astnormalization"
"github.com/wundergraph/graphql-go-tools/v2/pkg/asttransform"
"github.com/wundergraph/graphql-go-tools/v2/pkg/astvalidation"
Expand Down Expand Up @@ -132,8 +133,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByID"),
Value: &resolve.Object{
Path: []string{"heroByID"},
Nullable: true,
Path: []string{"heroByID"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -214,8 +217,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByIDInput"),
Value: &resolve.Object{
Path: []string{"heroByIDInput"},
Nullable: true,
Path: []string{"heroByIDInput"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -279,8 +284,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByID"),
Value: &resolve.Object{
Path: []string{"heroByID"},
Nullable: true,
Path: []string{"heroByID"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -365,8 +372,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByID"),
Value: &resolve.Object{
Path: []string{"heroByID"},
Nullable: true,
Path: []string{"heroByID"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -451,8 +460,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByID"),
Value: &resolve.Object{
Path: []string{"heroByID"},
Nullable: true,
Path: []string{"heroByID"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -541,8 +552,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByID"),
Value: &resolve.Object{
Path: []string{"heroByID"},
Nullable: true,
Path: []string{"heroByID"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -644,8 +657,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByIDInput"),
Value: &resolve.Object{
Path: []string{"heroByIDInput"},
Nullable: true,
Path: []string{"heroByIDInput"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -757,8 +772,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByIDMultipleArgs"),
Value: &resolve.Object{
Path: []string{"heroByIDMultipleArgs"},
Nullable: true,
Path: []string{"heroByIDMultipleArgs"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -877,8 +894,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByIDMultipleArgs"),
Value: &resolve.Object{
Path: []string{"heroByIDMultipleArgs"},
Nullable: true,
Path: []string{"heroByIDMultipleArgs"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down Expand Up @@ -975,8 +994,10 @@ func TestPlanSubscriptionFilter(t *testing.T) {
{
Name: []byte("heroByIDs"),
Value: &resolve.Object{
Path: []string{"heroByIDs"},
Nullable: true,
Path: []string{"heroByIDs"},
Nullable: true,
TypeName: "Hero",
PossibleTypes: map[string]struct{}{"Hero": {}},
Fields: []*resolve.Field{
{
Name: []byte("id"),
Expand Down
10 changes: 6 additions & 4 deletions v2/pkg/engine/plan/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,12 @@ func (v *Visitor) resolveFieldValue(fieldRef, typeRef int, nullable bool, path [
default:
}

if len(v.currentField.Info.Source.Names) > 0 {
object.SourceName = v.currentField.Info.Source.Names[0]
} else if len(v.currentField.Info.Source.IDs) > 0 {
object.SourceName = v.currentField.Info.Source.IDs[0]
if v.currentField.Info != nil {
if len(v.currentField.Info.Source.Names) > 0 {
object.SourceName = v.currentField.Info.Source.Names[0]
} else if len(v.currentField.Info.Source.IDs) > 0 {
object.SourceName = v.currentField.Info.Source.IDs[0]
}
}

v.objects = append(v.objects, object)
Expand Down
8 changes: 6 additions & 2 deletions v2/pkg/engine/resolve/resolvable.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (r *Resolvable) walkObject(obj *Object, parent *astjson.Value) bool {
}

typeName := value.GetStringBytes("__typename")
if typeName != nil {
if typeName != nil && len(obj.PossibleTypes) > 0 {
if _, ok := obj.PossibleTypes[string(typeName)]; !ok {
if !r.print {
if r.options.ApolloCompatibilityValueCompletionInExtensions {
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func (r *Resolvable) addValueCompletion(message, code string) {
}

func (r *Resolvable) pathLastElementDescription(typeName string) string {
if len(r.path) == 1 {
if len(r.path) <= 1 {
switch r.operationType {
case ast.OperationTypeQuery:
typeName = "Query"
Expand All @@ -1064,6 +1064,10 @@ func (r *Resolvable) pathLastElementDescription(typeName string) string {
case ast.OperationTypeSubscription:
typeName = "Subscription"
}

if len(r.path) == 0 {
return typeName
}
}
elem := r.path[len(r.path)-1]
if elem.Name != "" {
Expand Down
Loading

0 comments on commit 5476393

Please sign in to comment.