graphene upgrade from v2 to v3 breaks `to_global_id` node function
DrJfrost opened this issue · 1 comments
Note:` for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.
- What is the current behavior?
the following implementation of to_global_id
fails after upgrading graphene to v3
from graphene import (
Field,
String,
Int,
ObjectType,
relay,
ID,
List,
NonNull,
Date,
Boolean,
)
from graphene.relay.node import to_global_id
class SubmittedContent(ObjectType):
global_id = ID(description="The global ID of the submitted content.")
db_id = Int()
name = String(description="The name of the submitted content.")
type = String(description="The type of the submitted content.")
submitted_by = String(description="The name of the user who submitted the content.")
status = String(description="The status of the submitted content.")
def resolve_global_id(root, info):
if root.get("type") in [
DocumentTypes.FORM_RESULT.value,
DocumentTypes.SITE_DIARY.value,
DocumentTypes.DIGITAL_DOCKET.value,
DocumentTypes.TIMESHEET.value,
]:
doc_type = root.get("type")
if DocumentTypes(doc_type) == DocumentTypes.SITE_DIARY:
doc_type = "SiteDiary"
return to_global_id(root.get("type"), root["db_id"])
return None
this ends up in
cannot import name 'to_global_id' from 'graphene.relay.node'
-
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
a github repo, https://repl.it or similar. -
What is the expected behavior?
The
to_global_id
function should serialize the global id -
What is the motivation / use case for changing the behavior?
Many people uses the relay framework and plan to upgrade from v2 to v3, there is no documantation on this breaking changes -
Please tell us about your environment:
- Version: 2.16.0 --> 3.0.0
- Platform: python 3.9.5
-
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
As a work around changing the imports fixes the problem.
from graphql_relay import to_global_id
Hey, thanks for the report. I'm closing this, as this was one of the intended breaking changes between v2 and v3.