graphene-python

Order by query output column

杀马特。学长 韩版系。学妹 提交于 2020-08-24 03:47:06
问题 I'm using graphene with sqlalchemy and I have an output object that contains a computed field. The field is computed according to some input (query) parameter and more or less look like this (to simplify, lets consider I'm computing f(x)=ax+b where a and b are both columns in my Thing table): import models class Thing(SQLAlchemyObjectType): class Meta: model = models.Thing interfaces = (relay.Node, ) f = graphene.Field(graphene.Float) def resolve_f(self, info): return self.a * info.context['x

Graphene Django - Mutation with one to many relation foreign key

℡╲_俬逩灬. 提交于 2020-04-09 18:38:23
问题 I would like to know how to properly create mutation for creating this django model: class Company(models.Model): class Meta: db_table = 'companies' app_label = 'core' default_permissions = () name = models.CharField(unique=True, max_length=50, null=False) email = models.EmailField(unique=True, null=False) phone_number = models.CharField(max_length=13, null=True) address = models.TextField(max_length=100, null=False) crn = models.CharField(max_length=20, null=False) tax = models.CharField(max

Creating Dynamic Schema on Runtime Graphene

青春壹個敷衍的年華 提交于 2020-03-14 04:32:30
问题 I almost spent 3 days to find a way for creating a dynamic schema in python graphene. the only related result I could find is the below link: https://github.com/graphql-python/graphene/blob/master/graphene/types/dynamic.py But I couldn't find any documentation for it. The whole idea is to create a dynamic schema. I want to provide a GraphQL compatible API that makes users able to query my contents even if Models are not defined in the code. In other words, I want to create Models on the fly.

Creating Dynamic Schema on Runtime Graphene

好久不见. 提交于 2020-03-14 04:32:06
问题 I almost spent 3 days to find a way for creating a dynamic schema in python graphene. the only related result I could find is the below link: https://github.com/graphql-python/graphene/blob/master/graphene/types/dynamic.py But I couldn't find any documentation for it. The whole idea is to create a dynamic schema. I want to provide a GraphQL compatible API that makes users able to query my contents even if Models are not defined in the code. In other words, I want to create Models on the fly.

Exception raised but not caught by assertRaises

岁酱吖の 提交于 2020-01-26 05:01:14
问题 I'm trying to test that my authentication fails. The exception is raised but not caught by assertRaises . What am I missing here? def test_auth(self): from graphql_jwt.exceptions import PermissionDenied with self.assertRaises(PermissionDenied): response = self.client.execute(self.query) Traceback: Creating test database for alias 'default'... System check identified no issues (0 silenced). Traceback (most recent call last): File "/home/dan/game/venv/lib/python3.7/site-packages/promise/promise

Create mutations in GraphQL with a lot of use cases

笑着哭i 提交于 2020-01-24 23:07:06
问题 I'm a newbie in GraphQL and need some advice (best practice) in creating mutations in GraphQL (particular with graphene-python ). Let's suppose we have some Task and a User . Now I want to create Task mutation, that covers three cases: Create Task . Create Task and assign existing User to this Task . Create Task and assign newly created User to this Task . So, is this a good idea to implement this as a single QraphQL "entry point", or it's better to create another mutation for the third case

How to restrict anonymous users from GraphQL API endpoint?

北城以北 提交于 2020-01-21 20:10:29
问题 Django has two approaches. Regular DRF restricts user on Middleware level. So not logged in user doesn't reach anything. GraphQL, on contrary, uses "per method" approach. So middleware passes all the request and each method. But afterward method calls decorator. I want to implement 1st approach but for GraphQL. But in that case I need to open path for login mutation. How can I extract mutation name from payload? 回答1: If you want restrict a GraphQL API endpoint to Django logged in users, you

Graphene-Python: automatic schema generation from Django model

对着背影说爱祢 提交于 2020-01-12 10:15:55
问题 I am trying to generate a Graphene schema from a Django model. I am trying to do this by iterating through the apps then the models and then adding the appropriate attributes to the generated schema. This is the code: registry = {} def register(target_class): registry[target_class.__name__] = target_class def c2u(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() def s2p(name): s1 = re.sub("y$", "ie", name) return "{}s".format(s1)