Skip to content

Commit

Permalink
fix: temp fix for serverless-offline
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonadams committed Sep 8, 2020
1 parent 3a1c896 commit 20aaf2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions TRACKING_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ A list of random issues that are either bugs or features that will cause changes
If different queries queried todos.
When Apollo Client v3 (apollo-angular 2) is released, use the cache.evict /.release /.gc etc
https://github.com/apollographql/apollo-feature-requests/issues/5

* serverless-offline v6.7 introduced the noCaching option, however this causes a whole bunch of issues,
specifically with ApolloServer (duplicate types, importing from multiple realms etc )
https://github.com/dherault/serverless-offline/issues/931
https://github.com/dherault/serverless-offline/issues/1075
https://github.com/dherault/serverless-offline/issues/1080
3 changes: 3 additions & 0 deletions apps/server/lambda/serverless.ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
service: zero-to-production

enableLocalInstallationFallback: true

provider:
name: aws
runtime: nodejs12.x
Expand All @@ -22,6 +24,7 @@ functions:
# For production, path is relative to project directory
handler: dist/main.handler
environment:
NODE_ENV: production
AUDIENCE: ${env:AUDIENCE}
ISSUER: ${env:ISSUER}
ACCESS_TOKEN_EXPIRE_TIME: ${env:ACCESS_TOKEN_EXPIRE_TIME}
Expand Down
6 changes: 6 additions & 0 deletions apps/server/lambda/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
service: zero-to-production

enableLocalInstallationFallback: true

custom:
serverless-offline:
allowCache: true

provider:
name: aws
runtime: nodejs12.x
Expand Down
18 changes: 7 additions & 11 deletions libs/server/graphql/src/lib/directives/format-date.directive.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import { SchemaDirectiveVisitor } from 'apollo-server-koa';
import formatDate from 'date-fns/format';
import {
defaultFieldResolver,
GraphQLString,
GraphQLField,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLArgument,
} from 'graphql';
import formatDate from 'date-fns/format';

type TField = GraphQLField<any, any>;
interface TVisitedFieldDetails {
objectType: GraphQLObjectType | GraphQLInterfaceType;
}

export class FormatDateDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field: TField, details: TVisitedFieldDetails) {
visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field;
// the default format is defined as format on the type definition
const { format: defaultFormat } = this.args;

field.args.push({
name: 'format',
type: GraphQLString,
} as GraphQLArgument);

field.resolve = async function (root, { format, ...rest }, ctx, info) {
const date = await resolve.call(this, root, rest, ctx, info);
field.resolve = async function (source, { format, ...rest }, ctx, info) {
const date = await resolve.call(this, source, rest, ctx, info);
return formatDate(date, format || defaultFormat);
};

field.type = GraphQLString;
}
}

0 comments on commit 20aaf2f

Please sign in to comment.