-
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 (#405)
* Rename CustomInterface to AdditionalInterface The name `CustomInterface` is too similar with `CustomPageInterface` and the upcoming `CustomSnippetInterface` and their custom interfaces settings file. Better rename it to `AdditionalInterface` so there is less confusion. * Rename the custom interface settings file The settings file will contain an override for the default snippet interface, in addition to the default page interface, so we're renaming it up front here. * 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`. * Update changelog * Add contentType field on SnippetInterface * Test for no registered snippets * Create an instance each of both snippet types
- Loading branch information
Showing
19 changed files
with
337 additions
and
313 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
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
Oops, something went wrong.