Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Lüdemann lydemann

View GitHub Profile
View server.ts
import { ApolloServer, AuthenticationError } from 'apollo-server-express';
import responseCachePlugin from 'apollo-server-plugin-response-cache';
import * as express from 'express';
import admin from 'firebase-admin';
import { AuthIdentity, RequestContext } from './auth-identity';
import { resolvers } from './resolvers';
import { typeDefs } from './schema';
/* Async verification with user token */
View server.ts
import { ApolloServer, AuthenticationError } from 'apollo-server-express';
import responseCachePlugin from 'apollo-server-plugin-response-cache';
import * as express from 'express';
import admin from 'firebase-admin';
import { AuthIdentity, RequestContext } from './auth-identity';
import { resolvers } from './resolvers';
import { typeDefs } from './schema';
/* Async verification with user token */
View main.ts
import { region } from 'firebase-functions';
import { gqlServer } from './app/server';
import { environment } from './environments/environment';
const dotenvJSON = require('dotenv-json');
if (environment.production) {
dotenvJSON({ path: __dirname + '/assets/env.json' });
} else {
dotenvJSON({ path: __dirname + '/assets/env.local.json' });
}
View course.component.ts
ngOnDestroy(): void {
this.renderer.removeChild(this.elementRef.nativeElement, this.styleElement);
this.destroy$.next();
this.destroy$.complete();
}
ngOnInit() {
switchMap((courseId) =>
this.courseFacade.getCourseCustomStyling(courseId)
)
View router.selectors.ts
const getFlattenedParentRouteParams = (route: ActivatedRouteSnapshot) => {
if (!route.parent) {
return route.params;
}
const parentRouteParams = getFlattenedParentRouteParams(route.parent);
return {
...route.params,
...parentRouteParams,
};
@lydemann
lydemann / course-facade.service.ts
Last active Mar 23, 2021
course-facade.service.ts
View course-facade.service.ts
editCourseSubmitted(editedCourse: Course) {
return this.apollo.mutate<Course>({
mutation: EDIT_COURSE_MUTATION,
variables: {
id: editedCourse.id,
name: editedCourse.name,
description: editedCourse.description,
} as Course,
});
}
@lydemann
lydemann / prevent-ghost-clicks.directive.ts
Created Mar 15, 2021
prevent-ghost-clicks.directive.ts
View prevent-ghost-clicks.directive.ts
import { Directive, ElementRef, HostListener, OnInit } from '@angular/core';
import 'hammerjs';
/*
Preventing clicks after a HammerJS press (long press) event.
Inspired from HammerJS ghost click helper: https://gist.github.com/jtangelder/361052976f044200ea17
*/
@Directive({
selector: '[preventGhostClicks]',
})
@lydemann
lydemann / graphql-helpers.ts
Last active Mar 23, 2021
graphql-helpers.ts
View graphql-helpers.ts
export function removeFromCache<ReadQueryResponseT>(
toRemove: EntityObject,
readQuery: DocumentNode,
cache: ApolloCache<any>,
entityName: keyof ReadQueryResponseT
) {
const existingEntities = cache.readQuery<
Record<keyof ReadQueryResponseT, EntityObject[]>
>({
query: readQuery,
View graphql-helpers.ts
export function createInCache<ReadQueryResponseT>(
toCreate: EntityObject,
readQuery: DocumentNode,
cache: ApolloCache<any>,
entityName: keyof ReadQueryResponseT
) {
const existingEntities = cache.readQuery<
Record<keyof ReadQueryResponseT, EntityObject[]>
>({
query: readQuery,
View graphql-helpers.ts
export interface EntityObject {
id: string;
}