ChilliCream / ChilliCream/graphql-platform
IObjectFieldDescriptor.Authorize ambiguity
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When passing a single role param into the Authorize extension it selects a policy instead, but adding a 2nd string param will then select the role variation. This can lead to some confusing overload usage.
I think the optional param on the policy should be removed or params remove from the role variation so that its clear which overload is selected.
{
public static IObjectFieldDescriptor Authorize(this IObjectFieldDescriptor descriptor, string policy, ApplyPolicy apply = ApplyPolicy.BeforeResolver);
public static IObjectFieldDescriptor Authorize(this IObjectFieldDescriptor descriptor, params string[] roles);
}
Steps to reproduce
public class UserType : ObjectType<User>
{
protected override void Configure(IObjectTypeDescriptor<User> descriptor)
{
base.Configure(descriptor);
descriptor.Authorize();
descriptor.Field(t => t.Password).Authorize("Admin");
}
}
Due to params string[] roles and string policy having a optional param, .NET matches the incorrect signature (unless you pass more than one param in).
My suggestion is to remove the optional param or remove params off the role variation.
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.9.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating AuthorizeObjectFieldDescriptorExtensions and reviewing the two Authorize overloads shown in the issue. Reproduce the UserType example with a single role, then verify the overload behavior for zero, one, and multiple string arguments. Done means the intended role and policy calls are unambiguous, with coverage for the affected cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, authorization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100