graphene-python

Graphene-Django Filenaming Conventions

无人久伴 提交于 2020-01-07 04:40:11
问题 I'm rebuilding a former Django REST API project as a GraphQL one. I now have queries & mutations working properly. Most of my learning came from looking at existing Graphene-Django & Graphene-Python code samples. There seem to be a lot of inconsistencies amongst them. In some it was suggested that the GraphQL queries should be placed in schema.py whereas the mutations should be placed in mutation.py . What I'm thinking makes more sense is to instead have these two files hold their respective

Django graphene relay restricting queries to objects owned the user

扶醉桌前 提交于 2019-12-25 00:27:24
问题 I am doing the graphene tutorial on filtering with relay from: http://docs.graphene-python.org/projects/django/en/latest/filtering/ where the user is restricted to query objects that they previously created. I am using graphene 2, django 2, and django-filter 1.11. class AnimalFilter(django_filters.FilterSet): # Do case-insensitive lookups on 'name' name = django_filters.CharFilter(lookup_expr=['iexact']) #changed this to work class Meta: model = Animal fields = ['name', 'genus', 'is

Combine DjangoObjectType and ObjectType

怎甘沉沦 提交于 2019-12-24 09:08:50
问题 I have a simple django model with a calculated property field clicks . The model looks like this: class Link(models.Model): url = models.URLField() @property def clicks(self): """ Property does some calculations and returns a list of dictionaries: """ # removed calculation for simplicity return [{'dt': 1, 'clicks': 100}, {'dt': 2, 'clicks': 201}] I want to make this model accesible in my graphql endpoint. So I created the following Types and Query: class Stats(graphene.ObjectType): clicks =

Testing Graphene-Django

断了今生、忘了曾经 提交于 2019-12-23 04:37:07
问题 Currently I am investigating using graphene to build my Web server API. I have been using Django-Rest-Framework for quite a while and want to try something different. I have figured out how to wire it up with my existing project and I can test the query from Graphiql UI, by typing something like { industry(id:10) { name description } } Now, I want to have the new API covered by Unit/integration tests. And here the problem starts. All the documentation/post I am checking on testing query

mongoengine connection and multiple databases

这一生的挚爱 提交于 2019-12-19 10:10:12
问题 I have 2 databases I want to query from, but I only get results from one. I'm using mongoengine with python and graphene (it's my first time). I've exhausted my search and I don't understand how I can resolve this issue. Here is my code: import graphene from mongoengine import Document, connect from mongoengine.context_managers import switch_collection from mongoengine.fields import ( StringField, UUIDField, IntField, FloatField, BooleanField, ) from graphene_mongo import

GraphQL queries in Django returning None

删除回忆录丶 提交于 2019-12-12 16:17:50
问题 Hi guys, so i'm trying to use graphQL queries in django. Basically i have two apps, my 'api' app which contains everything i need to make the queries and another one called 'frontend' from which i call the api to use these queries. I can use the GraphQL view to type queries in it and it works perfectly, but whenever i try to make the query, i get this : "OrderedDict([('users', None)])" Result of my query in the GraphQl view And for the code : In 'api' my schema.py : import graphene import

How to limit field access on a model based on user type on Graphene/Django?

南笙酒味 提交于 2019-12-12 08:02:30
问题 Let's say I have a model: class Employee(models.Model): first_name = models.CharField(max_length=40) last_name = models.CharField(max_length=60) salary = models.DecimalField(decimal_places=2) I want anyone to be able to access first_name and last_name but only want certain users to be able to read salary because this is confidential data. And then I want to restrict write/update for salary to an even different kind of user. How do I restrict field read/write/update depending on the request

Is there a way to get graphene to work with django GenericRelation field?

放肆的年华 提交于 2019-12-11 19:11:59
问题 I have some django model generic relation fields that I want to appear in graphql queries. Does graphene support Generic types? class Attachment(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') file = models.FileField(upload_to=user_directory_path) class Aparto(models.Model):

graphene graphql dictionary as a type

烈酒焚心 提交于 2019-12-08 16:41:38
问题 I'm a newbie for the graphene and I'm trying to map the following structure into a Object Type and having no success at all { "details": { "12345": { "txt1": "9", "txt2": "0" }, "76788": { "txt1": "6", "txt2": "7" } } } Any guidance is highly appreciated Thanks 回答1: It is unclear what you are trying to accomplish, but (as far as I know) you should not have any arbitrary key/value names when defining a GraphQL schema. If you want to define a dictionary, it has to be be explicit. This means

Graphene Django without Django Model?

牧云@^-^@ 提交于 2019-12-08 04:50:05
问题 I've successfully used Graphene-Django to successfully build several GraphQL calls. In all of those cases I populated, in whole or in part, a Django model and then returned the records I populated. Now I have a situation where I'd like to return some data that I don't wish to store in the Django model. Is this possible to do with Graphene? Robert 回答1: Robert_LY answered his own question perfectly in the comments, I'd just like to expand his solution. My database-less model WordForm is