Skip to content

Commit

Permalink
fix: fix nil typename with multiple queries (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus committed Jun 8, 2023
1 parent 2e219a6 commit b0e183c
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 46 deletions.
3 changes: 1 addition & 2 deletions examples/federation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ require (
github.com/nats-io/nats.go v1.19.1 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/qri-io/jsonpointer v0.1.1 // indirect
github.com/qri-io/jsonschema v0.2.1 // indirect
github.com/r3labs/sse/v2 v2.8.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/tidwall/gjson v1.11.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down
11 changes: 4 additions & 7 deletions examples/federation/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
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 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/logrusorgru/aurora/v3 v3.0.0 h1:R6zcoZZbvVcGMvDCKo45A9U/lzYyzl5NfYIvznmDfE4=
Expand Down Expand Up @@ -126,17 +126,14 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
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/qri-io/jsonpointer v0.1.1 h1:prVZBZLL6TW5vsSB9fFHFAMBLI4b0ri5vribQlTJiBA=
github.com/qri-io/jsonpointer v0.1.1/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=
github.com/qri-io/jsonschema v0.2.1 h1:NNFoKms+kut6ABPf6xiKNM5214jzxAhDBrPHCJ97Wg0=
github.com/qri-io/jsonschema v0.2.1/go.mod h1:g7DPkiOsK1xv6T/Ao5scXRkd+yTFygcANPBaaqW+VrI=
github.com/r3labs/sse/v2 v2.8.1 h1:lZH+W4XOLIq88U5MIHOsLec7+R62uhz3bIi2yn0Sg8o=
github.com/r3labs/sse/v2 v2.8.1/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 h1:uIkTLo0AGRc8l7h5l9r+GcYi9qfVPt6lD4/bhmzfiKo=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
github.com/sebdah/goldie/v2 v2.5.3 h1:9ES/mNN+HNUbNWpVAlrzuZ7jE+Nrczbj8uFRjM7624Y=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down Expand Up @@ -262,8 +259,8 @@ gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (p *Planner) EnterField(ref int) {
}

fieldConfiguration := p.visitor.Config.Fields.ForTypeField(enclosingTypeName, fieldName)
if fieldConfiguration == nil && fieldName != "__typename" {
if fieldConfiguration == nil {
p.addField(ref)
return
}
Expand All @@ -536,10 +536,6 @@ func (p *Planner) EnterField(ref int) {

upstreamFieldRef := p.nodes[len(p.nodes)-1].Ref

if fieldConfiguration == nil {
return
}

for i := range fieldConfiguration.Arguments {
argumentConfiguration := fieldConfiguration.Arguments[i]
p.configureArgument(upstreamFieldRef, ref, *fieldConfiguration, argumentConfiguration)
Expand Down
119 changes: 119 additions & 0 deletions pkg/testing/federationtesting/accounts/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 29 additions & 10 deletions pkg/testing/federationtesting/accounts/graph/histories.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,41 @@ import (
var histories = []model.History{
&model.Purchase{
Product: &model.Product{Upc: "top-1"},
Wallet: &model.WalletType1{
Currency: "USD",
Amount: 123,
SpecialField1: "some special value 1",
},
Wallet: walletOne,
},
&model.Sale{
Product: &model.Product{Upc: "top-2"},
Rating: 5,
},
&model.Purchase{
Product: &model.Product{Upc: "top-3"},
Wallet: &model.WalletType2{
Currency: "USD",
Amount: 123,
SpecialField2: "some special value 2",
},
Wallet: walletTwo,
},
}

var allHistories = []model.History{
&model.Purchase{
Product: &model.Product{Upc: "top-1"},
Wallet: walletOne,
},
&model.Sale{
Product: &model.Product{Upc: "top-1"},
Rating: 1,
},
&model.Purchase{
Product: &model.Product{Upc: "top-2"},
Wallet: walletTwo,
},
&model.Sale{
Product: &model.Product{Upc: "top-2"},
Rating: 2,
},
&model.Purchase{
Product: &model.Product{Upc: "top-3"},
Wallet: walletTwo,
},
&model.Sale{
Product: &model.Product{Upc: "top-3"},
Rating: 3,
},
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extend type Query {
me: User
histories: [History]
}

type User @key(fields: "id") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (r *queryResolver) Me(ctx context.Context) (*model.User, error) {
}, nil
}

// Histories is the resolver for the histories field.
func (r *queryResolver) Histories(ctx context.Context) ([]model.History, error) {
return allHistories, nil
}

// Query returns generated.QueryResolver implementation.
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }

Expand Down
15 changes: 15 additions & 0 deletions pkg/testing/federationtesting/accounts/graph/wallets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package graph

import "github.com/wundergraph/graphql-go-tools/pkg/testing/federationtesting/accounts/graph/model"

var walletOne = &model.WalletType1{
Currency: "USD",
Amount: 123,
SpecialField1: "some special value 1",
}

var walletTwo = &model.WalletType2{
Currency: "USD",
Amount: 123,
SpecialField2: "some special value 2",
}
Loading

0 comments on commit b0e183c

Please sign in to comment.