mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
linting, server is working
This commit is contained in:
parent
4c0667d870
commit
34b30b216b
3
backend/.eslintignore
Normal file
3
backend/.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
**/*.min.js
|
||||
dist
|
||||
26
backend/.eslintrc.js
Normal file
26
backend/.eslintrc.js
Normal file
@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
// jest: true,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['prettier', '@typescript-eslint' /*, 'jest' */],
|
||||
extends: [
|
||||
'standard',
|
||||
'eslint:recommended',
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
],
|
||||
// add your custom rules here
|
||||
rules: {
|
||||
'no-console': ['error'],
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
'prettier/prettier': [
|
||||
'error',
|
||||
{
|
||||
htmlWhitespaceSensitivity: 'ignore',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
8
backend/.prettierrc.js
Normal file
8
backend/.prettierrc.js
Normal file
@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
semi: false,
|
||||
printWidth: 100,
|
||||
singleQuote: true,
|
||||
trailingComma: "all",
|
||||
tabWidth: 2,
|
||||
bracketSpacing: true
|
||||
};
|
||||
@ -8,7 +8,8 @@
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts"
|
||||
"dev": "nodemon -w src --ext ts --exec ts-node src/index.ts",
|
||||
"lint": "eslint . --ext .js,.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
@ -20,7 +21,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.12",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.28.0",
|
||||
"eslint": "^7.29.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"eslint-plugin-promise": "^5.1.0",
|
||||
"nodemon": "^2.0.7",
|
||||
"prettier": "^2.3.1",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.4"
|
||||
}
|
||||
|
||||
@ -3,8 +3,8 @@ import { InputType, Field } from 'type-graphql'
|
||||
@InputType()
|
||||
export class CreateBookInput {
|
||||
@Field()
|
||||
title: string;
|
||||
title: string
|
||||
|
||||
@Field()
|
||||
author: string;
|
||||
author: string
|
||||
}
|
||||
|
||||
@ -3,11 +3,11 @@ import { InputType, Field } from 'type-graphql'
|
||||
@InputType()
|
||||
export class UpdateBookInput {
|
||||
@Field({ nullable: true })
|
||||
title?: string;
|
||||
title?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
author?: string;
|
||||
author?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
isPublished?: boolean;
|
||||
}
|
||||
isPublished?: boolean
|
||||
}
|
||||
|
||||
@ -6,17 +6,17 @@ import { ObjectType, Field, ID } from 'type-graphql'
|
||||
export class Book extends BaseEntity {
|
||||
@Field(() => ID)
|
||||
@PrimaryGeneratedColumn()
|
||||
id: string;
|
||||
id: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
title: string;
|
||||
title: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
author: string;
|
||||
author: string
|
||||
|
||||
@Field(() => Boolean)
|
||||
@Column({ default: false })
|
||||
isPublished: boolean;
|
||||
}
|
||||
isPublished: boolean
|
||||
}
|
||||
|
||||
@ -7,35 +7,35 @@ import { UpdateBookInput } from '../inputs/UpdateBookInput'
|
||||
export class BookResolver {
|
||||
@Query(() => [Book])
|
||||
books() {
|
||||
return Book.find();
|
||||
return Book.find()
|
||||
}
|
||||
|
||||
@Query(() => Book)
|
||||
book(@Arg("id") id: string) {
|
||||
return Book.findOne({ where: { id } });
|
||||
book(@Arg('id') id: string) {
|
||||
return Book.findOne({ where: { id } })
|
||||
}
|
||||
|
||||
@Mutation(() => Book)
|
||||
async createBook(@Arg("data") data: CreateBookInput) {
|
||||
const book = Book.create(data);
|
||||
await book.save();
|
||||
return book;
|
||||
async createBook(@Arg('data') data: CreateBookInput) {
|
||||
const book = Book.create(data)
|
||||
await book.save()
|
||||
return book
|
||||
}
|
||||
|
||||
@Mutation(() => Book)
|
||||
async updateBook(@Arg("id") id: string, @Arg("data") data: UpdateBookInput) {
|
||||
const book = await Book.findOne({ where: { id } });
|
||||
if (!book) throw new Error("Book not found!");
|
||||
Object.assign(book, data);
|
||||
await book.save();
|
||||
return book;
|
||||
async updateBook(@Arg('id') id: string, @Arg('data') data: UpdateBookInput) {
|
||||
const book = await Book.findOne({ where: { id } })
|
||||
if (!book) throw new Error('Book not found!')
|
||||
Object.assign(book, data)
|
||||
await book.save()
|
||||
return book
|
||||
}
|
||||
|
||||
@Mutation(() => Boolean)
|
||||
async deleteBook(@Arg("id") id: string) {
|
||||
const book = await Book.findOne({ where: { id } });
|
||||
if (!book) throw new Error("Book not found!");
|
||||
await book.remove();
|
||||
return true;
|
||||
async deleteBook(@Arg('id') id: string) {
|
||||
const book = await Book.findOne({ where: { id } })
|
||||
if (!book) throw new Error('Book not found!')
|
||||
await book.remove()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,28 +1,29 @@
|
||||
import 'reflect-metadata'
|
||||
import express from 'express'
|
||||
import { graphqlHTTP } from 'express-graphql'
|
||||
import { createConnection } from 'typeorm'
|
||||
// import { createConnection } from 'typeorm'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
import { BookResolver } from "./graphql/resolvers/BookResolver"
|
||||
import { BookResolver } from './graphql/resolvers/BookResolver'
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
|
||||
async function main() {
|
||||
const connection = await createConnection()
|
||||
const schema = await buildSchema({ resolvers: [BookResolver]})
|
||||
const server = express();
|
||||
// const connection = await createConnection()
|
||||
const schema = await buildSchema({ resolvers: [BookResolver] })
|
||||
const server = express()
|
||||
|
||||
server.use('/api',
|
||||
server.use(
|
||||
'/api',
|
||||
graphqlHTTP({
|
||||
schema,
|
||||
graphiql: true,
|
||||
validationRules: [
|
||||
/**
|
||||
* This provides GraphQL query analysis to reject complex queries to your GraphQL server.
|
||||
* This can be used to protect your GraphQL servers
|
||||
* against resource exhaustion and DoS attacks.
|
||||
* More documentation can be found (here)[https://github.com/ivome/graphql-query-complexity]
|
||||
*/
|
||||
/*queryComplexity({
|
||||
/**
|
||||
* This provides GraphQL query analysis to reject complex queries to your GraphQL server.
|
||||
* This can be used to protect your GraphQL servers
|
||||
* against resource exhaustion and DoS attacks.
|
||||
* More documentation can be found (here)[https://github.com/ivome/graphql-query-complexity]
|
||||
*/
|
||||
/* queryComplexity({
|
||||
// The maximum allowed query complexity, queries above this threshold will be rejected
|
||||
maximumComplexity: 20,
|
||||
// The query variables. This is needed because the variables are not available
|
||||
@ -46,17 +47,15 @@ async function main() {
|
||||
defaultComplexity: 1,
|
||||
}),
|
||||
],
|
||||
}),*/
|
||||
],
|
||||
})
|
||||
}), */
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
// app.get("/playground", expressPlayground({ endpoint: "/graphql" }));
|
||||
server.listen(4000, () => {
|
||||
console.log(
|
||||
`Server is running, GraphIQL available at http://localhost:4000/api`,
|
||||
);
|
||||
});
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Server is running, GraphIQL available at http://localhost:4000/api`)
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
main()
|
||||
|
||||
1287
backend/yarn.lock
1287
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user