Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Validation for non-breakable chains of circular references in Input Objects #48

Merged
merged 3 commits into from Mar 2, 2020
Merged

Validation for non-breakable chains of circular references in Input Objects #48

merged 3 commits into from Mar 2, 2020

Conversation

nikola-mladenovic
Copy link

This PR adds a missing validation step for Input Objects which have non-breakable chains of circular references.

More details bellow:

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
        ...
      }
    }
  })
}

Copy link

@yanns yanns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx a lot for your contribution! ❤️
I left a minor suggestion

…e.scala

Co-Authored-By: Yann Simon <yann.simon.fr@gmail.com>
@yanns yanns merged commit f1a3290 into sangria-graphql-org:master Mar 2, 2020
@nikola-mladenovic nikola-mladenovic deleted the input-object-type-recursion branch March 2, 2020 13:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants