Node
Node interface for GraphQL types.
Subclasses must type the id field using NodeID
. It will be private to the
schema because it will be converted to a global ID and exposed as id: GlobalID!
The following methods can also be implemented:
resolve_id:
(Optional) Called to resolve the node’s id. Can be overriden to
customize how the id is retrieved (e.g. in case you don’t want
to define a NodeID
field)
resolve_nodes:
Called to retrieve an iterable of node given their ids
resolve_node:
(Optional) Called to retrieve a node given its id. If not defined
the default implementation will call .resolve_nodes
with that
single node id.
Example:
Methods:
-
resolve_id_attr
Signature:
-
resolve_id
Resolve the node id.
By default this will return
getattr(root, <id_attr>)
, whereis the field typed with NodeID
.You can override this method to provide a custom implementation.
Returns:
The resolved id (which is expected to be str)
Signature:
Parameters:
-
root:
The node to resolve.
- Type
-
Self
-
info:
The strawberry execution info resolve the type name from.
- Type
-
Info
-
-
resolve_typename
Signature:
Parameters:
-
root:
- Type
-
Self
-
info:
- Type
-
Info
-
-
resolve_nodes
Resolve a list of nodes.
This method should be defined by anyone implementing the
Node
interface.The nodes should be returned in the same order as the provided ids. Also, if
required
isTrue
, all ids must be resolved or an error should be raised. Ifrequired
isFalse
, missing nodes should be returned asNone
.Returns:
An iterable of resolved nodes.
Signature:
Parameters:
-
info:
The strawberry execution info resolve the type name from.
- Type
-
Info
-
node_ids:
List of node ids that should be returned.
- Type
-
Iterable[str]
-
required:
If
True
, allnode_ids
requested must exist. If they don’t, an error must be raised. IfFalse
, missing nodes should be returned asNone
. It only makes sense when passing a list ofnode_ids
, otherwise it will should ignored.- Type
-
bool
- Default
-
False
-
-
resolve_node
Resolve a node given its id.
This method is a convenience method that calls
resolve_nodes
for a single node id.Returns:
The resolved node or None if it was not found
Signature:
Parameters:
-
node_id:
The id of the node to be retrieved.
- Type
-
str
-
info:
The strawberry execution info resolve the type name from.
- Type
-
Info
-
required:
if the node is required or not to exist. If not, then None should be returned if it doesn’t exist. Otherwise an exception should be raised.
- Type
-
bool
- Default
-
False
-