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

Nested @requires generates incorrectly in generated federation file #1704

Closed
CFitzgerald212 opened this issue Nov 11, 2021 · 2 comments · Fixed by #1706
Closed

Nested @requires generates incorrectly in generated federation file #1704

CFitzgerald212 opened this issue Nov 11, 2021 · 2 comments · Fixed by #1706

Comments

@CFitzgerald212
Copy link

CFitzgerald212 commented Nov 11, 2021

What happened?

I'm using the recently implemented nested @requires directives to try to pass through an id of a subtype to a field extension, and the generated file is not able to correctly unmarshall the nested id field, resulting in a null id being passed through.

Schema

extend type User @key(fields:"id"){
  id: ID! @external
  name: String!
  subType: SubType!
  extension: String @requires(fields:"subType {id }")
}

extend type SubType @key(fields:"id"){
  id: ID! @external
}

Generated federation output

case "User":
	id0, err := ec.unmarshalNID2string(ctx, rep["id"])
	if err != nil {
		return errors.New(fmt.Sprintf("Field %s undefined in schema.", "id"))
	}

	entity, err := ec.resolvers.Entity().FindUserByID(ctx,
		id0)
	if err != nil {
		return err
	}

	entity.SubType.ID, err = ec.unmarshalNID2string(ctx, rep["subTypeID"])
	if err != nil {
		return err
	}

	list[i] = entity
	return nil

Expected generated output

case "User":
	id0, err := ec.unmarshalNID2string(ctx, rep["id"])
	if err != nil {
		return errors.New(fmt.Sprintf("Field %s undefined in schema.", "id"))
	}

	entity, err := ec.resolvers.Entity().FindUserByID(ctx,
		id0)
	if err != nil {
		return err
	}

	entity.SubType.ID, err = ec.unmarshalNID2string(ctx, rep["subType"].(map[string]interface{})["id"])
	if err != nil {
		return err
	}

	list[i] = entity
	return nil

What this does

When resolving User.extension, subType.ID = "null"

versions

@CFitzgerald212 CFitzgerald212 changed the title Nested @requires generates poorly in generated federation file Nested @requires generates incorrectly in generated federation file Nov 11, 2021
@carldunham
Copy link
Contributor

Not sure if this helps, but you may try marking subType with @external

carldunham pushed a commit to carldunham/gqlgen that referenced this issue Nov 11, 2021
@carldunham
Copy link
Contributor

@CFitzgerald212 sorry about that. Just saw this myself, should have a tested fix soon.

carldunham pushed a commit to carldunham/gqlgen that referenced this issue Nov 13, 2021
carldunham pushed a commit to carldunham/gqlgen that referenced this issue Nov 14, 2021
entity resolver tests for nested @requires fields
StevenACoffman pushed a commit that referenced this issue Nov 18, 2021
entity resolver tests for nested @requires fields
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

Successfully merging a pull request may close this issue.

2 participants