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

Broken Fragment resolving #2538

Open
dispalt opened this issue Feb 5, 2025 · 6 comments
Open

Broken Fragment resolving #2538

dispalt opened this issue Feb 5, 2025 · 6 comments
Labels
bug Something isn't working server Issue related to caliban server

Comments

@dispalt
Copy link

dispalt commented Feb 5, 2025

I think it's related to this. #2491

Previously this used to work and now it doesn't, it will return only crux or crux2, starting with 2.9.1, I didn't test 2.9.0 I jumped from 2.8.1 to 2.9.1 and it broke. It's easy to reproduce on my production code, Ill see if I can work on a test case in the repo later today or tomorrow.

It seems to only show up after a certain amount of nesting.

fragment Foo on Bar {
  baz {
    crux {
      something
   }
}
}

fragment Burrito on Bar {
  baz {
    crux {
      somethingElse
    }
  }
}

query Q {
  ..Foo
  ..Burrito
}

Edited: Changed crux2 to crux

@ghostdogpr
Copy link
Owner

#2491 only modifies the validation (whether you get a validation error or not) so it shouldn't have any impact on execution. Maybe #2368 ? Could you check 2.9.0?

@dispalt
Copy link
Author

dispalt commented Feb 6, 2025

Sure, sorry for the delay!

@ghostdogpr ghostdogpr added bug Something isn't working server Issue related to caliban server labels Feb 11, 2025
@dispalt
Copy link
Author

dispalt commented Feb 13, 2025

2.9.0 seems to have the same issue., which suggests the change you highlighted might be the issue, ill try to publish local with it removed and see if it works

@kyri-petrou
Copy link
Collaborator

@dispalt I can't seem to be able to reproduce the issue. I tried adding this test but it's passing:

test("nested fragment selection on the same type") {
        case class A(valueA: String)
        case class B(valueB: String)
        case class Foo(a: A, b: B)
        case class Query(foo: Foo)

        implicit val schemaQuery: Schema[Any, Query] = Schema.gen

        val api = graphQL(RootResolver(Query(Foo(A("a"), B("b")))))

        val q = gqldoc("""
            fragment FragA on Query {
              foo {
                a {
                  valueA
                }
              }
            }

            fragment FragB on Query {
              foo {
                b {
                  valueB
                }
              }
            }

            query {
              ...FragA
              ...FragB
            }
            """)

        api.interpreterUnsafe.execute(q).map { res =>
          val d = res.data.toString
          assertTrue(d == """{"foo":{"a":{"valueA":"a"},"b":{"valueB":"b"}}}""")
        }
      }

Would you be able to provide a reproducer that fails the test above so I can look into it?

@dispalt
Copy link
Author

dispalt commented Feb 13, 2025

Try this

test("nested fragment selection on the same type") {
        import caliban.schema.Schema.auto._

        case class A(valueA: String, valueC: String)
        case class B(valueB: String)
        case class Foo(a: A, b: B)
        case class Query(foo: Foo)

        val api = graphQL(RootResolver(Query(Foo(A("a", "c"), B("b")))))

        val q = gqldoc("""
            fragment FragA on Query {
              foo {
                a {
                  valueA
                  valueC
                }
              }
            }

            fragment FragB on Query {
              foo {
                a {
                  valueA
                }
                b {
                  valueB
                }
              }
            }

            query {
              ...FragA
              ...FragB
            }
            """)

        api.interpreterUnsafe.execute(q).map { res =>
          val d = res.data.toString
          assertTrue(d == """{"foo":{"a":{"valueA":"a","valueC":"c"},"b":{"valueB":"b"}}}""")
        }
      }

returns

{"foo":{"a":{"valueA":"a","valueC":"c"},"a":{"valueA":"a"},"b":{"valueB":"b"}}}

@dispalt
Copy link
Author

dispalt commented Feb 13, 2025

yep this is exactly what I was seeing testing, thank you for the primer test case, @kyri-petrou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Issue related to caliban server
Projects
None yet
Development

No branches or pull requests

3 participants