Error with Prisma Yoga server


#1

Hello, I am trying to set up a new project with NextJs, Typescript and Prisma Yoga graphql server based on this repo https://github.com/moltin-examples/graphql-moltin-server.
I added an addBillingAddress Mutation with the following resolver:

async addBillingAddress(
    root,
    {
      customerId,
      firstName,
      lastName,
      addressLine,
      postalCode,
      region,
      country
    },
    { Moltin }
  ) {
    try {
      const { data: address } = await Moltin.Addresses.Create({
        customer: customerId,
        body: {
          first_name: firstName,
          last_name: lastName,
          line_1: addressLine,
          postcode: postalCode,
          county: region,
          country
        }
      });

      return address;
    } catch (e) {
      return e;
    }
  },

The error I’m getting when submitting the form that uses this mutation is "Cannot return null for non-nullable field BillingAddress.first_name."
The mutation looks like this:

    const ADD_BILLING_ADDRESS = gql`
      mutation addBillingAddress(
        $customerId: ID!
        $firstName: String!
        $lastName: String!
        $addressLine: String!
        $postalCode: String!
        $region: String!
        $country: String!
      ) {
        addBillingAddress(
          customerId: $customerId
          firstName: $firstName
          lastName: $lastName
          addressLine: $addressLine
          postalCode: $postalCode
          region: $region
          country: $country
        ) {
          first_name
          country
        }
      }
    `;

I tried a lot of different ways to ask for the data but error is always there. Anyone can help indicating which direction I should look?


#2

Never mind, I figured it out :grinning:
Ended up being the country field being sent as the entire country name instead of the 2 digit code.
Pro tip: Make sure you have a way to debug your backend and don’t take graphql errors literally :grin:


#3

Great! It’s awesome to see you’re using GraphQL.

@jonathan and I recorded a video on GraphQL which will be doing out this week where we share some of the interesting things you can do with GraphQL + Moltin.

I’ll drop you a message when it’s online in case it’s of any use :smile:


#4

:+1: Absolutely, please let me know! I think I will have to do quite some work with GraphQL in the following months and I hope plugging in Moltin proves successful too! All resources are very welcome :slight_smile:


#5

Sounds great @proko!

Here is the video https://youtu.be/xThF2COeB-4

We’ve another coming on Gatsby and further videos/examples using GraphQL :wink: