Chapter 04 (Understanding GraphQL) - Intuit-London/imperial-react-workshop GitHub Wiki

Start GraphQL Server

  1. Clone the project from https://github.com/Intuit-London/invoice-graphql.git
  2. Navigate to the cloned invoice-graphql folder and Run the command ./gradlew build && java -jar build/libs/invoice-grapqhl-1.0-SNAPSHOT.jar For Windows: gradlew.bat build && java -jar build/libs/invoice-grapqhl-1.0-SNAPSHOT.jar
  3. Install Chrome browser extension chromeiql to execute graphql queries.
  4. Set endpoint as http://localhost:8080/graphql

Read Calls

  1. Execute following queries
{
  users {
    id,
    firstName,
    invoices {
      number,
      creationDate,
      totalAmount,
      totalAmount
    }
  }
}
  1. Making use of fragments
{
  users {
    id,
    firstName,
    invoices {
      ...invoicedetails
    }
  }
}

fragment invoicedetails on Invoice {
  number,
  paymentDate,
  creationDate,
  totalAmount
}

Mutations

  1. Sample mutation to create a Invoice
mutation InvoiceMutation {
    createInvoice(input: {
        clientMutationId: "client-mutation-1",
        invoice: {
            user: {
                id: "L1VzZXI6dXNlci0x"
            },
            number: 1234,
            customer: {
                id: "customer-2",
                businessName: "Juan"
            },
            creationDate: "25-06-2016",
            paymentDate: "28-06-2016",
            paid: true,
            totalAmount: 100
        }
    }) {
        clientMutationId
        invoice {
            user {
                id
            }
            number
            totalAmount
        }
    }
}