Skip to content

Reworks of relationship between Nodes/Objects, Connections and Edges - #288

Closed
Globegitter wants to merge 6 commits into
graphql-python:masterfrom
Globegitter:edge-for-type-2
Closed

Globegitter wants to merge 6 commits into
graphql-python:masterfrom
Globegitter:edge-for-type-2

Conversation

@Globegitter

@Globegitter Globegitter commented Sep 14, 2016 •

Copy link
Copy Markdown

…Edges.

I like a lot of the stuff that is happening on 1.0 :). After having looked more into how the relationship of connections to object types has been reworked I think there is a more accurate way of modeling their relationship.

To my understanding a Node or an ObjectType can belong to many Connections. A Connection has only one Edge (where-as an Edge can belong to many Connection) and an Edge has only one Node/ObjectType (where-as again a Node/ObjectType can belong to many Edges).

This should allow for any of these use-cases by removing NodeType.Connection, since it seems to me a Node should not now anything about a Connection. Furthermore this also leaves out a normal ObjectType (which can be used for a Connection).

Further I added a Connection.for_type(GqlType) so we can get the automatically created ConnectionType. This uses a thread-safe caching library based on the python 3 lru_cache api, I assume the memoize might have been part of the multi-threading issues. If we don't want to use memoizing at all the only other ways I can see are:

  • somehow getting the auto-created connection from the schema's TypeMap
  • storing the auto-created connection on a dict on the ObjectType/Node and then providing a function to retrieve this ala get_auto_generated_connection_from_type(GqlType, 'ConnectionName') but that kind of seems a bit sucky.
  • somehow getting it from the ConnectionField which is responsible for auto-creating the connection
  • disabling auto-creation from Connections completely (i.e. disallowing creating a ConnectionField with aNode/ObjectType) and just making it easy to create your ownConnectionby providingAbstractTypesand maybeConnection.for_typefunction that, which then creates the connection that is used for theConnectionField`

Having thought about this a bit more, I am actually quite in favor of the last option, which would only require minor changes to this PR.

Anyway, I know this is a lot of text and not sure if that is all clear, but there should be tests for all changes, which might make it easier to understand. Let me know what you think @syrusakbary.

Btw, apart from the rework this also includes the fixes from #253 and allows for a resolver to return a Connection directly.

@Globegitter Globegitter changed the title Minor reworks of relationship between Nodes/Objects, Connections and … Reworks of relationship between Nodes/Objects, Connections and Edges Sep 15, 2016
@coveralls

coveralls commented Sep 15, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.3%) to 91.649% when pulling 7137a59 on Globegitter:edge-for-type-2 into 84c8711 on graphql-python:master.

@Globegitter

Copy link
Copy Markdown
Author

Ok, I am also seeing that fastcache has some issues running on pypy. I could investigate that or switching to a thread-safe memoize, but I am leaning more and more towards ConnectionField only taking a Connection and putting the responsibility to the user rather than the framework trying to be a bit too clever.

@coveralls

coveralls commented Sep 16, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 91.57% when pulling ebcc1f0 on Globegitter:edge-for-type-2 into 84c8711 on graphql-python:master.

@Globegitter

Copy link
Copy Markdown
Author

I now implemented what I proposed - removing the 'magic' auto generation of Connections in favour of declarative genaration of Connections, which should remove any issues of caching as well as tying any Connections to a Node but also allowing ObjectTypes to be used for Connections as specified in the Relay spec.

@Globegitter

Copy link
Copy Markdown
Author

Can be closed in favour of #347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants