summaryrefslogtreecommitdiffstats
path: root/queries/index.js
blob: 9b11bb8ea133c4ce64806410c8f84206d948c14e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { gql } from 'react-apollo'
import { itemDetails } from './fragments';

export const CREATE_LINK_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
      }
    }
  }
`;