ChilliCream / ChilliCream/graphql-platform

Cost assuming two levels of recursion for circular references

Open
#9,548 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Version

16.0.rc.1.30

Link to minimal reproduction

See sample below

Steps to reproduce

See this minimal repo:

public static class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.AddGraphQL()
            .AddMutationType<Mutations>()
            .ModifyOptions(x => x.StrictValidation = false);

        var app = builder.Build();

        app.MapGraphQL();
        app.RunWithGraphQLCommands(args);
    }

    public class Mutations
    {
        public string SetField(Foo? input) => "Test";
    }

    public class  Foo
    {
        [Cost(1001)] // High cost to raise error
        public string Bar { get; set; } = "Test";

        [Cost(1002)] // High cost to raise error
        public Foo? Next { get; set; }
    }
}

For the mutation

mutation m($input: FooInput) {
  setField(input: $input)
}

with arguments

{ 
  "input": {
    "bar": "test"
   } 
}

this results in

{
  "errors": [
    {
      "message": "The maximum allowed field cost was exceeded.",
      "extensions": {
        "code": "HC0047",
        "fieldCost": 4007,
        "maxFieldCost": 1000
      }
    }
  ]
}
What is expected?

A cost of 0 (field) + 1001 for bar + 1002 for next + 1 for the arg = 2004.
The reported cost of 4007 suggests that two full recursion levels are being evaluated.
One might argue that this is not incorrect (and I could agree with that), since recursion is potentially infinite. However, I think assuming a single level of recursion is a better default than assuming two. Perhaps this should be configurable at all.

What is actually happening?

A cost of 4007 is emitted

Relevant log output

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction in Program.Main and the Mutations.SetField input type, then trace field-cost calculation for the circular Foo.Next reference. Compare the reported 4007 with the expected 2004 and determine whether a one-level default or configurable recursion limit is intended; done means the reproduction reports the agreed cost and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, graphql
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.