Pre-deployment
This commit is contained in:
29
api/src/graphql/contacts.sdl.js
Normal file
29
api/src/graphql/contacts.sdl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export const schema = gql`
|
||||
type Contact {
|
||||
id: Int!
|
||||
name: String!
|
||||
email: String!
|
||||
message: String!
|
||||
createdAt: DateTime!
|
||||
}
|
||||
|
||||
type Query {
|
||||
contacts: [Contact!]!
|
||||
}
|
||||
|
||||
input CreateContactInput {
|
||||
name: String!
|
||||
email: String!
|
||||
message: String!
|
||||
}
|
||||
|
||||
input UpdateContactInput {
|
||||
name: String
|
||||
email: String
|
||||
message: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createContact(input: CreateContactInput!): Contact
|
||||
}
|
||||
`
|
||||
29
api/src/graphql/posts.sdl.js
Normal file
29
api/src/graphql/posts.sdl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export const schema = gql`
|
||||
type Post {
|
||||
id: Int!
|
||||
title: String!
|
||||
body: String!
|
||||
createdAt: DateTime!
|
||||
}
|
||||
|
||||
type Query {
|
||||
posts: [Post!]!
|
||||
post(id: Int!): Post
|
||||
}
|
||||
|
||||
input CreatePostInput {
|
||||
title: String!
|
||||
body: String!
|
||||
}
|
||||
|
||||
input UpdatePostInput {
|
||||
title: String
|
||||
body: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createPost(input: CreatePostInput!): Post!
|
||||
updatePost(id: Int!, input: UpdatePostInput!): Post!
|
||||
deletePost(id: Int!): Post!
|
||||
}
|
||||
`
|
||||
21
api/src/services/contacts/contacts.js
Normal file
21
api/src/services/contacts/contacts.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { db } from 'src/lib/db'
|
||||
import { UserInputError } from '@redwoodjs/api'
|
||||
|
||||
const validate = (input) => {
|
||||
if (input.email && !input.email.match(/[^@]+@[^.]+\..+/)) {
|
||||
throw new UserInputError("Can't create new contact",{
|
||||
messages: {
|
||||
email: ['is not formatted like an email address'],
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const contacts = () => {
|
||||
return db.contact.findMany()
|
||||
}
|
||||
|
||||
export const createContact = ({ input }) => {
|
||||
validate(input)
|
||||
return db.contact.create({ data: input })
|
||||
}
|
||||
9
api/src/services/contacts/contacts.test.js
Normal file
9
api/src/services/contacts/contacts.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
import { contacts } from './contacts'
|
||||
*/
|
||||
|
||||
describe('contacts', () => {
|
||||
it('returns true', () => {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
30
api/src/services/posts/posts.js
Normal file
30
api/src/services/posts/posts.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { db } from 'src/lib/db'
|
||||
|
||||
export const posts = () => {
|
||||
return db.post.findMany()
|
||||
}
|
||||
|
||||
export const post = ({ id }) => {
|
||||
return db.post.findOne({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const createPost = ({ input }) => {
|
||||
return db.post.create({
|
||||
data: input,
|
||||
})
|
||||
}
|
||||
|
||||
export const updatePost = ({ id, input }) => {
|
||||
return db.post.update({
|
||||
data: input,
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const deletePost = ({ id }) => {
|
||||
return db.post.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
9
api/src/services/posts/posts.test.js
Normal file
9
api/src/services/posts/posts.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
import { posts } from './posts'
|
||||
*/
|
||||
|
||||
describe('posts', () => {
|
||||
it('returns true', () => {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user