walmartlabs / lacinia

GraphQL implementation in pure Clojure
http://lacinia.readthedocs.io/en/latest/
Other
1.82k stars 163 forks source link

Infinite loops in query #321

Closed xiongtx closed 3 years ago

xiongtx commented 4 years ago

I'm wondering if figuring out infinite loops should be a concern of Lacinia's. It seems so to me, given that it's a kind of query error.

Here's an example using the GitHub API:

{
  repository(name: "eros", owner: "xiongtx") {
    ...RepoFields
  }
}

fragment RepoFields on Repository {
  assignableUsers(first: 5) {
    edges {
      node {
        ...UserFields
      }
    }
  }
}

fragment UserFields on User {
  repositories(first: 5) {
    edges {
      node {
        ...RepoFields
      }
    }
  }
}

GitHub responds w/:

{
  "errors": [
    {
      "path": [
        "fragment RepoFields"
      ],
      "extensions": {
        "code": "infiniteLoop",
        "fragmentName": "RepoFields"
      },
      "locations": [
        {
          "line": 7,
          "column": 1
        }
      ],
      "message": "Fragment RepoFields contains an infinite loop"
    },
    {
      "path": [
        "fragment UserFields"
      ],
      "extensions": {
        "code": "infiniteLoop",
        "fragmentName": "UserFields"
      },
      "locations": [
        {
          "line": 17,
          "column": 1
        }
      ],
      "message": "Fragment UserFields contains an infinite loop"
    }
  ]
}
hlship commented 3 years ago

This is mentioned in the spec: http://spec.graphql.org/June2018/#sec-Fragment-spreads-must-not-form-cycles