Skip to content

Commit

Permalink
fix: 📦️ upgrade packages
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck committed Oct 23, 2023
1 parent fe30ff4 commit db94bf9
Show file tree
Hide file tree
Showing 26 changed files with 2,874 additions and 9,831 deletions.
1 change: 1 addition & 0 deletions bundestag.io/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ diffs/*
.env*
!.env.example
built
generated
14 changes: 8 additions & 6 deletions bundestag.io/api/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
schema: http://localhost:4000/
overwrite: true
schema: './src/graphql/schemas/*.graphql'
# documents: './src/**/*.graphql'
generates:
./src/graphql/resolvers/types.ts:
config:
contextType: ../../types/graphqlContext#GraphQlContext
./src/generated/graphql.ts:
plugins:
- typescript
- typescript-resolvers
- 'typescript'
- 'codegen/typedefs.js'
- 'typescript-operations'
- 'typescript-resolvers'
16 changes: 16 additions & 0 deletions bundestag.io/api/codegen/typedefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var graphqlUtils = require('@graphql-tools/utils');
var graphql = require('graphql');

// https://github.com/dotansimha/graphql-code-generator/issues/3899
var print = function (schema) {
var escapedSchema = schema.replace(/\\`/g, '\\\\`').replace(/`/g, '\\`');

// import { gql } from "@apollo/client/core"
return '\n' + 'export const typeDefs = `' + escapedSchema + '`;';
};

module.exports = {
plugin: function (schema) {
return print(graphql.stripIgnoredCharacters(graphqlUtils.printSchemaWithDirectives(schema)));
},
};
56 changes: 27 additions & 29 deletions bundestag.io/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,38 @@
"lint:es": "eslint src --ext .js,.jsx,.ts,.tsx",
"lint:ts": "tsc --noEmit",
"lint:exports": "ts-unused-exports ./tsconfig.json --excludePathsFromReport=generated --excludePathsFromReport=resolvers --excludePathsFromReport=/schemas --excludePathsFromReport=graphqlContext.ts",
"generate": "graphql-codegen"
"generate": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"@apollo/server": "^4.9.4",
"@democracy-deutschland/bundestag.io-definitions": "1.0.2",
"@democracy-deutschland/bundestagio-common": "0.1.20",
"apollo-server-express": "^2.3.3",
"axios": "^0.24.0",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"express": "^4.16.2",
"express-status-monitor": "^1.2.3",
"graphql": "^15.2.0",
"graphql-date": "^1.0.3",
"lodash": "^4.17.10",
"merge-graphql-schemas": "^1.5.0",
"@democracy-deutschland/bundestagio-common": "workspace:*",
"@graphql-tools/schema": "^10.0.0",
"@graphql-tools/utils": "^10.0.7",
"axios": "1.5.1",
"express": "4.18.2",
"graphql": "16.8.1",
"graphql-date": "1.0.3",
"lodash": "4.17.21",
"mongoose": "6.0.12",
"winston": "^3.0.0",
"winston-mongodb": "^5.0.1",
"xml-js": "^1.6.11"
"winston": "3.11.0",
"winston-mongodb": "5.1.1",
"xml-js": "1.6.11"
},
"devDependencies": {
"@graphql-codegen/cli": "^1.17.0",
"@graphql-codegen/typescript": "^1.17.0",
"@graphql-codegen/typescript-resolvers": "^1.17.0",
"@types/express-status-monitor": "^1.2.1",
"@types/graphql-date": "^1.0.5",
"@types/lodash": "^4.14.157",
"eslint": "^7",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"prettier": "^2.4.1",
"ts-node-dev": "^1.1.8",
"ts-unused-exports": "^7.0.3",
"typescript": "^4.6.3"
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "4.0.1",
"@types/graphql-date": "1.0.8",
"@types/lodash": "4.14.200",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.1",
"jest": "29.7.0",
"prettier": "3.0.3",
"ts-node-dev": "2.0.0",
"ts-unused-exports": "10.0.1",
"typescript": "5.2.2"
}
}
2 changes: 1 addition & 1 deletion bundestag.io/api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const requiredConfigs = {

const recommendedConfigs = {
// No correct default Values
PORT: process.env.PORT || 3100,
PORT: Number(process.env.PORT || 3100),
DB_URL: process.env.DB_URL || 'mongodb://localhost:27017/bundestagio',
ELASTICSEARCH_URL: process.env.ELASTICSEARCH_URL || 'elasticsearch',
PERIODS: process.env.PERIODS ? process.env.PERIODS.split(',') : ['Alle'],
Expand Down
98 changes: 40 additions & 58 deletions bundestag.io/api/src/graphql/schemaDirectives/auth.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,43 @@
import { defaultFieldResolver } from 'graphql';
import { Log } from '../../services/logger';
import { SchemaDirectiveVisitor } from 'apollo-server-express';
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
import { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils';

class AuthDirective extends SchemaDirectiveVisitor {
visitObject(type): void {
this.ensureFieldsWrapped(type);
type._requiredAuthRole = this.args.requires;
}
const directiveTypeDefs = `
directive @auth(
requires: Role = USER
) on FIELD_DEFINITION
// Visitor methods for nested types like fields and arguments
// also receive a details object that provides information about
// the parent and grandparent types.
visitFieldDefinition(field, details) {
this.ensureFieldsWrapped(details.objectType);
field._requiredAuthRole = this.args.requires;
}

ensureFieldsWrapped(objectType) {
// Mark the GraphQLObjectType object to avoid re-wrapping:
if (objectType._authFieldsWrapped) return;
objectType._authFieldsWrapped = true;

const fields = objectType.getFields();
Object.keys(fields).forEach((fieldName) => {
const field = fields[fieldName];
const { resolve = defaultFieldResolver } = field;

field.resolve = async (...args) => {
// Get the required Role from the field first, falling back
// to the objectType if no Role is required by the field:
const requiredRole = field._requiredAuthRole || objectType._requiredAuthRole;

if (!requiredRole) {
return resolve.apply(this, args);
}

const [, , context] = args;
let allow = true;
if (requiredRole === 'BACKEND') {
if (
!context.req.headers['bio-auth-token'] ||
context.req.headers['bio-auth-token'] !== process.env.BIO_EDIT_TOKEN
) {
Log.warn(
`Connection to Bio blocked from ${context.req.connection.remoteAddress} for role 'BACKEND'`,
);
allow = false;
}
}
if (!allow) {
throw new Error(`not authorized ${context.req.connection.remoteAddress}`);
}

return resolve.apply(this, args);
};
});
}
enum Role {
BACKEND
USER
}

export default AuthDirective;
`;

const hasPermissions = (context, role) =>
context.req.headers['bio-auth-token'] &&
context.req.headers['bio-auth-token'] === process.env.BIO_EDIT_TOKEN;

export const authDirective = (directiveName: string) => {
return {
authDirectiveTypeDefs: directiveTypeDefs,
authDirectiveTransformer: (schema: GraphQLSchema) =>
mapSchema(schema, {
[MapperKind.OBJECT_FIELD](fieldConfig) {
const authDirective = getDirective(schema, fieldConfig, directiveName)?.[0];
if (authDirective) {
const { resolve = defaultFieldResolver } = fieldConfig;
console.log(authDirective);
const { requires } = authDirective;
fieldConfig.resolve = async (parent, args, context, info) => {
console.log(hasPermissions(context, requires));
if (!hasPermissions(context, requires)) {
throw new Error('You have not enough permissions!');
}
const result = await resolve(parent, args, context, info);
return result;
};
return fieldConfig;
}
},
}),
};
};
3 changes: 0 additions & 3 deletions bundestag.io/api/src/graphql/schemaDirectives/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
export default `
type ConferenceWeekDetailSessionTopTopic {
lines: [String]
documents: [String],
isVote: Boolean
procedureIds: [String]
lines: [String]
documents: [String]
isVote: Boolean
procedureIds: [String]
}

type ConferenceWeekDetailSessionTopStatus {
line: String
documents: [String]
line: String
documents: [String]
}

type ConferenceWeekDetailSessionTop {
time: Date
top: String
heading: String
article: String
topic: [ConferenceWeekDetailSessionTopTopic]
status: [ConferenceWeekDetailSessionTopStatus]
time: Date
top: String
heading: String
article: String
topic: [ConferenceWeekDetailSessionTopTopic]
status: [ConferenceWeekDetailSessionTopStatus]
}

type ConferenceWeekDetailSession {
Expand All @@ -44,4 +42,3 @@ type Query {
conferenceWeekDetail(year: Int!, week: Int!): ConferenceWeekDetail
conferenceWeekDetails(limit: Int, offset: Int): [ConferenceWeekDetail]
}
`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export default `
type Decision {
page: String
tenor: String
Expand All @@ -8,4 +7,3 @@ type Decision {
foundation: String
majority: String
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export default `
type DeputyLink {
name: String!
URL: String!
Expand All @@ -8,7 +6,7 @@ type DeputyLink {

type DeputyFunctions {
category: String
functions: [String],
functions: [String]
}

type Deputy {
Expand All @@ -24,8 +22,8 @@ type Deputy {
biography: [String]
constituency: String
constituencyName: String
directCandidate: Boolean,
functions: [DeputyFunctions],
directCandidate: Boolean
functions: [DeputyFunctions]
speechesURL: String
votesURL: String
publicationRequirement: [String]
Expand All @@ -44,4 +42,3 @@ type Query {
deputies(limit: Int, offset: Int): [Deputy]
deputyUpdates(since: Date!, limit: Int, offset: Int): DeputyUpdate
}
`;
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export default `
type Document {
editor: String
number: String
type: String
url: String
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export default `
type LegislativePeriod {
number: Int!
start: Date!
Expand All @@ -11,4 +9,3 @@ type Query {
legislativePeriod(period: Int!): LegislativePeriod
legislativePeriods: [LegislativePeriod]
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export default `
type LegislativePeriod {
number: Int!
start: Date!
Expand All @@ -11,4 +9,3 @@ type Query {
legislativePeriod(period: Int!): LegislativePeriod
legislativePeriods: [LegislativePeriod]
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export default `
type NamedPollMediaVideoURL {
URL: String
description: String
Expand Down Expand Up @@ -79,4 +77,3 @@ type Query {
namedPolls(limit: Int, offset: Int): [NamedPoll]
namedPollUpdates(since: Date!, limit: Int, offset: Int, associated: Boolean): NamedPollUpdate
}
`;
Loading

0 comments on commit db94bf9

Please sign in to comment.