Skip to content

Instantly share code, notes, and snippets.

@erebus1
Last active November 12, 2019 13:56
Show Gist options
  • Save erebus1/191afbe847d13cdc0c73c7b35dc38f1f to your computer and use it in GitHub Desktop.
Save erebus1/191afbe847d13cdc0c73c7b35dc38f1f to your computer and use it in GitHub Desktop.
import graphene
from graphene import ObjectType, Int, String
from graphene_federation import build_schema, key
from utils import file_loader # custom data loader
@key(fields='id')
class FileNode(ObjectType):
id = Int(required=True)
url = String(required=True)
def __resolve_reference(self, info, **kwargs):
if not info.context.user.is_authenticated:
return None
return file_loader.load(self.id)
class Query(ObjectType):
pass
schema = build_schema(Query, types=[FileNode])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment