graphene-python

Django Graphene, Passing JSON or dict data as input for Mutation

人走茶凉 提交于 2019-12-08 01:37:04
问题 I have the following situation: I have a User, each user has a Inventory. I'm struggling to declare the user's inventory in the Mutation "CreateUser". Here is the following mutation for creating the user: mutation Create{ addUser(UserData:{name:"Shibunika",age:21} } I'm trying to declare the user's inventory in this mutation, I expected something like mutation Create{ addUser(UserData:{name:"Shibunika",age:21,inventory:{'item1':45,'item2':25} }s these number are the quantity of each item. How

Django Graphene, Passing JSON or dict data as input for Mutation

泪湿孤枕 提交于 2019-12-06 07:37:09
I have the following situation: I have a User, each user has a Inventory. I'm struggling to declare the user's inventory in the Mutation "CreateUser". Here is the following mutation for creating the user: mutation Create{ addUser(UserData:{name:"Shibunika",age:21} } I'm trying to declare the user's inventory in this mutation, I expected something like mutation Create{ addUser(UserData:{name:"Shibunika",age:21,inventory:{'item1':45,'item2':25} }s these number are the quantity of each item. How do I define these inputs in graphene? Would you gently show me a schema for this? You can create a

How can I upload and download files with graphene-django?

允我心安 提交于 2019-12-05 02:45:11
问题 I'm currently using graphene-django v2.0 and I've absolutely no clue of how can I upload and download files like images, does anyone have an example of a query where you can download an Image and a mutation where you can upload one? 回答1: UPLOADS You don't need to invent your own frontend code to add a file upload to a mutation -- there are existing packages that do this already. For example, apollo-upload-client if you are using Apollo. To receive an uploaded file on the backend, the files

How to configure Graphene-Django to work with persisted queries?

ぃ、小莉子 提交于 2019-12-05 02:37:01
问题 It looks like my company is going to move forward with Persisted Queries from the Apollo Client, as is discussed here: https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5 In this article there is mention that something needs to be done to the Middleware on the server. I have been unable to find any information as to what needs to be changed with Graphene-Django. Can anyone provide any advice? Robert 回答1: Persisted queries are not a part of the GraphQL

Graphene-Python: automatic schema generation from Django model

孤街浪徒 提交于 2019-12-03 20:08:14
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) class AutoSchemaMeta(type): def __new__(meta, clsname, superclasses, attributedict): new_class = type

How to configure Graphene-Django to work with persisted queries?

狂风中的少年 提交于 2019-12-03 18:22:20
It looks like my company is going to move forward with Persisted Queries from the Apollo Client, as is discussed here: https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5 In this article there is mention that something needs to be done to the Middleware on the server. I have been unable to find any information as to what needs to be changed with Graphene-Django. Can anyone provide any advice? Robert Persisted queries are not a part of the GraphQL spec and, as such, can be implemented in a wide variety of ways. Here are a few examples of how you might want

How can I upload and download files with graphene-django?

早过忘川 提交于 2019-12-03 16:31:05
I'm currently using graphene-django v2.0 and I've absolutely no clue of how can I upload and download files like images, does anyone have an example of a query where you can download an Image and a mutation where you can upload one? UPLOADS You don't need to invent your own frontend code to add a file upload to a mutation -- there are existing packages that do this already. For example, apollo-upload-client if you are using Apollo. To receive an uploaded file on the backend, the files are going to be available in the dictionary request.FILES . So any mutation handling a file upload needs to

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

两盒软妹~` 提交于 2019-12-03 12:45:45
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 user? EDIT: This is in the GraphQL API context. I am using Graphene. I'd like to see a scalable solution

mongoengine connection and multiple databases

我是研究僧i 提交于 2019-12-02 10:09: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 MongoengineObjectType from mongoengine.connection import disconnect class UserModel(Document): meta = {"collection": "users

Graphene Django “Must provide query string”

社会主义新天地 提交于 2019-12-01 03:13:06
问题 I have setup a Graphene server using Django. When I run my queries through GraphiQL (the web client), everything works fine. However, when I run from anywhere else, I get the error: "Must provide query string." I did some troubleshooting. GraphiQL sends POST data to the GraphQL server with Content-Type: application/json . Here is the body of the request that I copied from Chrome network tab for GraphiQL: {"query":"query PartnersQuery {\n partners{\n name\n url\n logo\n }\n}","variables":"null