Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancarlos-cpu committed Nov 22, 2019
1 parent 97afc46 commit b29ff6d
Show file tree
Hide file tree
Showing 10 changed files with 783 additions and 3,371 deletions.
3,937 changes: 580 additions & 3,357 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"description": "",
"main": "server.js",
"scripts": {
"start": "env-cmd -f ./config/prod.env node src/index.js",
"start": "env-cmd -f ./config/prod.env node src/apollo-sever.js",
"test": "env-cmd -f ./config/test.env jest --watch",
"dev": "env-cmd -f ./config/dev.env nodemon src/index.js"
"dev": "env-cmd -f ./config/dev.env nodemon src/apollo-sever.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server": "^2.9.12",
"bcryptjs": "^2.4.3",
"env-cmd": "^10.0.1",
"graphql-cli": "^3.0.14",
"graphql-yoga": "^1.18.3",
"graphql": "^14.5.8",
"jsonwebtoken": "^8.5.1",
"prisma-client-lib": "^1.34.10"
},
Expand Down
2 changes: 1 addition & 1 deletion prisma/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
connector: postgres
host: ec2-174-129-253-180.compute-1.amazonaws.com
database: dc8aulraamt5ms
#schema: public
schema: public
user: aursttndplnowi
password: 9ae74278f62224452e3738f7cf20a0bfaf45a12ec41aa40e50c5263988293471
ssl: true
Expand Down
4 changes: 2 additions & 2 deletions prisma/generated/prisma-client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export interface User {
name: String;
email: String;
password: String;
updatedAt: DateTimeOutput;
updatedAt?: DateTimeOutput;
createdAt: DateTimeOutput;
}

Expand Down Expand Up @@ -1464,7 +1464,7 @@ export interface UserPreviousValues {
name: String;
email: String;
password: String;
updatedAt: DateTimeOutput;
updatedAt?: DateTimeOutput;
createdAt: DateTimeOutput;
}

Expand Down
4 changes: 2 additions & 2 deletions prisma/generated/prisma-client/prisma-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ type User {
password: String!
posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post!]
comments(where: CommentWhereInput, orderBy: CommentOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Comment!]
updatedAt: DateTime!
updatedAt: DateTime
createdAt: DateTime!
}
Expand Down Expand Up @@ -736,7 +736,7 @@ type UserPreviousValues {
name: String!
email: String!
password: String!
updatedAt: DateTime!
updatedAt: DateTime
createdAt: DateTime!
}
Expand Down
4 changes: 3 additions & 1 deletion resolvers/query.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const Query = {
users: (parent, args, { prisma }, info) =>
prisma.users({
where: {
OR: [{ name_contains: args.query }, { email_contains: args.query }]
OR: [{ name_contains: args.query }, {
// email_contains: args.query
}]
},
first: args.first,
skip: args.skip,
Expand Down
17 changes: 17 additions & 0 deletions src/apollo-sever.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { ApolloServer } = require("apollo-server");
const { resolvers } = require("../resolvers/index.resolver");
const { prisma } = require("../prisma/generated/prisma-client/index");
const { schema } = require("./squema");

const server = new ApolloServer({
typeDefs: schema,
resolvers,
context: req => ({
prisma,
req
})
});

server.listen({ port: process.env.PORT || 4000 }).then(
console.log("its working!")
)
171 changes: 171 additions & 0 deletions src/squema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
const { gql } = require("apollo-server");

schema = gql`
type Query {
me: User!
users(
query: String
first: Int
skip: Int
orderBy: UserOrderByInput
): [User]
posts(
query: String
first: Int
skip: Int
orderBy: PostOrderByInput
): [Post]
myPosts(
query: String
first: Int
skip: Int
orderBy: PostOrderByInput
): [Post]
comments(first: Int, skip: Int, orderBy: CommentOrderByInput): [Comment]
post(id: ID!): Post!
}
type Mutation {
createUser(data: CreateUserInput): userPayload!
deleteUser(id: ID!): User!
updateUser(data: updateUserInput): User!
createPost(data: CreatePostInput): Post!
deletePost(id: ID!): Post!
updatePost(id: ID!, data: updatePostInput): Post!
createComment(data: CreateCommentInput): Comment!
deleteComment(id: ID!): Comment!
updateComment(id: ID!, data: updateCommentInput): Comment!
login(data: userCredentialsInput!): userPayload!
}
input userCredentialsInput {
email: String!
password: String!
}
type userPayload {
token: String!
user: User!
}
type Subscription {
comment(postId: ID!): CommentSubscriptionPayload
post: PostSubscriptionPayload
myPost: PostSubscriptionPayload
}
input CreateUserInput {
name: String!
email: String!
password: String!
}
input updateUserInput {
name: String
email: String
password: String
}
input CreatePostInput {
title: String!
body: String!
published: Boolean!
}
input updatePostInput {
title: String
body: String
published: Boolean
}
input CreateCommentInput {
text: String!
post: ID!
}
input updateCommentInput {
text: String
}
type User {
id: ID!
name: String!
email: String
password: String
posts: [Post]
comments: [Comment]
createdAt: String!
updatedAt: String!
}
type Post {
id: ID!
title: String!
body: String!
published: Boolean!
author: User!
comments: [Comment]
createdAt: String!
updatedAt: String!
}
type Comment {
id: ID!
text: String!
author: User!
post: Post!
createdAt: String!
updatedAt: String!
}
enum MutationType {
CREATED
UPDATED
DELETED
}
type PostSubscriptionPayload {
mutation: MutationType
node: Post
}
type CommentSubscriptionPayload {
mutation: MutationType
node: Comment
}
enum UserOrderByInput {
name_ASC
name_DESC
updatedAt_ASC
updatedAt_DESC
createdAt_ASC
createdAt_DESC
}
enum PostOrderByInput {
title_ASC
title_DESC
body_ASC
body_DESC
published_ASC
published_DESC
updatedAt_ASC
updatedAt_DESC
createdAt_ASC
createdAt_DESC
}
enum CommentOrderByInput {
text_ASC
text_DESC
updatedAt_ASC
updatedAt_DESC
createdAt_ASC
createdAt_DESC
}
`;

module.exports = {
schema
};
6 changes: 3 additions & 3 deletions src/utils/getUserId.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const jwt = require("jsonwebtoken");
const secret = "fhdsjf978saf7dsfb110vvcs780432";
const secret = process.env.JWT_SECRET;

const getUserId = (req, authRequired = true) => {
const token = req.request
? req.request.headers.authorization
const token = req.req
? req.req.headers.authorization
: req.connection.context.Authorization;

if (token) {
Expand Down
1 change: 0 additions & 1 deletion tests/user.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test("fdsa fdsa fdsafdsa", () => {
throw new Error('fdsafds')
});

0 comments on commit b29ff6d

Please sign in to comment.