Created
May 22, 2020 02:23
-
-
Save nicooga/4c616172fcbba5e9d956071af367b3bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query asdf { | |
getCustomers() { | |
phone | |
avatarUrl | |
} | |
} | |
mutation qwer($id: ID!) { | |
deleteCustomer(id: $id) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!]! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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