-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gql): updates gql types to work with apollo > 2.11
As of apollo-server-* > 2.11.0 `esModuleInterop` in the tsconfig needed to be turned to `true`. This is now the case for the project. Apollo-server-fatify has been udpated as well to accommodate the ability to work with fastify as a graphql server. Minor adjustments still needed
- Loading branch information
Showing
21 changed files
with
2,265 additions
and
2,594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { createProviderToken } from '../ogma.provider'; | ||
|
||
export const OgmaLogger = (topic: string | Function) => | ||
export const OgmaLogger = (topic: string | (() => any)) => | ||
Inject(createProviderToken(typeof topic === 'function' ? topic.name : topic)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 10 additions & 37 deletions
47
packages/platform-graphql-fastify/src/graphql-fastify-interceptor.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,23 @@ | ||
import { ExecutionContext, HttpException, Injectable } from '@nestjs/common'; | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { GqlExecutionContext } from '@nestjs/graphql'; | ||
import { AbstractInterceptorService } from '@ogma/nestjs-module'; | ||
import { FastifyParser } from '@ogma/platform-fastify'; | ||
import { FastifyReply, FastifyRequest } from 'fastify'; | ||
|
||
@Injectable() | ||
export class GraphQLFastifyParser extends AbstractInterceptorService { | ||
getCallerIp(context: ExecutionContext) { | ||
const req = this.getRequest(context); | ||
return req.ips && req.ips.length ? req.ips.join(' ') : req.ip; | ||
} | ||
|
||
getCallPoint(context: ExecutionContext) { | ||
const req = this.getRequest(context); | ||
return req.url; | ||
} | ||
|
||
getMethod(context: ExecutionContext) { | ||
export class GraphQLFastifyParser extends FastifyParser { | ||
getMethod(context: ExecutionContext): string { | ||
return this.getContext(context).getInfo().operation.operation; | ||
} | ||
|
||
getProtocol(context: ExecutionContext) { | ||
const req = this.getRequest(context); | ||
return `HTTP/${req.httpVersionMajor}.${req.httpVersionMinor}`; | ||
} | ||
|
||
getStatus( | ||
context: ExecutionContext, | ||
inColor: boolean, | ||
error?: Error | HttpException, | ||
) { | ||
const status = error ? this.determineStatusFromError(error) : 200; | ||
return inColor ? this.wrapInColor(status) : status.toString(); | ||
} | ||
|
||
private determineStatusFromError(error: Error | HttpException) { | ||
try { | ||
return (error as HttpException).getStatus(); | ||
} catch (err) { | ||
return 500; | ||
} | ||
} | ||
|
||
private getContext(context: ExecutionContext): GqlExecutionContext { | ||
return GqlExecutionContext.create(context); | ||
} | ||
|
||
private getRequest(context: ExecutionContext) { | ||
getRequest(context: ExecutionContext): FastifyRequest { | ||
return this.getContext(context).getContext().req; | ||
} | ||
|
||
getResponse(context: ExecutionContext): FastifyReply<any> { | ||
return this.getContext(context).getContext().res; | ||
} | ||
} |
Oops, something went wrong.