RFC 3 / Accepted

Disallow non-breakable chains of circular references in Input Objects

Opened on
Closed on

At a glance

Project
GraphQL Spec
Identifier
#445
Stage
RFC 3 / Accepted
Champion
@spawnia
Updated
2020-03-24
Latest activity
Pull request closed on
Source

Pull request description

This was already discussed in Issue #189

Input Objects are allowed to reference other Input Objects. A circular reference occurs when an Input Object references itself either directly or through subordinated Input Objects.

Circular references are generally allowed, however they may not be defined as an unbroken chain of Non-Null fields. Such Input Objects are invalid, because there is no way to provide a legal value for them.

The following examples are allowed:

input Example {
  self: Example
  value: String
}

This is fine because a value for self may simply be omitted from the arguments.

input Example {
  self: [Example!]!
  value: String
}

This also works as self can just contain an empty list.

The following examples are invalid:

input Example {
  value: String
  self: Example!
}
input First {
  second: Second!
  value: String
}

input Second {
  first: First!
  value: String
}

The following example shows why no possible value can be provided:

{
  someField(input: {
    value: "val"
    # self is required
    self: {
      value: "nextval"
      # self is still required
      self: {
        # We would have to recurse down infinitely
        ...
      }
    }
  })
}

Timeline

March 2020

February 2020

November 2019

  • Discussed in GraphQL WG

    Review implementation complexity of Disallow non-breakable chains of circular references in Input Objects (10m, Benedikt)

    • Benedikt: So this one that was discussed in the last working group meeting. It clarifies a particular edge case, circular references of non-null input object types, which might render parts of your schema unusable. There are no such things as references in GraphQL, all the spec change is it points out that fact and disallows making such schemas. We decided last time to examine the complexity of such implementations because this is just clarifying one part of the spec the implementations don’t really need to change, they just need to validate against it.
    • One place has a cyclomatic complexity of 6.
    • Ivan: we have cycle detection in a couple places (it's not something that initial implementers have to worry about): in the fragments, ...
    • Ivan: I think Lee is going to add to the spec about not having cycles. Seems reasonable to rely on this.
    • Lee: I have to look into this. B - you said this is optional, you don't have to implement, so why bother? Either it should not be in the spec at all, or it should be a requirement that if you have a cycle in input types then your schema is not valid.
    • Benedikt: <>
    • Lee: I see, so it’s backwards compatible
    • Benedikt: Existing schemas never have to implement it - it's just one less static validation guarantee that they'll have
    • Ivan: it's not a breaking change.
    • Lee: right now your GraphQL server just wouldn't work properly currently
    • Howard: It’s basically advertising that you don’t test
    • Michael: it's not possible to use this over JSON/HTTP anyway - so adding it should not be a breaking change
    • [Someone] there are other serialization format [e.g. YAML] that allow cycles
    • Benedikt: Yeah, I found there are two basic assumptions, 1) GraphQL schemas must be queryable, they should used for querying and 2) GraphQL literals are first class - everything you can do in GraphQL should be expressible in pure GraphQL, features that work only when variables are used are not valid.
    • Benedikt: I think the spec text is at a pretty good point. Lee, could you take a look at it for me?
    • Lee:** [Action - Lee] **Review the spec text
    • Lee: No need to rush on this, I'll take it offline to look into the spec changes.
    Meeting notes · GraphQL WG · 2019-11-07

October 2019

June 2019

October 2018

May 2018