-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
179 additions
and
59 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { userMutations } from './resource/user/user.schema' | ||
import { postMutation } from './resource/post/post.schema' | ||
import { commentMutation } from './resource/comment/comment.schema'; | ||
|
||
|
||
const Mutation = ` | ||
type: Mutation( | ||
${ commentMutation } | ||
${ postMutation } | ||
${ userMutations } | ||
) | ||
` | ||
|
||
export { | ||
Mutation | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { userQueries } from './resource/user/user.schema' | ||
import { postQueries } from './resource/post/post.schema' | ||
import { commentQueries } from './resource/comment/comment.schema'; | ||
|
||
|
||
const Query = ` | ||
type: Query( | ||
${ commentQueries } | ||
${ postQueries } | ||
${ userQueries } | ||
) | ||
` | ||
|
||
export { | ||
Query | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const commentType = ` | ||
type Post { | ||
id: ID! | ||
commnet: String! | ||
createdAt: String! | ||
updatedAt: String! | ||
user: User! | ||
post: Post! | ||
} | ||
input CommentInput { | ||
comment: String! | ||
post: Int!, | ||
user: Int! | ||
} | ||
` | ||
const commentQueries = ` | ||
commentsByPost(post: ID!, first: Int, offset: Int): [ Comment! ]! | ||
` | ||
const commentMutation = ` | ||
createComment(input: CommentInput!): Comment | ||
updatePost(id: ID!, input: CommentInput!): Comment | ||
deletePost(id: ID!) | ||
` | ||
export { | ||
commentType, | ||
commentQueries, | ||
commentMutation | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const postTypes = ` | ||
type Post { | ||
id: ID! | ||
title: String! | ||
content: String! | ||
photo: String | ||
createdAt: String! | ||
updatedAt: String! | ||
author: User! | ||
comments: [ Comment! ] | ||
} | ||
input PostInput { | ||
title: String! | ||
content: String! | ||
photo: String | ||
author: User! | ||
} | ||
` | ||
|
||
const postQueries = ` | ||
posts(first: Int, offset: Int): [ Post! ] | ||
post(id: ID!): Post | ||
` | ||
const postMutation = ` | ||
createPost(input: PostInput!): Post | ||
updatePost(id: ID!, input: PostInput!): Post | ||
deletePost(id: ID!) | ||
` | ||
export { | ||
postTypes, | ||
postQueries, | ||
postMutation | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const userTypes = ` | ||
# User definition type | ||
type User { | ||
id: ID! | ||
name: String! | ||
email: String! | ||
photo: String | ||
createdAt: String! | ||
updatedAt: String! | ||
} | ||
input UserCreateInput { | ||
name: String! | ||
email: String! | ||
password: String! | ||
} | ||
input UserUpdateInput { | ||
name: String! | ||
email: String! | ||
photo: String! | ||
} | ||
input UserUpdatePasswordInput { | ||
password: String! | ||
} | ||
` | ||
|
||
const userQueries = ` | ||
users(first: Int, offset: Int): [ User! ] | ||
user(id: ID!): User | ||
` | ||
|
||
const userMutations = ` | ||
createUser(input: UserCreateInput()): User) | ||
updateUser(id: ID!, input: UserUpdateInput): User | ||
UserUpdatePassword(id: ID!, input: UserUpdatePasswordInput): Boolean | ||
deleteUser(id: ID!): Boolean | ||
` | ||
|
||
export { | ||
userTypes, | ||
userQueries, | ||
userMutations | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,26 @@ | ||
import { makeExecutableSchema } from 'graphql-tools' | ||
|
||
const users: any[] = [ | ||
{ | ||
id: 1, | ||
name: 'Gabriel Marcos', | ||
email: '[email protected]' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Marcelo Montanher', | ||
email: '[email protected]' | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Camila Caligari', | ||
email: '[email protected]' | ||
} | ||
] | ||
|
||
const typeDefs = ` | ||
type User { | ||
id: ID! | ||
name: String! | ||
email: String! | ||
} | ||
import { Query } from "./query" | ||
import { Mutation } from "./mutation" | ||
|
||
type Query { | ||
allUser: [User!]! | ||
} | ||
import { postTypes } from './resource/post/post.schema'; | ||
import { userTypes } from './resource/user/user.schema'; | ||
import { commentType } from './resource/comment/comment.schema'; | ||
|
||
type Mutation { | ||
createUser(name: String!, email: String!): User | ||
const SchemaDefinition = ` | ||
type: Schema { | ||
query: Query, | ||
mutation: Mutation | ||
} | ||
` | ||
|
||
const resolvers = { | ||
Query: { | ||
allUser: () => users | ||
}, | ||
Mutation: { | ||
createUser: (parent, args) => { | ||
const newUser = Object.assign({id: users.length + 1}, args) | ||
users.push(newUser) | ||
return newUser | ||
} | ||
} | ||
} | ||
|
||
export default makeExecutableSchema({typeDefs, resolvers}) | ||
export default makeExecutableSchema({ | ||
typeDefs: [ | ||
SchemaDefinition, | ||
Query, | ||
Mutation, | ||
commentType, | ||
postTypes, | ||
userTypes | ||
] | ||
}) |
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
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
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
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