summaryrefslogtreecommitdiffstats
path: root/frontend/queries
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-01-30 12:41:01 -0500
committerWes Bos <wesbos@gmail.com>2018-01-30 12:41:01 -0500
commitcd0b07b3adb36fb5ec098f9e511ab45d774fee7b (patch)
treea203e5010219ccea1acc6bbd2c0a4bcfa0a78615 /frontend/queries
parent0a1648bf47490b312169c531aeb51ef4725e8d2e (diff)
Move to Prisma Backend
Diffstat (limited to 'frontend/queries')
-rw-r--r--frontend/queries/fragments.js16
-rw-r--r--frontend/queries/index.js196
-rw-r--r--frontend/queries/mutations.js0
3 files changed, 212 insertions, 0 deletions
diff --git a/frontend/queries/fragments.js b/frontend/queries/fragments.js
new file mode 100644
index 0000000..019992e
--- /dev/null
+++ b/frontend/queries/fragments.js
@@ -0,0 +1,16 @@
+import gql from 'graphql-tag';
+
+export const itemDetails = gql`
+ fragment itemDetails on Item {
+ id
+ title
+ price
+ fullPrice
+ description
+ image {
+ id
+ url
+ secret
+ }
+ }
+`;
diff --git a/frontend/queries/index.js b/frontend/queries/index.js
new file mode 100644
index 0000000..8b7897f
--- /dev/null
+++ b/frontend/queries/index.js
@@ -0,0 +1,196 @@
+import gql from 'graphql-tag';
+import { itemDetails } from './fragments';
+
+export const CREATE_ITEM_MUTATION = gql`
+ ${itemDetails}
+ mutation CreateLinkMutation($description: String!, $title: String!, $imageId: ID, $price: Int!) {
+ createItem(
+ description: $description,
+ title: $title,
+ imageId: $imageId
+ price: $price
+ ) {
+ ...itemDetails
+ }
+ }
+`;
+
+export const CREATE_USER_MUTATION = gql`
+ mutation CreateUserMutation($email: String!, $name: String!, $idToken: String!) {
+ createUser(email: $email, name: $name, authProvider: { auth0: { idToken: $idToken } }) {
+ id
+ email
+ name
+ cart {
+ id
+ title
+ }
+ }
+ }
+`;
+
+export const CREATE_ORDER_MUTATION = gql`
+ mutation CreateOrderMutation($token: String!, $userId: ID!, $itemId: ID!) {
+ createOrder(token: $token, userId: $userId, itemId: $itemId) {
+ id
+ token
+ charge
+ amount
+ item {
+ id
+ title
+ description
+ }
+ user {
+ id
+ email
+ }
+ }
+ }
+`;
+
+export const ALL_ITEMS_QUERY = gql`
+ # Import the Fragment
+ ${itemDetails}
+ query AllLinksQuery($skip: Int = 0, $first: Int = 3) {
+ _allItemsMeta {
+ count
+ }
+ allItems(orderBy: createdAt_DESC, first: $first, skip: $skip) {
+ ...itemDetails
+ }
+ }
+`;
+
+export const SINGLE_ITEM_QUERY = gql`
+ ${itemDetails}
+ query FindItem($id: ID!) {
+ Item(id: $id) {
+ ...itemDetails
+ }
+ }
+`;
+
+export const SEARCH_ITEMS_QUERY = gql`
+ ${itemDetails}
+ query SearchItems($searchTerm: String!) {
+ allItems(filter:{
+ OR:[
+ { title_contains: $searchTerm },
+ { description_contains: $searchTerm },
+ ]
+ }) {
+ ...itemDetails
+ }
+ }
+`;
+
+export const DELETE_ITEM_MUTATION = gql`
+ mutation DelteItem($id: ID!) {
+ deleteItem(id: $id) {
+ id
+ title
+ description
+ }
+ }
+`;
+
+export const UPDATE_LINK_MUTATION = gql`
+ ${itemDetails}
+ mutation UpdateItem($id: ID!, $title: String!, $description: String!, $price: Int!, $fullPrice: Int!) {
+ updateItem(
+ id: $id,
+ description: $description,
+ title: $title,
+ price: $price,
+ fullPrice: $fullPrice
+ ) {
+ ...itemDetails
+ }
+ }
+`;
+
+export const CURRENT_USER_QUERY = gql`
+ query userQuery {
+ user {
+ id
+ name
+ email
+ cart {
+ id
+ price
+ title
+ image {
+ id
+ secret
+ }
+ }
+ }
+ }
+`;
+
+export const USER_ORDERS_QUERY = gql`
+ query {
+ user {
+ # grab the current user
+ id
+ orders {
+ # and a all their orders
+ id
+ amount
+ charge
+ item {
+ # populate the details about the item they bought with the image, description and title
+ image {
+ id
+ secret
+ }
+ description
+ title
+ }
+ }
+ }
+ }
+`;
+
+export const ADD_TO_CART_MUTATION = gql`
+ mutation AddToCart($userId: ID!, $itemId: ID!) {
+ addToCartItems(userUserId: $userId, cartItemId: $itemId) {
+ cartItem {
+ id
+ title
+ price
+ }
+ }
+ }
+`;
+
+export const REMOVE_FROM_CART_MUTATION = gql`
+ mutation xxx($userId: ID!, $itemId: ID!) {
+ removeFromCartItems(userUserId: $userId, cartItemId: $itemId) {
+ cartItem {
+ id
+ title
+ price
+ }
+ }
+ }
+`;
+
+export const GET_CART_STATE = gql`
+ query {
+ ui {
+ isCartOpen
+ }
+ }
+`;
+
+export const UPDATE_CART_STATE = gql`
+ mutation updateCartState($isCartOpen: Boolean!) {
+ updateCartState(isCartOpen: $isCartOpen) {
+ ui {
+ isCartOpen
+ }
+ }
+ }
+`;
diff --git a/frontend/queries/mutations.js b/frontend/queries/mutations.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/frontend/queries/mutations.js