Skip to content

Instantly share code, notes, and snippets.

View nidhinp's full-sized avatar

Nidhin Pushpakaran nidhinp

View GitHub Profile
import graphene
from .queries import AuthorType
from ..models import Author
class AuthorInput(graphene.InputObjectType):
id = graphene.ID()
name = graphene.String()
class Query(ObjectType):
authors = graphene.List(AuthorType)
# The field added for auther search with name
author_search = graphene.List(AuthorType, string=graphene.String())
def resolve_author_search(self, info, **kwargs):
string = kwargs.get("string", "")
return Author.objects.filter(name__icontains=string)
import graphene
from graphene_django.types import DjangoObjectType, ObjectType
from ..models import Author, Book
class AuthorType(DjangoObjectType):
class Meta:
model = Author
import graphene
from .queries import Query
from .mutations import Mutation
schema = graphene.Schema(query=Query, mutation=Mutation)
from graphene import ObjectType, Schema
from app.info.graphql.schema import Query as InfoQuery
from app.info.graphql.schema import Mutation as InfoMutation
class Query(InfoQuery, ObjectType):
# This class will inherit from multiple Queries
# as we begin to add more apps to our project
pass
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# libraries
from graphene_django.views import GraphQLView
from django.contrib import admin
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
urlpatterns = [
path('admin/', admin.site.urls),
path('graphql/', csrf_exempt(GraphQLView.as_view())),
]
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Meta:
def get_presigned_url():
s3 = boto3.client('s3')
bucket = "your-s3-bucket-name"
return s3.generate_presigned_post(
Bucket=bucket,
Key="media/screenshots/login.png",
Fields={"acl": "public-read", "Content-Type": "png"},
Conditions=[
{"acl": "public-read"},
print 'hello world'