Skip to content

Commit

Permalink
Run tests to reset federation testdata
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman committed Dec 15, 2024
1 parent fee5609 commit d6b38cf
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 263 deletions.
28 changes: 22 additions & 6 deletions _examples/federation/accounts/graph/federation.go

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

50 changes: 38 additions & 12 deletions _examples/federation/products/graph/federation.go

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

42 changes: 32 additions & 10 deletions _examples/federation/reviews/graph/federation.go

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

20 changes: 15 additions & 5 deletions plugin/federation/federation.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ func (ec *executionContext) resolveManyEntities(
{{- if .Resolvers }}

func entityResolverNameFor{{$entity.Name}}(ctx context.Context, rep EntityRepresentation) (string, error) {
// we collect errors because a later entity resolver may work fine
// when an entity has multiple keys
entityResolverErrs := []error{}
{{- range .Resolvers }}
for {
var (
Expand All @@ -310,12 +313,16 @@ func (ec *executionContext) resolveManyEntities(
{{- range $i, $field := .Field }}
val, ok = m["{{.}}"]
if !ok {
return "", fmt.Errorf("%w due to missing Key Field {{.}} for User", ErrTypeNotFound)
entityResolverErrs = append(entityResolverErrs,
fmt.Errorf("%w due to missing Key Field \"{{.}}\" for {{$entity.Name}}", ErrTypeNotFound))
break
}
{{- if (ne $i $keyField.Field.LastIndex ) }}
if m, ok = val.(map[string]interface{}); !ok {
// nested field value is not a map[string]interface
return "", fmt.Errorf("%w for {{$entity.Name}} due to nested Keyfield not being map value", ErrTypeNotFound)
// nested field value is not a map[string]interface so don't use it
entityResolverErrs = append(entityResolverErrs,
fmt.Errorf("%w due to nested Key Field \"{{.}}\" value not matching map[string]any for {{$entity.Name}}", ErrTypeNotFound))
break
}
{{- else}}
if allNull {
Expand All @@ -325,12 +332,15 @@ func (ec *executionContext) resolveManyEntities(
{{- end}}
{{- end }}
if allNull {
return "", fmt.Errorf("%w due to all null value KeyFields for User", ErrTypeNotFound)
entityResolverErrs = append(entityResolverErrs,
fmt.Errorf("%w due to all null value KeyFields for {{$entity.Name}}", ErrTypeNotFound))
break
}
return "{{.ResolverName}}", nil
}
{{- end }}
return "", fmt.Errorf("%w for {{$entity.Name}}", ErrTypeNotFound)
return "", fmt.Errorf("%w for {{$entity.Name}} due to %v", ErrTypeNotFound,
errors.Join(entityResolverErrs...).Error())
}
{{- end }}
{{- end }}
Expand Down
10 changes: 5 additions & 5 deletions plugin/federation/federation_entityresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ func TestEntityResolver(t *testing.T) {
Bar int `json:"bar"`
} `json:"_entities"`
}

eq := entityQuery([]string{
"WorldWithMultipleKeys {foo hello {name}}",
"WorldWithMultipleKeys {bar}",
})
err := c.Post(
entityQuery([]string{
"WorldWithMultipleKeys {foo hello {name}}",
"WorldWithMultipleKeys {bar}",
}),
eq,
&resp,
client.Var("representations", representations),
)
Expand Down
Loading

0 comments on commit d6b38cf

Please sign in to comment.