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

@requires does not work as expected for Apollo Federation #2619

Closed
mihirpmehta opened this issue Apr 20, 2023 · 3 comments
Closed

@requires does not work as expected for Apollo Federation #2619

mihirpmehta opened this issue Apr 20, 2023 · 3 comments

Comments

@mihirpmehta
Copy link

What happened?

When i entity in on subgraph which does have @requires from another subgraph entity, Resolvers does not generated where i can access the required attribute from another subgraph

What did you expect?

func (r *queryResolver) Screen(ctx context.Context, id string) (*model.GuideScreen, error) {
	return FindScreen(id)
}

this method should be generated with asset input

Minimal graphql.schema and models to reproduce

Subgraph1

type GuideScreen @key(fields: "id")  {
  id:ID!
  tile:Tile!
}

type Asset @key(fields: "channelID", resolvable: false) {
  channelID: ID!
  movie_title: String! @external
}

type Tile @key(fields: "id") {
  id: ID!
  title: String! @requires(fields: "asset { movie_title }")
  asset: Asset
}

Subgraph2


type Asset @key(fields: "channelID") {
  channelID:ID!
  movie_title: String!
}

versions

  • v0.17.29
  • go1.20.3?

In federation.go i can see

func (ec *executionContext) __resolve_entities(ctx context.Context, representations []map[string]interface{}) []fedruntime.Entity {
switch typeName {

.....

			case "findTileByID":
				id0, err := ec.unmarshalNID2string(ctx, rep["id"])
				if err != nil {
					return fmt.Errorf(`unmarshalling param 0 for findTileByID(): %w`, err)
				}
				entity, err := ec.resolvers.Entity().FindTileByID(ctx, id0)
				if err != nil {
					return fmt.Errorf(`resolving Entity "Tile": %w`, err)
				}

				entity.Asset.MovieTitle, err = ec.unmarshalNString2string(ctx, rep["asset"].(map[string]interface{})["movie_title"])
				if err != nil {
					return err
				}
				list[idx[i]] = entity
				return nil
			}

		}
		return fmt.Errorf("%w: %s", ErrUnknownType, typeName)

Thank you

@mihirpmehta
Copy link
Author

Update

Somehow router skips calling subgraph 2 before calling subgraph1 and throwing error


interface conversion: interface {} is nil, not map[string]interface {}

type Entity @key(fields: "id") {
  id: ID!
  independentString: String
  otherEntity: Other 
  dependentString: String @requires(fields: "OtherEntity { supplementaryString }")
}

type OtherEntity @key(fields: "id") {
  id: ID!
  supplementaryString: String @external
}

Subgraph2


type Other @key(fields: "id") {
  id: ID!
  supplementaryString: String
}

When we generate boilerplate and implement schema resolver and entity resolver for both subgraph. Somehow subgraph2 never gets called from router. and tries to fetch directly from Subgraph1

@DRodriguez88
Copy link

DRodriguez88 commented Feb 28, 2024

@mihirpmehta what was the solution here? I'm having the same issue.

gqlgen 0.17.43
go 1.22

@mihirpmehta
Copy link
Author

They have comeup with a solution
go mod edit -replace github.com/99designs/gqlgen=github.com/99designs/gqlgen@15cef76f18afec4c5352911360e33f4042500697

#2884 (comment) (I have not tried this yet)

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