{"action":"created","issue":{"url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/44","repository_url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby","labels_url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/44/comments","events_url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/44/events","html_url":"https://github.com/rmosolgo/graphql-relay-ruby/issues/44","id":154377366,"number":44,"title":"Any way to make re-usable connections?","user":{"login":"davidcelis","id":36873,"avatar_url":"https://avatars.githubusercontent.com/u/36873?v=3","gravatar_id":"","url":"https://api.github.com/users/davidcelis","html_url":"https://github.com/davidcelis","followers_url":"https://api.github.com/users/davidcelis/followers","following_url":"https://api.github.com/users/davidcelis/following{/other_user}","gists_url":"https://api.github.com/users/davidcelis/gists{/gist_id}","starred_url":"https://api.github.com/users/davidcelis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidcelis/subscriptions","organizations_url":"https://api.github.com/users/davidcelis/orgs","repos_url":"https://api.github.com/users/davidcelis/repos","events_url":"https://api.github.com/users/davidcelis/events{/privacy}","received_events_url":"https://api.github.com/users/davidcelis/received_events","type":"User","site_admin":true},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-12T01:22:30Z","updated_at":"2016-05-12T18:03:47Z","closed_at":null,"body":"I'm working on a Graph API where three or four types will have a connection to one other type, and each connection will pretty much be exactly the same. Is there a good way of constructing a reusable connection that can be included in several types? Looking through the code and the DSL, I can't really determine if there's a way to, like a field, create a connection object that can be placed on multiple object types. Thanks in advance!"},"comment":{"url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/comments/218837714","html_url":"https://github.com/rmosolgo/graphql-relay-ruby/issues/44#issuecomment-218837714","issue_url":"https://api.github.com/repos/rmosolgo/graphql-relay-ruby/issues/44","id":218837714,"user":{"login":"rmosolgo","id":2231765,"avatar_url":"https://avatars.githubusercontent.com/u/2231765?v=3","gravatar_id":"","url":"https://api.github.com/users/rmosolgo","html_url":"https://github.com/rmosolgo","followers_url":"https://api.github.com/users/rmosolgo/followers","following_url":"https://api.github.com/users/rmosolgo/following{/other_user}","gists_url":"https://api.github.com/users/rmosolgo/gists{/gist_id}","starred_url":"https://api.github.com/users/rmosolgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmosolgo/subscriptions","organizations_url":"https://api.github.com/users/rmosolgo/orgs","repos_url":"https://api.github.com/users/rmosolgo/repos","events_url":"https://api.github.com/users/rmosolgo/events{/privacy}","received_events_url":"https://api.github.com/users/rmosolgo/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T18:03:47Z","updated_at":"2016-05-12T18:03:47Z","body":"Oh, now I think I understand! Thanks for clarifying.\r\n\r\n> only HerbType?\r\n\r\nYes, only HerbType. \r\n\r\nThe configuration is applied to the underlying GraphQL::Field,  so to share that code, you have a couple of options. \r\n\r\n1. __Use plain Ruby.__ Define a method which applies the field definition and call it during configuration, for example: \r\n\r\n   ```ruby \r\n   module LeavesConnection\r\n    # Put the configuration inside this method: \r\n    def self.create(definition)\r\n      definition.connection(:leaves, LeafType.connection_type) do \r\n        argument :alive, types.Boolean \r\n        resolve -> { ... } \r\n      end \r\n    end \r\n  end \r\n\r\n  ShrubType = GraphQL::ObjectType.define do \r\n    # Use the config helper during configuration:\r\n    LeavesConnection.create(self) # pass the definition into that object \r\n  end \r\n  ``` \r\n\r\n   It's a bit weird because, within the `define { }` block, `self` is a configuration object. So you must pass that object into the method and call helpers on that config object (`config.connection`, `config.types`)   \r\n\r\n   \r\n2. __Use an Interface.__ If you define the field on the interface, it will be \"inherited\" by the implementing types. For example: \r\n\r\n  ```ruby \r\n  LeafyInterface = GraphQL::InterfaceType.define do \r\n    connection :leaves, LeafType.connection_type do \r\n      # ... custom config  \r\n     end \r\n  end \r\n\r\n  HerbType = GraphQL::ObjectType.define do \r\n    interfaces [LeafyInterface]\r\n  end \r\n  ```\r\n\r\n  Now, HerbType gets the complex field definition from LeafyInterface.\r\n\r\n\r\nDoes that sound more like what you're looking for?"}}