Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing package name for models in resolveManyEntities routine #2472

Closed
jdavisclark opened this issue Dec 14, 2022 · 1 comment
Closed

missing package name for models in resolveManyEntities routine #2472

jdavisclark opened this issue Dec 14, 2022 · 1 comment

Comments

@jdavisclark
Copy link

jdavisclark commented Dec 14, 2022

What happened?

If you utilize a config where autogenerated models and federation code are in different packages and @entityResolver(multi:true) is present on some of your federated types, the generated code re the _rep input slice in the resolveManyEntities routine is missing the package name for the input types.

What did you expect?

valid code

Minimal graphql.schema and models to reproduce

gqlgen.yml:

schema:
  - internal/graphql/schema/**/*.graphql

exec:
  filename: internal/graphql/generated/generated.go
  package: generated

federation:
  filename: internal/graphql/generated/federation.go
  package: generated
  version: 2

model:
  filename: internal/graphql/gqlmodels/gqlmodels.go
  package: gqlmodels

resolver:
  layout: follow-schema
  dir: internal/graphql/resolvers
  package: resolvers
  filename_template: "{name}.resolvers.go"

omit_slice_element_pointers: true

models:
  ID:
    model:
      - github.com/99designs/gqlgen/graphql.String
      - github.com/99designs/gqlgen/graphql.Int
      - github.com/99designs/gqlgen/graphql.ID

schema:

directive @entityResolver(multi: Boolean) on OBJECT

type Customer @key(fields: "id") @entityResolver(multi: true) {
    id: ID!
    name: String
}

diff required to fix autogenerated code:

From e623279096b8eeef99dfa757a202a0c6c001c164 Mon Sep 17 00:00:00 2001
From: jdavisclark
Date: Tue, 13 Dec 2022 16:49:51 -0600
Subject: [PATCH] manually fix gqlgen

---
 internal/graphql/generated/federation.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/internal/graphql/generated/federation.go b/internal/graphql/generated/federation.go
index d6b1399..5e70360 100644
--- a/internal/graphql/generated/federation.go
+++ b/internal/graphql/generated/federation.go
@@ -6,6 +6,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"github.com/yourOrg/yourRepo/internal/graphql/gqlmodels"
 	"strings"
 	"sync"
 
@@ -99,7 +100,7 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati
 		switch typeName {
 
 		case "Customer":
-			_reps := make([]*CustomerByIDsInput, len(reps))
+			_reps := make([]gqlmodels.CustomerByIDsInput, len(reps))
 
 			for i, rep := range reps {
 				id0, err := ec.unmarshalNID2string(ctx, rep["id"])
@@ -107,7 +108,7 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati
 					return errors.New(fmt.Sprintf("Field %s undefined in schema.", "id"))
 				}
 
-				_reps[i] = &CustomerByIDsInput{
+				_reps[i] = gqlmodels.CustomerByIDsInput{
 					ID: id0,
 				}
 			}
-- 
2.24.0

versions

  • go run github.com/99designs/gqlgen version?
    • v0.17.20
  • go version?
    • go version go1.16.15 darwin/amd64
@StevenACoffman
Copy link
Collaborator

Can you verify that #2594 resolves your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants