Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm just starting out with graphene-django and GraphQL and can't figure out how to craft my mutation correctly.

Here's my current mutation request:

mutation createCustomer {
  createCustomer(input: {
    customerName: "John Smith",
    customerAddress: "1000 Airport Drive",
    customerCity: "1",
    customerState: "TX",
    customerZip: "75121",
    customerEmail: "me@me.com",
    customerCellPhone: "124567894",
    referredFrom: "g"
  }) {
    ok,
    customer{
      id,
      customerName,
      customerZip,
      customerAddress
    }
  }
}

Here's my CustomerInput schema:

input CustomerInput {
  id: ID
  customerName: String
  customerAddress: String
  customerCity: [LocationInput]
  customerState: String
  customerZip: String
  customerEmail: String
  customerCellPhone: String
  customerHomePhone: String
  referredFrom: String
}

LocationInput schema:

input LocationInput {
  id: ID
  locationCity: String
  locationState: String
  locationSalesTaxRate: Float
}

And the error I'm receiving:

{
  "errors": [
    {
      "message": "Argument "input" has invalid value {customerName: "John Smith", customerAddress: "1000 Airport Drive", customerCity: "1", customerState: "TX", customerZip: "75121", customerEmail: "me@me.com", customerCellPhone: "124567894", referredFrom: "g"}.
In field "customerCity": Expected "LocationInput", found not an object.",
      "locations": [
        {
          "line": 3,
          "column": 25
        }
      ]
    }
  ]
}

And finally, here is my models:

class Location(BaseModel, models.Model):
    location_city = models.CharField(max_length=100, blank=False, null=False, unique=True) 
    location_state = models.CharField(max_length=2, blank=False, null=False, default="TX")
    location_sales_tax_rate = models.DecimalField(max_digits=4, decimal_places=2, verbose_name="Sales Tax Rate (%)", blank=True, null=True)

class Customer(BaseModel, models.Model):
    """Customer model."""

    REFERRAL_CHOICES = (
        ('g', 'Google'),
        ('o', 'A friend'),
        ('f', 'Facebook'),
    )

    # templates = "workorders/customers/customer.html"
    customer_name = models.CharField(max_length=100, blank=False, null=False, help_text="John Doe", verbose_name="Name")
    customer_address = models.CharField(max_length=100, blank=False, null=False, help_text="1111 Airport Drive", verbose_name="Address")
    customer_city = models.ForeignKey('locations.Location', on_delete=models.PROTECT, verbose_name="City", related_name="cust_city")
    customer_state = models.CharField(max_length=2, blank=False, null=False, default="TX", verbose_name="State")
    customer_zip = models.CharField(max_length=5, blank=False, null=False, help_text="75060", verbose_name="ZIP")
    customer_unit_number = models.CharField(max_length=20, blank=True, null=True, help_text="Unit #204", verbose_name="Unit")
    customer_email = models.EmailField(blank=False, null=False, help_text="john.doe@gmail.com", verbose_name="Email")
    customer_cell_phone = models.CharField(max_length=15, blank=False, null=False, help_text="Cell Phone", verbose_name="Cell")
    customer_home_phone = models.CharField(max_length=15, blank=True, null=True, help_text="Home Phone", verbose_name="Home")
    referred_from = models.CharField(max_length=1, choices=REFERRAL_CHOICES, default='g')

I've tried changing my query to something like customerCity: {location: 1}, customerCity: [location:{id:1}] and many variants of these.

Note: there exists a location record in the database with an id of 1

question from:https://stackoverflow.com/questions/65944982/cant-figure-out-how-to-craft-my-graphql-query-with-graphene-django

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...