Skip to content

Unable to render schema with recursive type that requires oneOf directive #2631

Description

@annad-at-tapad

Minimally reproduced in this Scastie (which is modified from @ghostdogpr 's Scastie in our chat in Discord around this topic to account for the rules required for @oneOf: (1) the leaf case class must contain exactly 1 non-nullable field, (2) the field names in the leaf cases must be unique, and (3) any objects used in the leaf cases must have a Schema and an ArgBuilder).

Just in case there's some issue with accessing the Scastie content, I'm leaving the code snippet here as well:

import caliban.schema.Annotations.GQLOneOfInput
import caliban.schema.{ArgBuilder, Schema}

//@GQLOneOfInput
sealed trait Clause derives Schema.SemiAuto, ArgBuilder

case class SimpleClause(col: String) extends Clause derives Schema.SemiAuto, ArgBuilder
case class And (andClauses: Seq[Clause]) extends Clause derives Schema.SemiAuto, ArgBuilder
case class Or (orClauses: Seq[Clause]) extends Clause derives Schema.SemiAuto, ArgBuilder

case class Args(clause: Clause) derives Schema.SemiAuto, ArgBuilder
case class Query(test: Args => Int) derives Schema.SemiAuto


println(caliban.render[Query])

If I commented out the @GQLOneOfInput directive, the schema is rendered successfully as:

union Clause = And | Or | SimpleClause

type And {
  andClauses: [Clause!]!
}

type Or {
  orClauses: [Clause!]!
}

type Query {
  test(clause: Clause!): Int!
}

type SimpleClause {
  col: String!
}

However, with the directive, the code does not terminate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverIssue related to caliban server

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions