Skip to content

It's not possible to project an ignored property #4192

@eliottrobson

Description

@eliottrobson

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using resolvers / extensions it is not possible to hide a field from the schema via .Ignore() and also simultaneously .Project() that field for use in an extension.

Steps to reproduce

Assume a model where we have a book type, this contains a "GoodreadsId" field that links to an ID on the good reads service and a resolver which uses their API to return extra data. Exposing this ID to the user isn't useful, but we need it to query the remote service.

Using .IsProjected() always adds to the query as expected.
Using .Ignore() hides the field from the schema as expected.
Using .Ignore() and .IsProjected() hides the field from the schema but does not add to the query.

public class BookType : ObjectType<Book>
{
    protected override void Configure(IObjectTypeDescriptor<Book> descriptor)
    {
        descriptor.Field(f => f.GoodreadsId)
            .Ignore()
            .IsProjected();
    } 
}

[ExtendObjectType(typeof(Book))]
public class BookExtensionsType
{
    public async Task<GoodreadsData> GetGoodreadsData([Parent] Book book)
    {
        // book.GoodreadsId is always null
    }
}

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

11.3.7

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions