-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace SnippetObjectType with SnippetInterface
Fixes #386 API clients could use a field on snippet objects to determine the type of snippet they are looking at. Therefore, we change the snippet type to an interface, similar to the page interface, so it can expose a new field called `snippetType`.
- Loading branch information
Showing
12 changed files
with
139 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,19 @@ | ||
import graphene | ||
|
||
from ..registry import registry | ||
|
||
|
||
class SnippetTypes: | ||
# SnippetObjectType class can only be created if | ||
# registry.snippets.types is non-empty, and should only be created | ||
# once (graphene complains if we register multiple type classes | ||
# with identical names) | ||
_SnippetObjectType = None | ||
|
||
@classmethod | ||
def get_object_type(cls): | ||
if cls._SnippetObjectType is None and registry.snippets: | ||
|
||
class SnippetObjectType(graphene.Union): | ||
class Meta: | ||
types = registry.snippets.types | ||
|
||
cls._SnippetObjectType = SnippetObjectType | ||
return cls._SnippetObjectType | ||
from .interfaces import get_snippet_interface | ||
|
||
|
||
def SnippetsQuery(): | ||
SnippetObjectType = SnippetTypes.get_object_type() | ||
|
||
if SnippetObjectType is not None: | ||
|
||
class Mixin: | ||
snippets = graphene.List(graphene.NonNull(SnippetObjectType), required=True) | ||
# Return all snippets. | ||
|
||
def resolve_snippets(self, info, **kwargs): | ||
snippet_objects = [] | ||
for snippet in registry.snippets: | ||
for object in snippet._meta.model.objects.all(): | ||
snippet_objects.append(object) | ||
|
||
return snippet_objects | ||
|
||
return Mixin | ||
class Mixin: | ||
snippets = graphene.List(graphene.NonNull(get_snippet_interface), required=True) | ||
|
||
else: | ||
def resolve_snippets(self, info, **kwargs): | ||
snippet_objects = [] | ||
for snippet in registry.snippets: | ||
for object in snippet._meta.model.objects.all(): | ||
snippet_objects.append(object) | ||
|
||
class Mixin: | ||
pass | ||
return snippet_objects | ||
|
||
return Mixin | ||
return Mixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters