ChilliCream / ChilliCream/graphql-platform

Error in variable coercion when using custom filter in query

Open
#7,024 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Product

Hot Chocolate

Version

13.9.0

Link to minimal reproduction

https://github.com/Mephistofeles/HotChocolateReproduction

Steps to reproduce

I've included minimal reproduction.
When I run query like:

query {
  machines(where: { locks: { any: true } }) {
    id
  }
}

It runs just fine, but when I create a variable for where, like:

query ($filter: MachineFilterInput) {
  machines(where: $filter) {
    id
  }
}

and use it with variables:

{
  "filter": {
    "locks": {
      "any": true
    }
  }
}

I'm getting error HC0016: Variable filter got an invalid value.
which when I debug probably comes from trying to convert "locks" to IEnumerable in HotChocolate.Utilities.DictionaryToObjectConverter.VisitObject (in call to Activator.CreateInstance(context.ClrType)) which failes, because of course IEnumerable is an interface and results in "System.MissingMethodException: 'Cannot create an instance of an interface.'"

What is expected?

Query should run the same whether I use variables or not

What is actually happening?

Query fails when I use variable for a filter input

Relevant log output

No response

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 linked minimal reproduction and compare the inline filter query with the variable-based query. Read HotChocolate.Utilities.DictionaryToObjectConverter.VisitObject, especially the Activator.CreateInstance path mentioned in the report. Done means the variable-based filter query runs successfully and behaves like the equivalent inline query.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.