{"action":"created","issue":{"url":"https://api.github.com/repos/graphql-python/graphene/issues/522","repository_url":"https://api.github.com/repos/graphql-python/graphene","labels_url":"https://api.github.com/repos/graphql-python/graphene/issues/522/labels{/name}","comments_url":"https://api.github.com/repos/graphql-python/graphene/issues/522/comments","events_url":"https://api.github.com/repos/graphql-python/graphene/issues/522/events","html_url":"https://github.com/graphql-python/graphene/issues/522","id":249338952,"number":522,"title":"Circular import question","user":{"login":"IgorBMSTU","id":14938720,"avatar_url":"https://avatars2.githubusercontent.com/u/14938720?v=4","gravatar_id":"","url":"https://api.github.com/users/IgorBMSTU","html_url":"https://github.com/IgorBMSTU","followers_url":"https://api.github.com/users/IgorBMSTU/followers","following_url":"https://api.github.com/users/IgorBMSTU/following{/other_user}","gists_url":"https://api.github.com/users/IgorBMSTU/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorBMSTU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorBMSTU/subscriptions","organizations_url":"https://api.github.com/users/IgorBMSTU/orgs","repos_url":"https://api.github.com/users/IgorBMSTU/repos","events_url":"https://api.github.com/users/IgorBMSTU/events{/privacy}","received_events_url":"https://api.github.com/users/IgorBMSTU/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-08-10T13:03:10Z","updated_at":"2017-08-22T15:40:40Z","closed_at":null,"body":"In our project we have schema consisting of around 20 different classes and we want to divide it in different files instead of having only one. But while trying to do this, we encountered circular import problem. We have tried using advices given in https://github.com/graphql-python/graphene/issues/110 and https://github.com/graphql-python/graphene/issues/436 but couldn't solve the problem:\r\n\r\n```python\r\n# Basic example (we need to import Dictionary on language.py and Language in dictionary.py)\r\n# mymodule/language.py\r\nclass Language(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    dictionaries = graphene.List(Dictionary)\r\n    def resolve_dictionaries(self, args, context, info):\r\n        result = list()\r\n        for dictionary in db_list:\r\n            result.append(Dictionary(id=dictionary.id))\r\n        return result\r\n\r\n\r\n# mymodule/dictionary.py\r\nclass Dictionary(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    language = graphene.Field(Language)\r\n    def resolve_language(self, args, context, info):\r\n        language = db_object\r\n        return Language(id=language.id)\r\n\r\n# first example (working, but it violates pep8)\r\n# mymodule/language.py\r\nclass Language(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    dictionaries = graphene.List(lambda: Dictionary)\r\n    def resolve_dictionaries(self, args, context, info):\r\n        result = list()\r\n        for dictionary in db_list:\r\n            result.append(Dictionary(id=dictionary.id))\r\n        return result\r\nfrom .dictionary import Dictionary\r\n\r\n\r\n# mymodule/dictionary.py\r\nclass Dictionary(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    language = graphene.Field(lambda: Language)\r\n    def resolve_language(self, args, context, info):\r\n        language = db_object\r\n        return Language(id=language.id)\r\nfrom .language import Language\r\n\r\n# second example (Dictionary(id=dictionary.id) and Language(id=language.id) \r\n# gives TypeError: import_string() got an unexpected keyword argument 'id')\r\n# mymodule/language.py\r\nDictionary = lazy_import('mymodule.dictionary.Dictionary')\r\nclass Language(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    dictionaries = graphene.List(Dictionary)\r\n    def resolve_dictionaries(self, args, context, info):\r\n        result = list()\r\n        for dictionary in db_list:\r\n            result.append(Dictionary(id=dictionary.id))\r\n        return result\r\n\r\n\r\n# mymodule/dictionary.py\r\nDictionary = lazy_import('mymodule.language.Language')\r\nclass Dictionary(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    language = graphene.Field(Language)\r\n    def resolve_language(self, args, context, info):\r\n        language = db_object\r\n        return Language(id=language.id)\r\n\r\n```\r\nHow can we solve this problem without violating pep8? Thanks in advance"},"comment":{"url":"https://api.github.com/repos/graphql-python/graphene/issues/comments/324066522","html_url":"https://github.com/graphql-python/graphene/issues/522#issuecomment-324066522","issue_url":"https://api.github.com/repos/graphql-python/graphene/issues/522","id":324066522,"user":{"login":"totaki","id":6254062,"avatar_url":"https://avatars1.githubusercontent.com/u/6254062?v=4","gravatar_id":"","url":"https://api.github.com/users/totaki","html_url":"https://github.com/totaki","followers_url":"https://api.github.com/users/totaki/followers","following_url":"https://api.github.com/users/totaki/following{/other_user}","gists_url":"https://api.github.com/users/totaki/gists{/gist_id}","starred_url":"https://api.github.com/users/totaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/totaki/subscriptions","organizations_url":"https://api.github.com/users/totaki/orgs","repos_url":"https://api.github.com/users/totaki/repos","events_url":"https://api.github.com/users/totaki/events{/privacy}","received_events_url":"https://api.github.com/users/totaki/received_events","type":"User","site_admin":false},"created_at":"2017-08-22T15:40:40Z","updated_at":"2017-08-22T15:40:40Z","body":"My solve problem, something like this\r\n**iteration.py**\r\n```python\r\nclass IterationObject(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    tasks = graphene.List(TaskObject)\r\n```\r\n\r\n**tasks.py**\r\n```python\r\nclass TaskObject(graphene.ObjectType):\r\n    id = graphene.Int()\r\n    iteration = graphene.Field('iteration.IterationObject')\r\n\r\n    @property\r\n    def iteration_class(self):\r\n        return self._meta.fields['iteration'].type\r\n```"}}
{"actor":{"display_login":"totaki"}}