-
-
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.
feat(gql): implements gql parser for express
The GqlParser now is working for express. There are updates to the main module packages to handle whenever subscriptions come in, as there is not enough information in them to properly add them to the request logging. This may change in the future. fix #14
- Loading branch information
Showing
24 changed files
with
8,920 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ coverage/ | |
|
||
*.tgz | ||
|
||
*.txt | ||
*.txt | ||
*.gql |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@ogma/platform-graphql-integration", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "nest build", | ||
"start": "nest start", | ||
"visual": "node testScript" | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
"@nestjs/common": "^7.0.0", | ||
"@nestjs/core": "^7.0.0", | ||
"@nestjs/graphql": "^7.0.0", | ||
"@nestjs/platform-express": "^7.0.0", | ||
"apollo-server-express": "^2.11.0", | ||
"graphql": "^14.0.0", | ||
"graphql-subscriptions": "^1.1.0", | ||
"graphql-tools": "^4.0.7" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^7.1.1", | ||
"@nestjs/testing": "^7.0.0", | ||
"jest": "^25.2.3", | ||
"reflect-metadata": "0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "6.5.4", | ||
"ts-jest": "^25.2.1" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { GraphQLModule } from '@nestjs/graphql'; | ||
import { OgmaModule } from '@ogma/nestjs-module'; | ||
import { GraphQLParser } from '@ogma/platform-graphql'; | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { AppResolver } from './app.resolver'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
OgmaModule.forRoot({ | ||
interceptor: { | ||
gql: GraphQLParser, | ||
}, | ||
}), | ||
GraphQLModule.forRoot({ | ||
autoSchemaFile: 'schema.gql', | ||
context: ({ req, res }) => { | ||
return { req, res }; | ||
}, | ||
installSubscriptionHandlers: true, | ||
}), | ||
], | ||
providers: [AppResolver, AppService, PubSub], | ||
}) | ||
export class AppModule {} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { Mutation, Query, Resolver, Subscription } from '@nestjs/graphql'; | ||
import { OgmaSkip } from '@ogma/nestjs-module'; | ||
import { PubSub } from 'graphql-subscriptions'; | ||
import { AppService } from './app.service'; | ||
import { SimpleObject } from './models'; | ||
|
||
@Resolver(() => SimpleObject) | ||
export class AppResolver { | ||
constructor( | ||
private readonly appService: AppService, | ||
private readonly pubSub: PubSub, | ||
) {} | ||
|
||
@Query(() => SimpleObject) | ||
getQuery(): SimpleObject { | ||
const hello = this.appService.getHello(); | ||
this.pubSub.publish('saidHello', hello); | ||
return hello; | ||
} | ||
|
||
@Mutation(() => SimpleObject) | ||
getMutation(): SimpleObject { | ||
return this.appService.getHello(); | ||
} | ||
|
||
@Query(() => SimpleObject) | ||
getError(): never { | ||
throw new BadRequestException('Borked'); | ||
} | ||
|
||
@OgmaSkip() | ||
@Query(() => SimpleObject) | ||
getSkip(): SimpleObject { | ||
return this.appService.getHello(); | ||
} | ||
|
||
@Subscription(() => SimpleObject) | ||
saidHello() { | ||
return this.pubSub.asyncIterator<SimpleObject>('saidHello'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { SimpleObject } from './models'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
getHello(): SimpleObject { | ||
return { key: 'value' }; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { OgmaService } from '@ogma/nestjs-module'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const logger = app.get(OgmaService); | ||
await app.listen(3000); | ||
logger.log('Graphql Listening at ' + (await app.getUrl()) + '/graphql'); | ||
} | ||
|
||
bootstrap(); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './simple-object.model'; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql'; | ||
|
||
@ObjectType() | ||
export class SimpleObject { | ||
@Field() | ||
key: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { request } = require('http'); | ||
|
||
const baseUrl = 'http://localhost:3000/graphql'; | ||
|
||
function cb(res) { | ||
let data = ''; | ||
res.on('data', (chunk) => (data += chunk)); | ||
res.on('end', () => console.log(data)); | ||
} | ||
|
||
function makeCall(gqlQuery) { | ||
const req = request( | ||
baseUrl, | ||
{ method: 'POST', headers: { 'Content-Type': 'application/json' } }, | ||
cb, | ||
); | ||
req.write(gqlQuery); | ||
req.end(); | ||
} | ||
|
||
function makeQueryString(type, name) { | ||
return `{"query": "${type} ${name}{ ${name} { key }}"}`; | ||
} | ||
|
||
makeCall(makeQueryString('query', 'getQuery')); | ||
makeCall(makeQueryString('query', 'getError')); | ||
makeCall(makeQueryString('mutation', 'getMutation')); | ||
makeCall(makeQueryString('query', 'getSkip')); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./tsconfig.json" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": false, | ||
"rootDir": "./src", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["./src"] | ||
} |
Oops, something went wrong.