Skip to content

Instantly share code, notes, and snippets.

@nicooga
Created May 22, 2020 02:23
Show Gist options
  • Save nicooga/4c616172fcbba5e9d956071af367b3bb to your computer and use it in GitHub Desktop.
Save nicooga/4c616172fcbba5e9d956071af367b3bb to your computer and use it in GitHub Desktop.
GET /api/customers Devuelve la lista de usuarios
POSt /api/customers con un JSON string { username, surname, address, email, phone }. Creo un usario
DELETE /api/customers/:id destruyo el cliente con ese ID
query asdf {
getCustomers() {
email
phone
avatarUrl
}
}
mutation qwer($id: ID!) {
deleteCustomer(id: $id)
}
type Customer {
id: ID!
username: String!
surname: String!
address: String!
email: String!
phone: string!
avatarUrl: String
}
type GenericResponse {
message: String!
}
type Mutation {
createCustomer(username: String!, surname: String!, address: String!, email: String!, phone: String!): Customer!
deleteCustomer(id: ID!): GenericActionResponse!
}
type Query {
getCustomers(): [Customer!]!
}
import { ApolloServer } from 'apollo-server'
import typeDefs from './schema.graphql'
import Customers from "./models/Customers"
const Server = new ApolloServer({
typeDefs,
resolvers: {
Mutation: {
deleteCustomer: async (_root, { id }, _context) => {
await Customers.findByIdAndDelete(id)
return { message: 'Exitos amigos' }
},
createCustomer: async (_root, { username, surname, address, email, phone }, _context) {
const newCustomers = new Customers({
username,
surname,
address,
email,
phone,
})
const customer = await newCustomers.save()
return customer
}
},
Query: {
getCutstomers: async (_root, _params, _context) => {
const customers = await Customers.find()
return customers
}
}
}
})
Server.listen(4000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment